954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Compiling .py files...

Hi..

Ive been doing python for about 2 days now (my 1st programming language) and im wondering, after ive made the .py file, and all the codes in it, how do i run it?

To be honest im not even sure if the term compiling is right...

I am doing all of the work on Fedora Core 3 (im also new to linux. lol, though im not a computer noob, i do know my way around one :P)

anyways, can anyone give me a link to a website, another post explaining this, or even explain it?

Ty in advance :P

Fallen05
Newbie Poster
4 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

AFAIK, python just works, something like Perl just works, no need to compile :)

You do need a way to run python however :)

Zachery
The Geek Father
Team Colleague
894 posts since Nov 2003
Reputation Points: 96
Solved Threads: 21
 

AFAIK, python just works, something like Perl just works, no need to compile :)

You do need a way to run python however :)

Need a way to run python? huh? lol, re-phrase plz -.-

and as for "python just works" how do i run .py files as a program? o.O

Eg. i have helloworld.py saved in /usr/bin/
what command do i run to run it as a program, and i also want to have it run as an executable...

Fallen05
Newbie Poster
4 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

A command like Python.exe Filename.py will do. It is simpler to run it from an editor/IDE like IDLE, see the "Starting Python" sticky right here.

On Windows, once you have installed Python, any .py file is associated with Python.exe, so you just double click on the .py file. I don't work with Linux, there should be a command of some kind.

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

lol, maby i should just learn C r sumthin, ive been told its too hard as a 1st language tho *-*

Fallen05
Newbie Poster
4 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

C isn't hard to learn! It works well in the trenches. It only gets hard, if you want to program something fancy.

Python works at a much higher level, this simply means that a lot of things you will be coding in C many pages long is ready to go in a Python module (some of it written in C). Walking on foot, flying in a jetplane, each has its purpose.

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

hmm........
lol, though switching to a different language is gona give me all the same problems again *-* lol, ill have to find out how to compile .c files, and all that poo -.-

lol, though i supposes its the most worth while learning, so, know any good tuts? (That includes compiling the files.. through unix/linux terminal)

Fallen05
Newbie Poster
4 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

There is a Python online book/tutorial at:
http://www.byteofpython.info/
that is for the very beginner and addresses Python programming in the linux environment too.

The first step, be it Python or C, is a little steep. It's like learning to ride a bike. Try the tutorial or find someone in school that has done programming. Who knows, even a teacher or two may know.

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

if your file is in /usr/bin and the file starts with
#!/usr/bin/python
the above method assumes you have python install in /usr/bin or better yet
#!/usr/bin/env python
this method will run it no matter where you installed python

you just need to make the file executable with the command

chmod +x /usr/bin/hello.py

now you can just run it by entering its command hello.py. This will work because /usr/bin is in your normal path. If you had the program somewhere else like your home directory. you would need to type the whole path, /home/fallen/hello.py

It is not probably a good habit to be putting test programs in /usr/bin. It should not cause problems, but will make a mess of that directory. I myself have a python directory in my home directory

you also could ignore everything I said above and do it this way. type the command python then the location of the file

python hello.py

the above method will work if you are in the same directory as the program. else do it like this

python /full/path/to/hello.py
shanenin
Posting Whiz in Training
217 posts since May 2005
Reputation Points: 10
Solved Threads: 17
 

Hi Friends,
I am new to Python programming. I had been given a simple project using c & python.The Project goes like this "To give .c and .py file's outputs as input to another .c file which should give single output". so please post ur valuable Solutions. My mail-id is [email]krishnamohan516@yahoo.com[/email].

krishnamohan516
Newbie Poster
1 post since Nov 2005
Reputation Points: 10
Solved Threads: 0
 
./secondprogram | python firstprogram.py
jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

You need to install the proper python IDE for your programs. You can get one at Python.org. But make sure that you type '.org', because 'python.com' is a porn site.

Fredo699
Newbie Poster
1 post since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You