gpt4 book ai didi

android - 为什么我不能使用 python 在 android 上创建文件

转载 作者:搜寻专家 更新时间:2023-11-01 09:47:40 25 4
gpt4 key购买 nike

我无法使用 qpython3 在我的 android 设备上运行我的 python 程序。

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

这是用于轻松创建/或确保文件存在的函数。

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

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

最佳答案

默认情况下,QPython 从非根用户不可写的根目录运行您的程序。如果您检查 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

关于android - 为什么我不能使用 python 在 android 上创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37200692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com