Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Py2exe无法使用linecache_Python_Py2exe_Readline_Linecache - Fatal编程技术网

Python Py2exe无法使用linecache

Python Py2exe无法使用linecache,python,py2exe,readline,linecache,Python,Py2exe,Readline,Linecache,当我以.py文件的形式运行它时,下面的代码部分可以完美地工作。当我使用py2exe将其转换为.exe时,linecache.getline()函数似乎工作不正常。我能够很好地创建和编写.txt文件,因此我认为linecache函数是问题所在。是否存在不使用linecache从文本文件读取指定行的解决方法,或者是否有方法使linecache与Py2exe一起工作 server = "en15" pagenum = "0" page = urllib.urlopen('http://www.west

当我以.py文件的形式运行它时,下面的代码部分可以完美地工作。当我使用py2exe将其转换为.exe时,linecache.getline()函数似乎工作不正常。我能够很好地创建和编写.txt文件,因此我认为linecache函数是问题所在。是否存在不使用linecache从文本文件读取指定行的解决方法,或者是否有方法使linecache与Py2exe一起工作

server = "en15"
pagenum = "0"
page = urllib.urlopen('http://www.westforts.com/%s/battles/page/%s' % (server, pagenum))
page_content = page.read()
with open('battle_id_getter%s.txt' % (pagenum) , 'w') as textfile:
    textfile.write(page_content)
line = linecache.getline('battle_id_getter%s.txt' % (pagenum), 126)

提前感谢您提供的任何帮助。

通过将代码更改为以下内容,它成功了

page = urllib.urlopen('http://www.westforts.com/%s/battles/page/%s' % (server, pagenum))
page_content = page.read()
with open('battle_id_getter%s.txt' % (pagenum) , 'w') as textfile:
    textfile.write(page_content)
with open('battle_id_getter%s.txt' % (pagenum), 'rU') as fp:
    lines = fp.readlines()
line = lines[125]