Reputation: 119
I have two scripts and want to call the tester script from the terminal.
string s = """ output/directory/366d595b-23b2-435d-8dc6-698b3d0844b9/result.csv scores=[{
"base_score": 0.92,
"metric": "ACCURACY"
}]"""
Script #1 (script1.py)- consists of a function that parses a string
def parser_score(s):
dict_txt = re.search('\[([^]]+)', s).group(1).strip()
data = json.loads(dict_txt)
return data
Script #2(script2.py) - calls script #1 and saves the result in a json file
import sys
from parser_for_score_v3 import parser_score
s = sys.argv[1]
print(s)
result = parser_score(s)
# save dict to a json file
with open('result.json', 'w') as fp:
json.dump(result, fp)
I call the second script from the terminal -
abc $ python script2.py """output/directory/366d595b-23b2-435d-8dc6-698b3d0844b9/result.csv scores=[{
"base_score": 0.92,
"metric": "ACCURACY"
}]"""
I get an error: AttributeError: 'NoneType' object has no attribute 'group' -bash: base_score:: command not found
Thanks in advance.
Upvotes: 0
Views: 1665
Reputation: 295687
The precise literal multi-line string
output/directory/366d595b-23b2-435d-8dc6-698b3d0844b9/result.csv scores=[{
"base_score": 0.92,
"metric": "ACCURACY"
}]
...requires nothing more than single quotes to pass it on a shell command line. Thus:
python script2.py 'output/directory/366d595b-23b2-435d-8dc6-698b3d0844b9/result.csv scores=[{
"base_score": 0.92,
"metric": "ACCURACY"
}]
'
...will pass that string in sys.argv[1]
.
Upvotes: 1