I am trying to run the following python with \" python get_timestamp.py -f gsham_input.xvg -1 −0.1348 -2 −0.1109\". However, it seems that the python is mistaking
In Python 3
float_num_of_str = float(arg_str.replace(u"\u2212", "-"))
It's not a Python problem, the float numbers that you are passing begin with minus signs (−
, unicode U+2212) instead of regular hyphens-minus symbols (-
, unicode U+002D, the ones used by Python and most languages as "minus" sign). I'd guess it's because you copied the numbers from some document, since it is rather hard to type a Unicode minus sign with a keyboard.
The easy solution is to replace these signs with regular hyphens when you call the program in the command line. If you really need you program to work with these signs, you could use a function like this to parse the numbers instead of calling float
:
def float_unicode(arg_str):
return float(arg_str.decode("utf8").replace(u"\u2212", "-"))
However I wouldn't recommend this, as it just complicates the program more and most command line tools that work with numbers do not support this, so users generally won't expect your program to do so.