By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Python 123 introduction

P: n/a
Here is a brief simple introduction to Python I wrote for a computing course
for graduate astronomers. It assumes some programming experience. Although
it is not a complete guide, I believe this could be a useful document for
other groups to learn Python, so I'm making it available for others to
download, and modify for their own needs (some of the content is site
specific).

HTML version:
http://www-xray.ast.cam.ac.uk/~jss/l...ut/python_123/
Postscript LaTeX output:
http://www-xray.ast.cam.ac.uk/~jss/l.../python_123.ps
PDF LaTeX output:
http://www-xray.ast.cam.ac.uk/~jss/l...python_123.pdf
LaTeX source:
http://www-xray.ast.cam.ac.uk/~jss/l...python_123.tex

Jeremy

--
Jeremy Sanders
http://www.jeremysanders.net/
Oct 30 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
This is great! A excellent tutorial for somone who has prior experience
in programming and is starting out in python. My friend keeps wanting
me to teach him python, I think this would be the perfect link for him.
Thanks.
Jeremy Sanders wrote:
Here is a brief simple introduction to Python I wrote for a computing course
for graduate astronomers. It assumes some programming experience. Although
it is not a complete guide, I believe this could be a useful document for
other groups to learn Python, so I'm making it available for others to
download, and modify for their own needs (some of the content is site
specific).

HTML version:
http://www-xray.ast.cam.ac.uk/~jss/l...ut/python_123/
Postscript LaTeX output:
http://www-xray.ast.cam.ac.uk/~jss/l.../python_123.ps
PDF LaTeX output:
http://www-xray.ast.cam.ac.uk/~jss/l...python_123.pdf
LaTeX source:
http://www-xray.ast.cam.ac.uk/~jss/l...python_123.tex

Jeremy

--
Jeremy Sanders
http://www.jeremysanders.net/
Oct 30 '06 #2

P: n/a
da****@gmail.com wrote:
This is great! A excellent tutorial for somone who has prior experience
in programming and is starting out in python. My friend keeps wanting
me to teach him python, I think this would be the perfect link for him.
I'm glad you think it is useful. It needs a bit of cleaning up as it assumes
things such as python being in /usr/local/bin... I may try to improve this
later.

Jeremy

--
Jeremy Sanders
http://www.jeremysanders.net/
Oct 30 '06 #3

P: n/a

dakmanThis is great! A excellent tutorial for somone who has prior
dakmanexperience in programming and is starting out in python. My
dakmanfriend keeps wanting me to teach him python, I think this would
dakmanbe the perfect link for him.

I'm not trying to minimize Jeremy's efforts in any way, but how is his
tutorial a significant improvement over the original
(http://www.python.org/doc/current/tut/)?

Skip
Oct 30 '06 #4

P: n/a
sk**@pobox.com wrote:
I'm not trying to minimize Jeremy's efforts in any way, but how is his
tutorial a significant improvement over the original
(http://www.python.org/doc/current/tut/)?
It's not intended as a replacement, but what I wanted to do was write a
quick 2 hour course for people to work through. It overlaps quite a bit
with the tutorial, but I tried to minimise any detail.

I just publicised it in case anybody wanted something similar.

Jeremy

--
Jeremy Sanders
http://www.jeremysanders.net/
Oct 30 '06 #5

P: n/a
sk**@pobox.com wrote:
I'm not trying to minimize Jeremy's efforts in any way, but how is his
tutorial a significant improvement over the original
(http://www.python.org/doc/current/tut/)?
don't forget the community-enhanced edition over at:

pytut.infogami.com

</F>

Oct 30 '06 #6

P: n/a
sk**@pobox.com wrote:
dakmanThis is great! A excellent tutorial for somone who has prior
dakmanexperience in programming and is starting out in python. My
dakmanfriend keeps wanting me to teach him python, I think this would
dakmanbe the perfect link for him.

I'm not trying to minimize Jeremy's efforts in any way, but how is his
tutorial a significant improvement over the original
(http://www.python.org/doc/current/tut/)?

Skip
well, not to minimize the efforts of guido's tutorial, but sometimes it
seems less of a tutorial and more of a summary of python's features, so
it never hurts to have things explained in a different way...
Oct 30 '06 #7

P: n/a
Jeremy Sanders a écrit :
Here is a brief simple introduction to Python I wrote for a computing course
for graduate astronomers. It assumes some programming experience. Although
it is not a complete guide, I believe this could be a useful document for
other groups to learn Python, so I'm making it available for others to
download, and modify for their own needs (some of the content is site
specific).
May I emit some observations and suggest a couple of corrections ?

"""
To make it executable type chmod +x test.py, then run it by typing its
name, test.py on the unix prompt
"""

Unless the current directory is in the path, this won't work:
bruno@bibi ~ $ cat toto.py
#!/usr/bin/python
print 'hello'
bruno@bibi ~ $ chmod +x toto.py
bruno@bibi ~ $ toto.py
-bash: toto.py: command not found
bruno@bibi ~ $ ./toto.py
hello
bruno@bibi ~ $

">>a+b # the value is printed at the prompt"
s/value/result/

"Numbers can be integers (int, whole numbers) or floating point (float)"
s/Numbers/Numeric objects/

"Strings are collections of characters"
s/Strings/String objects/

"Lists are collections of any types of variable (even lists)"
List objects are ordered collections of any type of objects (even other
lists)

"Tuples are like lists but they cannot be changed"
s/Tuples/Tuple objects/

<side-note>
Semantically, a tuple is more a kind of record - a dict indexed by
position - than an immutable list. That is: lists are homogenous ordered
collections of arbitrary length. Neither the length of the collection
nor the position of an object in it have special meaning. While tuples
are fixed-length heterogenous ordered structures where both the number
of items and their positions are meaningfull. Canonically, a DB table
can be represented as a list of tuples.
</side-note>

"Files correspond to files on the disk"
File objects correspond to OS files.
>>import sys
type(sys.stdin)
<type 'file'>

"""
Note that immutable objects (like numbers, strings or tuples) do not
have this property.
>>a = 10 # makes a point to object 10
"""

NB : here '10' is not the id of the object, it's its value. So it should
be: # makes name 'a' point to an int object

"""
>>b = a # makes b point to object 10
a = 11 # makes a point to object 11
print b # prints 10
"""

Hem... This has nothing to do with ints being immutables:

a = [1] # makes 'a' point to a list
b = a # makes 'b' points to the same object
a = [1] # makes 'a' points to *another* list
print "a is b ? %s" % (a is b)

"""
In Python subroutines, procedures and functions are basically the same thing
"""

NB : The type is 'function'. They *always* return something
(implicitely, the None object).

"None is a special value meaning ``nothing''"
s/value/object/

"You can test whether something is None by using is None"
There's always only one single None object, so you can test whether
something is None by using 'is None'.

"""
a = ['foo', 'fred', 42]
for i in a:
print i
"""

Traditionaly, identifier 'i' is used as the current index in C-like
loops. Using it in this context might be a bit confusing :

a = ['foo', 'fred', 42]
for obj in a:
print obj

"""
As an aside, there is a shortcut version of loops called a list
comprehension which is very convenient:
"""

List comps are a "shortcut" for building lists. They are not a "shortcut
version of loops".

"""
filename = 'stupid.dat'
try:
f = open(filename)
except IOError: # the file did not open
print "The filename", filename, "does not exist!"
"""

Actually, the file may exist, but the program may not be able to open it
for other reasons...

filename = 'stupid.dat'
try:
f = open(filename)
except IOError, e: # the file did not open
print "could not open file %s : %s" % (filename, e)

My 2 cents...
Oct 31 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.