Flag control variable
On 2014-02-11 10:37, luke.geelen at gmail.com wrote:
> command1 = "sudo mpg321
> % (a, b, sum)
> when using * i get
> Traceback (most recent call last):
> File "./math+.py", line 6, in <module>
> b = int(sys.argv)
> ValueError: invalid literal for int() with base 10:
> i don't understand why b is a problem, it works fine with +
This is the fault of your shell (bash perhaps)?
bash$ echo +
bash$ echo *
(a list of files in your current directory here)
which occurs because of file-globbing.
You have a couple options that occur to me:
1) quote the asterisk:
bash$ ./mycode.py 3 "*" 2
which will let Python see it without the shell expanding it
2) use a different character/string such as "3 times 2"
3) pass the whole thing as a quoted string and then let Python do the
bash$ ./mycode.py "3 * 2"
a, operator, b = argv[1:].split()