You are not logged in.

#1 2008-03-02 02:43:28

Xs1t0ry
Member
From: Canada
Registered: 2007-07-01
Posts: 181

Python files

Hello World!

I'm learning Python right now using the tutorials found on the official site. I access the interpreter in Arch using the terminal and simply typing Python. Mostly, I've been experimenting with the various commands, syntax and etc. Now I want to start writing programs...

The problem is that I'm not sure how to do this. I am writing the code right into the CLI, so how do I save stuff? Do I write the code in a text editor and then save it as a certain format? And then after that, how do I execute these programs?

The only real language I have experience with is .Net and that was easy because you wrote the code and ran it from Visual Studio. Now I'm in a whole new world! Help, please!

Thanks in advance

Offline

#2 2008-03-02 02:52:20

Lazer
Banned
Registered: 2007-08-02
Posts: 111

Re: Python files

Open a text editor (Nano, Kate, Geany, etc.) and type your script. Then save the name as scriptname.py in whatever directory you wish.

To run the script, change to that directory in the terminal (cd /path/to/directory) and type "python scriptname.py" (no quotes). Alternatively, put this line at the top of your Python script:

#! /usr/bin/python

...or wherever your interpreter is installed. Then type "chmod 755 scriptname.py" (no quotes) and to execute it, type "./scriptname.py" (from here on, just assume no quotes). If the directory is in your PATH, just type "scriptname.py". To make a program executable without the .py part, just add that line to the script (saved without a file extension, the line tells the computer what to use for the file), "chmod 755 scriptname", and to execute, "./scriptname". Again, if it's in your PATH, just type "scriptname".

Hope I helped!

EDIT: It would benefit you to use a syntax-highlighting editor, such as Gedit or Bluefish, etc. so you can keep easier track of your code.

Last edited by Lazer (2008-03-02 02:54:45)

Offline

#3 2008-03-02 02:58:32

Xs1t0ry
Member
From: Canada
Registered: 2007-07-01
Posts: 181

Re: Python files

Thank you, you did!

Offline

#4 2008-03-02 02:59:24

Lazer
Banned
Registered: 2007-08-02
Posts: 111

Re: Python files

Glad I could help. Now I'm going to go register for my own account. BugMeNot is great, but I want to get credit for my posts!

Offline

#5 2008-03-02 03:19:09

sajro
Member
Registered: 2008-03-02
Posts: 56

Re: Python files

No it's not more help. It's me with my own account. However, I just wanted to say...

NO FREAKING FAIR! YOU'RE CANADIAN! I WANNA BE CANADIAN! IT SUCKS HERE IN THE U.S.A!

So many people are so idiotic. I know a few Canadians and it seems that your people are held to a higher average intelligence. I feel like so many Americans are too arrogant and ignorant compared to the Canadians I've met.

Offline

Board footer

Powered by FluxBB