pygame android没有读取文件

时间:2013-08-05 17:26:20

标签: android pygame

我已经在pygame中编写了一个游戏并将其移植到android,使用pygame子集为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()

1 个答案:

答案 0 :(得分: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

我在+模式下打开文件,文件指针在最后。这就是我无法读取文件内容的原因。

奇怪的是它在windows中的作用:(