+ 3

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??

18th Mar 2021, 11:20 AM
Scarlet Witch
Scarlet Witch - avatar
23 Answers
0
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
18th Mar 2021, 1:57 PM
Ervis Meta
Ervis Meta - avatar
+ 2
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...
18th Mar 2021, 2:04 PM
visph
visph - avatar
+ 1
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 ^^
18th Mar 2021, 11:26 AM
visph
visph - avatar
+ 1
visph I am using Pydroid 3
18th Mar 2021, 11:53 AM
Scarlet Witch
Scarlet Witch - avatar
+ 1
With a absolute path of course
18th Mar 2021, 1:58 PM
Ervis Meta
Ervis Meta - avatar
+ 1
Ervis Meta thank you. my problem is solved!!
18th Mar 2021, 2:10 PM
Scarlet Witch
Scarlet Witch - avatar
+ 1
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
18th Mar 2021, 2:20 PM
visph
visph - avatar
+ 1
18th Mar 2021, 2:28 PM
Scarlet Witch
Scarlet Witch - avatar
+ 1
I got my first OWN phone (what I'm using now) of Android 10 just some day before as gift for my birthday🙃
18th Mar 2021, 2:31 PM
Scarlet Witch
Scarlet Witch - avatar
+ 1
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
18th Mar 2021, 2:38 PM
Ervis Meta
Ervis Meta - avatar
+ 1
If you have created the file then put the file in the same directory as the python file
20th Mar 2021, 10:22 AM
Eashan Morajkar
Eashan Morajkar - avatar
+ 1
Eashan Morajkar BTW I solved my problem but THANK YOU
20th Mar 2021, 11:23 AM
Scarlet Witch
Scarlet Witch - avatar
0
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...
18th Mar 2021, 11:51 AM
visph
visph - avatar
0
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 ^^
18th Mar 2021, 11:57 AM
visph
visph - avatar
0
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
18th Mar 2021, 2:10 PM
Ervis Meta
Ervis Meta - avatar
0
No problem 👍. Ask Anytime !
18th Mar 2021, 2:11 PM
Ervis Meta
Ervis Meta - avatar
0
I once had a phone Android 4.2.2 and it's folders were like 4.1 or 4.3, but no problem 😄
18th Mar 2021, 2:27 PM
Ervis Meta
Ervis Meta - avatar
0
It works
20th Mar 2021, 10:21 AM
Eashan Morajkar
Eashan Morajkar - avatar
0
Have you created the file
20th Mar 2021, 10:21 AM
Eashan Morajkar
Eashan Morajkar - avatar
0
Because 'r' can't create file
20th Mar 2021, 10:21 AM
Eashan Morajkar
Eashan Morajkar - avatar