社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  陈海栋  »  全部回复
回复总数  2
6 年前
回复了 陈海栋 创建的主题 » 从python中的.txt文件读取类对象[关闭]

python的最佳实践是使用json内置的dict数据类型:

如: 文本文件.json: {"name":"Fox Mulder","email":"fox@findthetruth.com"} 读卡器.py:

import json
with open("text_file.json",'r') as file:
  a=file.readlines()
dict_0=json.loads(a[0])

然后是你的读者课:

class Profile:
  def reader(self,input_dict,*kwargs):
    for key in input_dict:
      try:
        setattr(self, key, input_dict[key])
      except:
        print("no such attribute,please consider add it at init")
        continue

如果你想读书就这么做

profile_instance=Profile()
profile_instance.reader(dict_0)

你们都准备好了

听起来像是使用芹菜工人redis作为消息队列的rest api。 以下是CHK列表:

1在您的客户机中,您是否在逻辑完成后关闭了连接?

2芹菜会新工人,工人可能会惹麻烦,试试用花监测芹菜

3确保你的客户机完成任务,试着用打印的东西调试,有时登台和本地有网络问题阻止你结束芹菜任务。

4如果你用redis做芹菜味精队列,试着监控队列的数量,也许它们会自动放大?