tags:

views:

78

answers:

1

I don't know if this is a problem with python or with the shell (zsh on linux), I've an argument like this: "@xyz" that starts with a "@"

python the_script.py first_argument @second_argument third_arg

I tried to escape @ with \ or \\, or use "" but the program doesn't start. If I leave the @ from @second_arguments everything's ok.

+2  A: 
  1. Perhaps the "@" is a glob character in zsh, expanding to all symbolic links in the current directory. Try escaping it with "@@"?

  2. Try running the argument list with echo, i.e:

    echo the_script.py first_argument @second_argument third_arg

That way, you can figure out if it was expanded or passed as-is to the script.

Adam Matan
ok, thanks, the echo test works also for me. I think that the problem is then I pass the @something to os.system
wiso
Use subprocess.Popen() instead of os.system.
Thomas Wouters
@Thomas +1 always a good advice.
Adam Matan
yes, I know, but unfortunatly I have to use python 2.3
wiso
'@' is **not** a glob character in zsh.`setopt xtrace` to turn on tracing of the shell, to see what's happening and whether the program is starting.Use print debug statements to check what's happening in Python and what value you're seeing at *that* point.I suspect that the actual setup is more complicated than you have indicated; for instance, perhaps somewhere there is a Perl shim and you're interpolating the params with incorrect quoting, so that @array is getting dropped at that shim.
Phil P