LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python executable (https://www.linuxquestions.org/questions/programming-9/python-executable-450537/)

deep_jyotsingh 06-01-2006 08:10 AM

python executable
 
can anyone tell me how do i get to make a bin or .pyc extension file with my python code.i need to make my code executable so that no can see my code.

jonaskoelker 06-01-2006 02:33 PM

Whenever you import a .py module, python will compile it into a .pyc file.

deep_jyotsingh 06-02-2006 02:12 AM

thanks for reply
 
hi i did the same thing but i get following error i dont whats wrong

python
Python 2.4.2 (#1, Feb 12 2006, 03:59:46)
[GCC 4.1.0 20060210 (Red Hat 4.1.0-0.24)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello.py
This is a multi-line string. This is the first line.
This is the second line.
"What's your name?," I asked.
He said "Bond, James Bond."

Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named py


my script is
#!/usr/bin/python
#Filename : hello.py
print '''This is a multi-line string. This is the first line.
This is the second line.
"What's your name?," I asked.
He said "Bond, James Bond."
'''
s='hi this is.\
deep jyot singh.'
print \
s
number = 45
guess = int(raw_input('Enter an Integer : '))
if guess == number:
print 'Congratulations,you guessed it correct.'
elif guess < number:
print 'you are higher than number'
else:
print 'your guess is wrong'
print 'Done'

Hko 06-02-2006 04:09 AM

Remove ".py" when importing. Like this:
Code:

import hello
Alternatively, you can usea python script like this:
Code:

#!/usr/bin/env python

from compileall import *
compile_dir('.', 0, force=True)

This will compile all *.py files in the current working directory.


All times are GMT -5. The time now is 06:45 AM.