我正在尝试根据用户输入将多个函数写入文件。这里的问题是写入文件的代码没有左对齐。也许缺少一些基本元素。
这是代码:
import requests
G=input("Define Count")
for k in range(0,G):
perf=G
if k==0 :
string = """
### RUN ####
def run():
d = collections.OrderedDict()
d['run']= 123,
return d
URL = "https://..../run"
headers = {"Content-Type":"application/json",
"Authorization": Token}
payload = json.dumps([run() for n in range(%s)])
resp = requests.post(URL, headers = headers ,data = payload))
if resp.status_code = 200:
print('Fail: ' + str(resp.status_code)+ str(resp.text))
else:
print('Pass' + str(resp.status_code)+ str(resp.text))
"""
string = Template % (Perf)
with open(path, 'a') as f:
f.write(string)
elif k==1:
string = """
### STOP ####
def stop():
d = collections.OrderedDict()
d['STOP']= 123,
d['wait']=20
return d
URL = "https://..../stop"
headers = {"Content-Type":"application/json",
"Authorization": Token}
payload = json.dumps([stop() for n in range(%s)])
resp = requests.post(URL, headers = headers ,data = payload))
if resp.status_code = 200:
print('Fail: ' + str(resp.status_code)+ str(resp.text))
else:
print('Pass' + str(resp.status_code)+ str(resp.text))
"""
string = Template % (Perf)
with open(path, 'a') as f:
f.write(string)
elfif k=.....
当在循环中执行时,我期望写入后的输出文件,左对齐为:
def run():
....
....
def stop():
....
....
def wait():
....
不知道为什么我会出现不规则的缩进。请帮助我
慕的地8271018
相关分类