我有下面的文件,它调用一个端点并将结果保存在json文件中,以便在我的算法上执行基准测试。
import requests
import json
import simplejson
r = requests.get('http://localhost:5000/get_jobs/accurate,detail%20oriented,n mbers,finance,analyst,optimistic,emotional%20intelligence,positive,calm,resilient,stable,committed,competitive,ambitious,determined,targets,goal-oriented,quick%20learner').json()
f = open('ProfileA.json', 'w')
simplejson.dump({'this is a test on Profile A with the following words: accurate,detail%20oriented,numbers,finance,analyst,optimistic,emotional%20intelligence,positive,calm,resilient,stable,committed,competitive,ambitious,determined,targets,goal-oriented,quick%20learner' : r}, f,sort_keys = True, indent = 4)
f.close()
我想知道python中是否有任何方法可以简单地用随机字符串生成器复制文件。
我想了一些方法,例如,一个正则表达式,它可以拾取字符串,如果它发现该字符串,就会用一个新字符串写入另一个文件,但听起来效率很低。
您可以使用hash将事物映射到固定长度的字符串:
import hashlib
hashlib.sha256(json.dumps(info).encode('utf-8')).hexdigest()
其中info
是你的东西,dict
、str
。。。