2

Python newbie here....I was interested in writing a basic touch typing tutor program in python. I was wondering what is the best way to download source code of applications that people have written that are of a similar nature (to use as a guide to learn from). I went to http://pypi.python.org/ and downloaded some packages but I'm not quite sure how to view the actual python code. Which file are you supposed to open. I found a run.py file in one of them and it doesn't seem to even work when I try to run it. I'm sure I'm missing something here.

Thanks!

2
  • 3
    View your files in your favourite text editor. I like Notepad++, but there are a gazillion different editors. Commented May 25, 2011 at 21:44
  • I don't know why people are voting to close it as "not a real question". It is not difficult to tell what OP is asking here. Sure, it is a simple question but OP has noted that he/she is a newbie. Just give a simple answer and move on. Commented May 25, 2011 at 22:02

3 Answers 3

4

You can also use inspect to view the code from the interpreter. So say your file is named "test.py" and it's on your PYTHONPATH (if you don't know what that is, then make sure you are in the same directory as "test.py").

>>> import inspect
>>> import test  # this imports test.py
>>> print inspect.getsource(test)   
def hello(name):
  print("Hello %s" % name)

If you were using IPython, then you could also do:

In [1]: import test
In [2]: test??

You can't edit the code like this... but you can view it.

Sign up to request clarification or add additional context in comments.

Comments

2

There is usually a README explaining things.

If not, the src/ directory is where you should start looking and open some files with a text editor like Notepad++.

Comments

1

Double-clicking a .py script will execute the script (and may not send any useful results to the screen). To view the source you can open a .py file with IDLE (which comes with Python) or even Notepad although a more advanced text editor or IDE is recommended. See Is there a good, free Python IDE for Windows for IDE recommendations by the stackoverflow community. Good luck, and welcome to the Python community!

2 Comments

@ Dhaivat Pandya seriously? Most of those IDEs exist on all popular platforms...and I bet you $10 he on windows.
a) Double clicking .py scripts don't execute on Linux b) He probably is on Windows, but, do you know already?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.