2

我无法使用 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中克服这个问题?

4

5 回答 5

1

在您的脚本中使用之前,只需使用 QPython 创建文件。您可以使用 QPython 创建一个 txt 文件。在我的情况下,我在文件夹“MyPythonScripts”内创建名称为“pontoText.txt”的文件(我创建该文件夹来放置我的python文件),因此该文件位于脚本的同一文件夹中并在QPython中创建现在一个示例代码我做吨测试:

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)
于 2018-09-10T03:16:28.577 回答
1

QPython 默认从非 root 用户不可写的根目录运行你的程序。如果您检查 ftp 实用程序(在 About 菜单下),您将找到 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'))
...

QPython 和 SQLite3 的类似问题示例

于 2017-04-17T22:41:49.383 回答
0

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

于 2017-01-08T17:38:39.487 回答
0

使用他们改变的东西。您拥有的文件在/accounts/mastercard根目录中,而您在其中的文件/accounts/main.py只需要使用 /mastercard/xxxxx就像我的代码一样

from django.shortcuts import render
from django.http import HttpResponse
from . import models
# Create your views here.
def index(request):
    return render(request,"mastercard/Templates/mastercard/Base.html")
def about(request):
    return render(request,"mastercard/Templates/mastercard/index.html")
于 2020-08-31T11:02:11.957 回答
0

您的应用可能没有管理该文件所需的权限。检查您的清单,指定 Android 版本和文件路径。检查文档:http: //developer.android.com/training/basics/data-storage/files.html

于 2016-05-13T15:32:31.457 回答