QPython by default runs your programs from the root directory which is not writable by non-root users. If you check the ftp utility (under About menu) you will find the name of the directory that is writable by QPython. On my HTC it is:
/storage/emulated/0/com.hipipal.qpyplus
So you need to do something along the lines of:
RootPath='/storage/emulated/0/com.hipipal.qpyplus'
...
import os
f = open(file, os.path.join(RootPath,'a'))
...
Example of a similar problem with QPython and SQLite3
Answer from CyberFonic on Stack OverflowWhy can't I create a file on android using python - Stack Overflow
Is there a way to run Python on Android? - Stack Overflow
Is it possible to run python scripts from my Android phone?
Recommend python file viewer app for Android.
QPython by default runs your programs from the root directory which is not writable by non-root users. If you check the ftp utility (under About menu) you will find the name of the directory that is writable by QPython. On my HTC it is:
/storage/emulated/0/com.hipipal.qpyplus
So you need to do something along the lines of:
RootPath='/storage/emulated/0/com.hipipal.qpyplus'
...
import os
f = open(file, os.path.join(RootPath,'a'))
...
Example of a similar problem with QPython and SQLite3
Just create the file with QPython before use in your script. You can create an txt file with QPython. In My case I create the file whith name "pontoText.txt" Inside folder "MyPythonScripts" (Im create that folder to put my python files) so the file is in the same folder of the script and are created in QPython Now an example code im make ton test:
import time
import os
a = input("1 to save date on file or 2 too see records on file. ")
folder= '/storage/emulated/0/MyPythonScripts'
if(a == "1"):
pontoTxt=open(os.path.join(folder,'pontoText.txt'),'w')
pontoTxt.write(time.strftime("%I %M %p on %A, %B %e, %Y"))
if(a == "2"):
pontoTxt=open(os.path.join(folder,'pontoText.txt'),'r')
exibe = pontoTxt.read()
print(exibe)
One way is to use Kivy:
Open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps.
Kivy runs on Linux, Windows, OS X, Android and iOS. You can run the same [python] code on all supported platforms.
Kivy Showcase app
There is also the new Android Scripting Environment (ASE/SL4A) project. It looks awesome, and it has some integration with native Android components.
Note: no longer under "active development", but some forks may be.
I am wondering if it is possible to run a python script from a mobile phone. Is there an app that simulates something like a bash terminal window? And since my phone is almost always up and running, would it be possible to use it as a remote server (think DigitalOcean's droplet) with scheduled jobs (cron)? Ideally, I could create (edit, test) my scripts on my Linux machine and then run them from my mobile.
Title. Sometimes I need to look up python files on my android tablet, I don't need editing but syntax hilighting and if possible find definition, reference would be useful.