+ 1
To create a file and write in it. Then we copy the contents to newfile. We print the new file.can u spot my error(.no output)
file1 = open("testfile.txt","w") file1.write("most memorabe books of 2018 are 1. harry potter") file1.close() f=open("testfile.txt","r") file2=open("newfile.txt","w") for line in f: file2.write(line) f2=open("newfile.txt","r") print(f2.read()) f.close() f2.close() file2.close()
17 Antworten
+ 4
HonFu wrote << you can't work with files here >>
In fact, you can... since you read the file in the same code running instance, both on mobile and on browser version of SL code playground ;)
Obviously, the created file(s) are just temporary and not available when you run the code again ^^
+ 3
HonFu : yes, I've read your post... but in my memory (quite a long time that I havent used qpython) there's no problem to write file in the same directory as the running script, since you only provide a filename without a path ^^ (and also yes, I was running qpython on android, with two kind/brand of device: samsung phone -- qpython -- and asus tablet -- qpython 3)
+ 3
HonFu : Yes, it seems to me that I was facing too such issue with qpython console (unabled to get back when the cursor go to a new line after width overflow), as well as with termux console...
Anyway, I don't know about japanese input (or other utf-8 paricular languages char ranges, as I mostly use latin one -- I'm french -- so only type ascii char with my keyboard) trouble ^^
+ 3
HonFu : anyway, qpython/pydroid (never tested the second one) provide useful python ide for mobile devices, sometimes with some useless functionality (depending of what each user expect)... Have you tried termux? You can install python on your own without all other stuff provided by these apps. It require a little more advanced skill to use it, but if you're an quite advanced user (having at least some console/shell experience), I think this is a good alternative ;)
+ 2
shivaani : you forgot to close file2 after write, and before open it for read ;)
+ 2
HonFu : I guess that since you don't try to write anywhere than the qpython/pydroid script directory you shouldn't have access right problems (at least on qpython, from my experience ^^)
+ 1
shivaani, I'd be happy to hear later if your code works just by closing file2 properly, or if you also need different measures like me to work text files on Android.
+ 1
visph, have you read my post above?
Whenever I tried to work with files from QPython on my Android device, I had to add the whole path, otherwise it just wouldn't work, and also txt-files didn't fly, while on regular desktop pc version there's no problem with both, just using 'name.txt'.
Are you on android? Or maybe it already makes a difference what phone it is? No idea.
0
Have you tried that here on Sololearn?
Because you can't work with files here.
0
no I just used an app to create this code and run it . I copied the code and pasted it here.
0
Which app did you use? QPython?
Because I also had problems earlier when I didn't add the path. By writing out the whole path, it worked.
Oh yeah, and txt-files don't seem to work, so I started to use py-files instead.
In my case it looks like this:
'/storage/emulated/0/qpython/scripts3/namegoeshere.py'
Maybe it's the same with Pydroid, some kind of incompatibility with Android... my solution should work for that too.
0
pydroid3
0
visph could you tell me what is wrong with this code ?
0
visph, another question: With QPython and Pydroid3 on my phone there are issues when a user input goes beyond the line's length.
The line gets broken, and if you try to get back up, the output gets messed up. Also on my phone, input methods for Japanese writing get refused by both apps, and QPython even crashes when I try to input Japanese.
Maybe there are issues with certain phones and not with others? I have no idea, but the trouble exists.
Therefore I'd like to know if shivaani encounters similar troubles or not, to get a better picture if this is android or just my android.
0
visph, another question: With QPython and Pydroid3 on my phone there are issues when a user input goes beyond the line's length.
The line gets broken, and if you try to get back up, the output gets messed up. Also on my phone, input methods for Japanese writing get refused by both apps, and QPython even crashes when I try to input Japanese.
Maybe there are issues with certain phones and not with others? I have no idea, but the trouble exists.
Therefore I'd like to know if shivaani encounters similar troubles or not, to get a better picture if this is android or just my android.
0
visph, yeah, I suppose most people don't even encounter these problems. Also it's not encoding-related, since you can freely read or write Japanese from files; only the phone's input tools aren't handled properly.
I have seen another issue with other phones and QPython: When people wanted to input stuff, the enter key from their input tool had disappeared! Just like that!
As it is, I have already encountered a few annoying issues with these Interpreters/editors, and I'd be happy if one day there was a fully adapted android Python that can interact properly with everything on its own.
0
visph, I doubt I have enough experience... apart from that I'd be more interested in a solution that works for users as well.
Guess I should start to look into Kivy and the like ...