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]
        opened_script.close()
        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')
        ascii_file.write('eval('+result+')')
        ascii_file.close()
        print 'ascii_'+script_to_convert, 'has been created.'
        raw_input('conversion completed. Press enter to exit')
        sys.exit()
else:
    print 'No other files found.'

Can you give us your whole error message?

sure

Traceback (most recent call last):
  File "C:\Python25\custom scripts\auto ascii converter\ascii_test.py", line 1, in <module>
    eval(chr(112)+chr(114)+chr(105)+chr(110)+chr(116)+chr(32)+chr(39)+chr(73)+chr(32)+chr(104)+chr(97)+chr(116)+chr(101)+chr(32)+chr(72)+chr(105)+chr(112)+chr(112)+chr(105)+chr(101)+chr(115)+chr(33)+chr(39)+chr(10))
  File "<string>", line 1
    print 'I hate Hippies!'
        ^
SyntaxError: invalid syntax

replace eval by print repr(...) so that we can see the string which was eval'ed

it prints it fine when you add that.

"print 'I hate Hippies!'\n"

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.