+ 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??
22 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
+ 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...
+ 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 ^^
+ 1
visph I am using Pydroid 3
+ 1
With a absolute path of course
+ 1
Ervis Meta thank you. my problem is solved!!
+ 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
+ 1
+ 1
I got my first OWN phone (what I'm using now) of Android 10 just some day before as gift for my birthday🙃
+ 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
+ 1
If you have created the file then put the file in the same directory as the python file
+ 1
Eashan Morajkar BTW I solved my problem but THANK YOU
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...
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 ^^
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
0
No problem 👍. Ask Anytime !
0
I once had a phone Android 4.2.2 and it's folders were like 4.1 or 4.3, but no problem 😄
0
It works
0
Have you created the file
0
Because 'r' can't create file