473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Python 123 introduction

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
7 1642
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
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

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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: David MacQuigg | last post by:
I am starting a new thread so we can avoid some of the non-productive argument following my earlier post "What is good about Prothon". At Mr. Hahn's request, I will avoid using the name "Prothon"...
24
by: Charif Lakchiri | last post by:
Okay, here's what I know so far about Python: It's an object-oriented scripting language, supported on many platforms. Now here are my questions: It is easy to learn? Does it support GUI...
37
by: michele.simionato | last post by:
Paul Rubin wrote: > How about macros? Some pretty horrible things have been done in C > programs with the C preprocessor. But there's a movememnt afloat to > add hygienic macros to Python. Got any...
9
by: Paul DiRezze | last post by:
I'm spending the next two weeks off and I'm looking to take a crack at learning how to program in Python. Here's a list of the places I've bookmarked: http://www.python.org/doc/ and more...
0
by: Fuzzyman | last post by:
It's finally happened, `Movable Python <http://www.voidspace.org.uk/python/movpy/>`_ is finally released. Versions for Python 2.3 & 2.4 are available from `The Movable Python Shop...
11
by: John Coleman | last post by:
Greetings, My copy of the second edition of Chun's "Core Python Programming" just arrived from Amazon on Friday. What really jumped out at me is an interesting feature about how it sequences its...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
0
by: wesley chun | last post by:
Need to get up-to-speed with Python as quickly as possible? Come join me, Wesley Chun, author of Prentice-Hall's bestseller "Core Python Programming," for another comprehensive intro course plus a...
0
by: wesley chun | last post by:
*** FINAL REMINDER also, the course begins on monday immediately following the *free* CodeCamp conference http://siliconvalley-codecamp.com (click Program => Sessions to see all the talks)... 5...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.