2016-05-13 181 views
2

我无法使用qpython3在我的android设备上运行我的python程序。为什么我无法在android上使用python创建文件

他程序的第一步是创建一个文本文件来保存数据。但我得到一个I/O错误(文件系统只读)

这是用来创建/或确保该文件很容易存在的函数。

def filecreate(file):  # creates the text file 
    f = open(file, 'a') 
    print('file created successfully\n') 
    print() 
    f.close() 

如何在android中克服这个问题?

回答

0

您必须实际找到文件路径,因为它不会推断文件作为目标目录所在的目录,这与PC上的Python不同。

0

默认情况下,QPython从根目录运行你的程序,这是非root用户不可写入的。如果您检查ftp实用程序(在关于菜单下),您将找到可由QPython写入的目录的名称。在我的HTC是:

/storage/emulated/0/com.hipipal.qpyplus 

所以,你需要做的线沿线的东西:

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

相关问题