大佬,帮忙看看生成器的问题吧
本帖最后由 chmod 于 2022-9-26 18:16 编辑test.txt
116.4977588,39.9792711
116.4977588,39.9792861
116.4977589,39.9793011
116.4977590,39.9793161
116.4977591,39.9793311
116.4977592,39.9793461
tmp.py
import os
file_path = os.path.dirname(os.path.abspath(__file__))
path = file_path + '\\test.txt'
def get_txt(path=path):
with open(path, mode='r', encoding='utf-8', errors='ignore') as f:
for data in f.readlines():
yield data
tmp = get_txt()
if __name__ == '__main__':
print(next(tmp))
谁帮我瞅瞅,哪出错了,后面的不打印呀? 本帖最后由 jackz007 于 2022-9-26 19:08 编辑
next() 必须进循环啊
这些语句
tmp = get_txt()
if __name__ == '__main__':
print(next(tmp))
改为:
if __name__ == '__main__':
tmp = get_txt()
while True:
try:
print(next(tmp) , end = '')
except:
break
print() jackz007 发表于 2022-9-26 18:55
next() 必须进循环啊
这些语句
明白了。谢谢
页:
[1]