Can python open/read Android files??
file = open('filepath.txt', 'r') file.read() When I do this in Windows and write a Windows filepath, It works but when try in Android it gives 'No such file or dictionary'. I check many time the filepath is correct. Now doubting that can python open Android file? If yes, then how? WHAT MISTAKE I AM DOING??
3/18/2021 11:20:00 AMScarlet Witch
23 AnswersNew Answer
Currently I am using Pydroid 3 Premium (hacked of course) and with the permissions plugin (or without) you can access files or folders from everywhere if this file is inside the /storage folder . For example: def fRead(path): with open(path) as f: a = f.read()#or readline print(a) f.close() path = str(input('Enter the path of file you want to open : ').lower() fRead(path) If the file is not at /storage folder, then you are trying to access a file that belongs to operating system A solution can be creating a main folder on the default folder of your phone and filling it up with content. This procedure must be the same even someone else can use this code from a different device
With a absolute path of course
or maybe you are running a quite outdated andoid version: I do not remember wich, but when google decide to make file access more restrictive there was at least an android version wich could prevent you to read files elsewhere of app path...
python can open android file if path is good and you're running your script locally... if you run your script in sololearn app, you cannot open local files, as script are executed on sololearn server ^^
visph I am using Pydroid 3
Ervis Meta thank you. my problem is solved!!
Ervis Meta I think the android version wich I was talking should may be 4.2, but as I previously said, I don't remember: perhaps you don't have ran all androids versions or at least not tested file access with all? anyway, the essential is that RIYA KUMARI had solved its problem ;P
Ervis Meta 😅
I got my first OWN phone (what I'm using now) of Android 10 just some day before as gift for my birthday🙃
Than for the topic you should give your python ide access to read/write folders and files . If you're gonna use Pydroid, you'll grant it this permission just before starting typing your first code. And you may need repository and permissions plugin(or for this purpose
If you have created the file then put the file in the same directory as the python file
Eashan Morajkar BTW I solved my problem but THANK YOU
The problem with Android is the security mechanisms. Under Android every program runs as a different user. Consequently most programs cannot access the files created by another program.
Martin Taylor to just read file, all python interpreters installed on android should be able to open them... if you authorize file access (may require a few more steps) ^^ to write file, you will be more restricted...
then you should be able to at least read your local files... I guess: I have never used pydroid, but only qpython and python inside tetmux ^^
For myself I've ran all Android Platforms from Android 4.0 with non-premium Pydroid 3 till Android 10 that I am actually. I really don't know if my way can be successful under Android 4.0 but I know that the system folders may be separated from the user ones
No problem 👍. Ask Anytime !
I once had a phone Android 4.2.2 and it's folders were like 4.1 or 4.3, but no problem 😄
Have you created the file