Looking for help :

I run abc.py with normal output as I expect, but get error in abc.pyc. Below is what I have done. Would you tell me what I have mistaken ? Thank you very much !!

abc.py
#!/usr/bin/python

import datetime
test_time = open('test.time', 'w')
test_time.write('oh, today is\n')
test_time.close()

test_time = open('test.time', 'a')
timing = datetime.date.today()
#
print timing, type(timing) # 2008-03-09 <type 'datetime.date'>
# convert <type 'datetime.date'> to a string first
# since write() expects a string
test_time.write(str(timing))
test_time.close()

# test the file's contents
for line in file('test.time'):
print line,

running in termial
~/abc$ ./abc.py
2008-03-10 <type 'datetime.date'>
timing is
2008-03-10

I created abc.pyc
>>> import py_compile
>>> py_compile.compile("abc.py")


However, when running with abc.pyc
:~/abc$ ./abc.pyc
: command not found�
./abc.pyc: line 2: ���Gc@s�ddkZedd�Zeid�ei�edd�Zeii�ZeGe�GHeie: command not found
./abc.pyc: line 3: d�D]: command not found
./abc.pyc: line 4: syntax error near unexpected token `i����Ns'
./abc.pyc: line 4: `Z
e
Gq�WdS(i����Ns test.timetws'


So what is wrong ?

Recommended Answers

All 2 Replies

pyc modules are used by modules. i think they are already compiled. they do not use python, instead python uses them.

It looks like you are in a linux console. When you give the name of an executable file in the terminal, it probably tries to execute it as if it is a bash script, and you see the error messages of bash. Normally you should be able to execute your file with python abc.pyc

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.