python


34、输出保存txt

<pre><code># 在windows 命令行会有gbk错误,在ubuntu命令行可以正确运行 输出到text.txt zcr@acer:/mnt/e/work/practice$ python3 to_text.py &gt; text.txt zcr@acer:/mnt/e/work/practice$ python3 to_text.py &gt; text2.txt zcr@acer:/mnt/e/work/practice$ python3 to_text.py &gt; text3.txt zcr@acer:/mnt/e/work/practice$ python3 to_text.py &gt; text4.txt zcr@acer:/mnt/e/work/practice$ python3 to_text.py &gt; text5.txt zcr@acer:/mnt/e/work/practice$ # cat qq.json | python prepare_file.py &gt; qq1.json # 读取qq.json做为输入 经过 prepare_file 中的操作,所有的print输出做为qq1.json中的文件 import pickle class PdfName(): def __init__(self,name,url): self.name = name self.url = url def get_name(self): return self.name def get_url(self): return self.url pdf_object_list = pickle.load(open('./pdf_object_list_2.txt', 'rb')) for item in pdf_object_list: if isinstance(item,str): print("\n******************************************************") print(item) print("******************************************************") continue print(item.get_name()) print(item.get_url()) </code></pre>

页面列表

ITEM_HTML