0

我在 pygame 中编写了一个游戏并将其移植到 android,使用 pygame 子集 for andorid。我的游戏使用 python 文件模块(读写两者)。但是在 andorid 中我无法在 andorid 中读取文件。有什么我想念的吗!!!

import pygame

try:
    import android
except ImportError:
    android = None

def main():
    pygame.init()
    if android:
        android.init()
    print "reading file content"
    file_read = open("text.txt","a+")
    print file_read # This prints file object in andorid
    for line in file_read:
    print "line",line
    print "reading file done"

if __name__ == "__main__":
    main()
4

1 回答 1

0
    a+  Opens a file for both appending and reading. The file pointer is at
 the end of the file if the file exists. The file opens in the append mode.
 If the file does not exist, it creates a new file for reading and writing.

http://www.tutorialspoint.com/python/python_files_io.htm

我以 a+ 模式打开文件,文件指针位于末尾。这就是我无法读取文件内容的原因。

奇怪的是它在 Windows 中的作品:(

于 2013-08-10T14:34:10.867 回答