So I made this script call auto ascii encrypter and it basically goes character by character through a script and converts it to ascii numbers. It makes a new a script using the ascii numbers. But I get an error no matter how simple the script is. 'invalid syntax.' Heres the code and thanks for the help.

import os
import sys
import glob
result = ""
for script_to_convert in glob.glob1(sys.path[0],'*.py*'):
    if str(sys.path[0])+'\\'+script_to_convert != sys.argv[0]:
        print 'converting', script_to_convert, '...'
        opened_script = open(script_to_convert, 'r')
        for eachline in opened_script:
            for eachletter in eachline:
                for eachchar in range(0, 256):
                    if chr(eachchar) == eachletter:
                        result = result+"chr("+str(eachchar)+")+"
        result = result[0:-1]
        os.rename(sys.path[0]+'\\'+script_to_convert, 'c:\python25\custom scripts'+'\\'+script_to_convert)
        print 'moved', script_to_convert, 'to c:\python25\custom scripts'
        ascii_file = open('ascii_'+script_to_convert, 'w')
        print 'ascii_'+script_to_convert, 'has been created.'
        raw_input('conversion completed. Press enter to exit')
    print 'No other files found.'


Traceback (most recent call last):
  File "C:\Python25\custom scripts\auto ascii converter\", line 1, in <module>
  File "<string>", line 1
    print 'I hate Hippies!'
SyntaxError: invalid syntax

just to clarify the auto ascii script runs to completion just fine. Its the output files that encounter errors

The problem is that the argument to eval must be an expression, while "print 'I hate Hippies'\n" is a statement. You can exec statements :)

This question has already been answered. Start a new discussion instead.