Q:

argv doesn't read < or > python

I'm using Python3 and I want to get < or > via argv.  here is my code:
str_args = [ str(x) for x in argv[1:] ] #create sequence
cmd = ''
for i in argv[1:]: #create str
    cmd += i + ' '
path = 'cmd.txt'
file=open(path, "a")
file.write(cmd + '\n')
file.close()

here in for loop  I concatenate arguments to make a linux terminal command and write in a .txt file.  I execute that command somewhere else.  when I type < or > (greater than or less than), it only pass until < or >.  example:

echo 12 > test.txt

and it just get 

echo 12

and doesn't pass > test.txt
What should I do ?  It works fine for non < or > examples.  for example it pass a command like this well:

ping 8.8.8.8 -c 2 -s 60

Thanks

A:

The > and < are treated specially by the shell, this has nothing to do with python because the shell strips them out before your code is called.  Without quotes, the > means to send the output of the command to a file given as the next argument.  In your case, stdout of the script will be redirected to the file test.txt. 
To pass them as character strings you must either use quotes or the escape character:
# using quotes
python the_script.py echo 12 '>' test.txt

# using the escape character
python the_script.py echo 12 \> test.txt

Note: it's not just > and < you have to worry about.  Characters such as * and a few others need to be protected, too.  These are all mentioned in the bash man page (or the man page of whatever shell you're using). 