Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to open .py file?

  1. Jan 12, 2012 #1

    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 :)
  2. jcsd
  3. Jan 12, 2012 #2


    User Avatar
    Science Advisor

    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.
  4. Jan 12, 2012 #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.
  5. Jan 12, 2012 #4
    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.
  6. Jan 12, 2012 #5
    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)
  7. Jan 12, 2012 #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?
  8. Jan 12, 2012 #7


    User Avatar
    Science Advisor
    Homework Helper

    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.
  9. Jan 12, 2012 #8
    Ah... Well, that's a pity!

    Thanks for your input!
  10. Jan 12, 2012 #9


    User Avatar
    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:
  11. Jan 15, 2012 #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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook