how do i modify a prop default value, i want to keep all default values initially and base on the requirement i want to modify a specific prop default value. for example i want to modify prop3 default value to data1 but then next time i run i want to keep all prop default and change prop8 default value.
def property_value(prop_name, value)
data = {
"id": 104,
"content": "prop1=default_value\n"
"prop2=default_value\n"
"prop3=default_value\n"
"prop4=default_value\n"
"prop5=default_value\n"
"prop6=default_value\n"
"prop7=default_value\n"
"prop8=default_value"
}
res = requests.post(url, headers=headers, json=data)
CodePudding user response:
data
is local variable - so when you run again function then it creates it again with default values.
Problem is only to replace value in content
. I would keep it as dictionary content = {"prop1" "default_value", "prop2" "default_value", ..}
and replace value content[prop_name] = value
and later convert it to one string and put in this string in data
def property_value(prop_name, value):
content = {
"prop1": "default_value",
"prop2": "default_value",
"prop3": "default_value",
"prop4": "default_value",
"prop5": "default_value",
"prop6": "default_value",
"prop7": "default_value",
"prop8": "default_value",
}
content[prop_name] = value
text = [f'{key}={val}' for key, val in content.items()]
text = "\n".join(text)
data = {
"id": 104,
"content": text,
}
print(data)
#res = requests.post(url, headers=headers, json=data)
# --- main ---
property_value('prop1', 'ABC')
property_value('prop4', 'XYZ')
CodePudding user response:
os. mkdir("your folder nime")
- Fore more information http://q.gs/FTMuv