New Reply

How to open .py file?

 
Share Thread Thread Tools
Jan12-12, 06:56 AM   #1
 

How to open .py file?


Hello,

I'm trying to open the "Exponential atmosphere" simulation found on this site.

It's a .py file, so I downloaded python, more specifically 2.7 for windows (I have windows vista). I downloaded the .py file, but when I try to open, a command window opens for a second, but it immediately disappears (and nothing else happens).

How can I open such a file? I'm fully aware of how noobish this is :)
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Bird's playlist could signal mental strengths and weaknesses
>> Minus environment, patterns still emerge: Computational study tracks E. coli cells' regulatory mechanisms
>> Bacterium uses natural 'thermometer' to trigger diarrheal disease, scientists find
Jan12-12, 08:38 AM   #2
 
The .py file is just a text file, and you can open it with any text editor. In Windows, I think there is a NotePad or TextPad program that should open and edit the file. If that fails, you can probably open it with Microsoft Word.
Jan12-12, 09:11 AM   #3
 
But I think it's supposed to show a simulation? I have no intention of changing the code, I simply want to play the simulation.
Jan12-12, 09:43 AM   #4
 

How to open .py file?


open a command prompt first (Start>CMD)
then navigate to the folder where you have the python script downloaded
then try typing
"python.exe yourFileName.py" and see what it says

the way you are describing the issue, the script is opening a dos prompt but is terminated too quickly for you to read what it says. manually opening the dos prompt will prevent the output from being closed and you will be able to see what it says.
Jan12-12, 10:12 AM   #5
 
Blog Entries: 2
Alternatively, you can open the file with IDLE.

1) Starting IDLE:
In Windows go to:
Start -> all programs -> Python 2.7 -> IDLE (Python GUI)

2) Opening the file in IDLE:
After starting IDLE click on: File -> Open
Navigate to the file. Double click on it.

3) After double-clicking on the file a new window opens that shows the code.
Run it by clicking on: Run -> Run Module
(or just simply press F5)
Jan12-12, 12:08 PM   #6
 
Thank you for the replies!

At first I got the error that some indentations and spaces were unclear or something like that and it gave instructions how to clear that up (Untabify region) and I followed that correctly, and now it doesn't give that error anymore, but another one: it says it expected a tab somewhere. I then added the tab, but now it expects one somewhere else.

Is this a normal procedure? Is the file corrupt?
Jan12-12, 02:00 PM   #7

Math 2012
 
Recognitions:
Science Advisor Science Advisor
Python uses the indentation of lines of the source file to describe the structure of nested loops and if statements etc, instead of the syntax like { } , if - endif, etc of most other languages.

If something has messed up the number of tabs and/or spaces at the start of the lines in the .py file, that is probably very bad news.
Jan12-12, 02:09 PM   #8
 
Ah... Well, that's a pity!

Thanks for your input!
Jan12-12, 04:38 PM   #9
 
Blog Entries: 9
Recognitions:
Gold Membership Gold Member
Indentation is critical in Python. You'll have a lot of problems if you mix tab characters and spaces for indentation.

The accepted Python standard is to use 4 spaces per indentation level, as stated in PEP 8:
Quote by PEP 8
Indentation
Use 4 spaces per indentation level.

...

Tabs or Spaces?
Never mix tabs and spaces.

The most popular way of indenting Python is with spaces only. The
second-most popular way is with tabs only. Code indented with a mixture
of tabs and spaces should be converted to using spaces exclusively. When
invoking the Python command line interpreter with the -t option, it issues
warnings about code that illegally mixes tabs and spaces. When using -tt
these warnings become errors. These options are highly recommended!

For new projects, spaces-only are strongly recommended over tabs. Most
editors have features that make this easy to do.
Jan15-12, 09:39 PM   #10
 
I was just reading over this and wasn't sure if you still needed help or not. But, from what you are describing it sounds like 1 of 2 possible problems:

1) It's a compatibility problem, maybe it wasn't written for Python 2.7, but some other release version
2) Since python is mostly a scripting language, when you use it to be ran like that it needs special attention for things like text boxes and data output. Most likely there was an error with the code toward that output, it is a very common problem with python files that they will open a dialog box and immediately close it,the only solution being to rewrite that section of code.

Hope that helps.
New Reply
Thread Tools


Similar Threads for: How to open .py file?
Thread Forum Replies
Open a .pdf file from C++ Win32 Console Application Programming & Comp Sci 2
how to open xml file? Introductory Physics Homework 2
can any one help me me???? need a c program to open a file using c Programming & Comp Sci 3
can not open IR spectra file Chemistry 1
Help! File won't open: Computing & Technology 8