I tried to run the following code, which is inside of a Bash-script.
NUMBER=600
LOSS_RATE=0,3
TOT_PKT=100
test=$(python -c "from math import ceil; print ceil($NUMBER * 500.0)")
test2=$(python -c "from math import ceil; print ceil($NUMBER * $LOSS_RATE)")
echo $test
echo $test2
I get the following printed out:
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: ceil() takes exactly one argument (2 given)
300000.0
The first Python-command is executed, but the second causes the given TypeError. How do I do to resolve this?
Python uses
.as the decimal point since,is the argument separator. So if you useLOSS_RATE=0.3everything should work fine:The problem lies in the shell script.echoinstead ofpython -cthe code and you’ll see it:You never define
LOSS_RATE. However, this results in a SyntaxError. Since you get a different error it sounds likeLOSS_RATEis set to something containing a comma.