New to python

0 views
Skip to first unread message

e-tones.co.uk

unread,
Oct 20, 2002, 2:56:56 PM10/20/02
to
Hi all, im new to python, i have an oriely book on order, should get me
going.

Are there any decent reference sites I can peek at (im a seased programmer
btw, so the fundamentals will be fine). I see that if you want to use a
function you have to import it from the library at the top (grr :P), anyhow,
are there any more 'quirks' such as this I should know about ?

Also, whats the easiest way to see what data type is help in a variable? eg
string, integer etc.

And last but not least, whats the best place to find the different exception
handling techniques, the python.org site is obismal when compared to php.net
and the likes :( About as much use as a dead dog :(

Thanks to all who can help

Cheers,
Taz


Erik Max Francis

unread,
Oct 20, 2002, 4:36:08 PM10/20/02
to
"e-tones.co.uk" wrote:

> Are there any decent reference sites I can peek at (im a seased
> programmer
> btw, so the fundamentals will be fine). I see that if you want to use
> a
> function you have to import it from the library at the top (grr :P),
> anyhow,
> are there any more 'quirks' such as this I should know about ?

http://www.python.org/doc/

> Also, whats the easiest way to see what data type is help in a
> variable? eg
> string, integer etc.

type(x)

> And last but not least, whats the best place to find the different
> exception
> handling techniques, the python.org site is obismal when compared to
> php.net
> and the likes :( About as much use as a dead dog :(

Exception handling techniques are the same in Python as in other
languages with exception handling.

--
Erik Max Francis / m...@alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ Nothing you have said / Is revelation
\__/ The Russian, _Chess_
Sade Deluxe / http://www.sadedeluxe.com/
The ultimate Sade encyclopedia.

Brian Quinlan

unread,
Oct 20, 2002, 4:00:49 PM10/20/02
to
> Are there any decent reference sites I can peek at (im a seased
> programmer btw, so the fundamentals will be fine).

http://www.python.org/doc/current/tut/tut.html

> I see that if you want to use a function you have to import it from
> the library at the top (grr :P), anyhow, are there any more 'quirks'
> such as this I should know about ?

There are many ways to do imports:

>>> from math import sin, cos
>>> sin(5) + cos(2)
-1.3750711112102809

OR:

>>> import math
>>> math.tan(3) + math.ceil(5)
4.8574534569257226

OR:

>>> from math import *
>>> atan(2)
1.1071487177940904

The last method is not recommended because it can cause name collisions.

> Also, whats the easiest way to see what data type is help in a

> variable? Eg string, integer etc.

>>> foo = 5
>>> type(foo)
<type 'int'>

> And last but not least, whats the best place to find the
> different exception handling techniques,

Are you asking a design pattern question, are you looking for a list of
Python exception handling control structures or are you looking for a
list of builtin exception types?

> the python.org site is obismal when compared to php.net
> and the likes :( About as much use as a dead dog :(

Do you have any specific (i.e. useful) criticism? I quite like the
Python documentation.

Cheers,
Brian


Carl Caulkett

unread,
Oct 20, 2002, 6:49:23 PM10/20/02
to
On Sun, 20 Oct 2002 19:56:56 +0100, "e-tones.co.uk"
<ad...@e-tones.co.uk> wrote:

>Cheers,
>Taz

Is that Taz Higgins aka "The Taz" ? If so, are you still doing Delphi
stuff? I haven't seen you on the Borland newsgroups for many a long
month.

--
Carl

Alessandro Bottoni

unread,
Oct 20, 2002, 5:48:28 PM10/20/02
to
Alle 20:56, domenica 20 ottobre 2002, hai scritto:
> And last but not least, whats the best place to find the different
> exception handling techniques, the python.org site is obismal when compared
> to php.net and the likes :( About as much use as a dead dog :(

Taz, it is quite dangerous to speak your mind here in this way: you could be
killed for this ;-)

Anyway, please read at least these documents:

- the Python tutorial
- the Python library reference (just have a look at the available modules and
study the ones you need)

They both are included with the standard distribution.

You can find a lot of articles and examples at:

ASPN.activestate.com

And, please, read one or both of these books:

- Learning Python (beginner's level) - Lutz & Ascher for O'Reilly
- The Python Cookbook (from intermediate to advanced) - Martelli & Ascher for
O'Reilly

---------------------
Alessandro Bottoni


e-tones.co.uk

unread,
Oct 21, 2002, 1:09:40 PM10/21/02
to
Thats spooky... Im not taz higgins, but i program delphi! :D

wow, strange.
Taz


"Carl Caulkett" <car...@dircon.co.uk> wrote in message
news:5ic6rusts9cruhoas...@4ax.com...

Peter Hansen

unread,
Oct 21, 2002, 6:33:13 PM10/21/02
to
Alessandro Bottoni wrote:
> Alle 20:56, domenica 20 ottobre 2002, hai scritto:
>
>>And last but not least, whats the best place to find the different
>>exception handling techniques, the python.org site is obismal when compared
>>to php.net and the likes :( About as much use as a dead dog :(
>
>
> Taz, it is quite dangerous to speak your mind here in this way: you could be
> killed for this ;-)

Oh come, let's not exaggerate! While there have been the odd
times when a contributor has suddenly and without apparent
explanation gone offline for extended periods - even permanently -
and some have been replaced by new and advanced bots without
notice or fanfare, I can assure you that the PSU kills outspoken
contributors rather less frequently than it used to. These
days it is much more common simply to receive an unexpected

Bob Koss

unread,
Oct 22, 2002, 4:41:52 AM10/22/02
to
On 10/20/02 2:56 PM, in article 3db2fcc9$0$5803$fa0f...@lovejoy.zen.co.uk,
"e-tones.co.uk" <ad...@e-tones.co.uk> wrote:

> Hi all, im new to python, i have an oriely book on order, should get me
> going.
>


Similar question, but from a different angle....

I'm a very experienced C++/Java programmer. Can anyone recommend papers or
books that will help me avoid programming C++ using Python syntax and to
learn to do things the "Python way".

-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----

Steve Holden

unread,
Oct 22, 2002, 9:18:31 AM10/22/02
to
"e-tones.co.uk" <ad...@e-tones.co.uk> wrote ...

> Hi all, im new to python, i have an oriely book on order, should get me
> going.
>
> Are there any decent reference sites I can peek at (im a seased programmer
> btw, so the fundamentals will be fine). I see that if you want to use a
> function you have to import it from the library at the top (grr :P),
anyhow,
> are there any more 'quirks' such as this I should know about ?
>
Sorry the language isn't psychic :-)

> Also, whats the easiest way to see what data type is help in a variable?
eg
> string, integer etc.
>

The type(v) built-in returns the type of a value v.

> And last but not least, whats the best place to find the different
exception
> handling techniques, the python.org site is obismal when compared to
php.net
> and the likes :( About as much use as a dead dog :(
>

I'm sure we're all looking forward to your helpful improvements ... ;-)

Good luck with Python. I'm sure you'll enjoy it once you get going.

regards
-----------------------------------------------------------------------
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
Previous .sig file retired to www.homeforoldsigs.com
-----------------------------------------------------------------------

Mel Wilson

unread,
Oct 22, 2002, 9:47:24 AM10/22/02
to
In article <B9DA8790...@objectmentor.com>,

Bob Koss <ko...@objectmentor.com> wrote:
>I'm a very experienced C++/Java programmer. Can anyone recommend papers or
>books that will help me avoid programming C++ using Python syntax and to
>learn to do things the "Python way".

I dunno, I found the docs supplied with the Python
release to be very, very good. I ditched the O'Reilly books
(for the first time in my life) and just learned from the
docs.

I only know a little C++ and Java, but it seemed that
there was a pretty direct mapping of the useful parts.

Lose the braces, as you know them, and most of the
semicolons, obviously.

Where you would use `<vector T>`, use lists, or tuples ,,
that is [] or () . Where you would use `<map T1, T2>`, use
dictionaries ,, that is {} .

The semantics of iterators is available, but most of the
syntax goes away. `for item in alist:` iterates over all
the items in alist, one by one .. where `alist` is a
sequence, i.e. a list, tuple, or string. To iterate over a
sublist, use slices: `for item in alist[1:-1]:` does as
above, but omits the first and last items.

For trickier iterations, read and re-read the Library doc
on the topic of general-purpose functions. There are some
functions that apply to sequences: map, filter, reduce,
zip. that can work wonders. Hidden somewhere under the
documentation for sequences there is a description of string
methods that you'll want to read.

Hidden under the docs for 'Other Types' are the
descriptions of all the file methods. There are no
iostreams per se, but the class method __str__ can get some
of the effect for your own classes, and there are surely
other angles I haven't thought of.

Forget polymorphism. You can define a function, and call
it with anything you want, but if it has to behave
differently for different type operands, you have to use the
run-time type identification `type` function explicitely
within the single definition of the function. Default
arguments to functions are just as powerful a tool as in
C++.

In class definitions the equivalents of operator methods
are covered in a chapter in the Python Language Reference.
(Look for the double-underscore methods like __cmp__,
__str__, __add__, etc.)

In C, the gotcha for new users is probably about
pointers; they're tricky and they can't be avoided. The
gotchas in Python are situations when you use different
references to a single object, thinking you are using
different objects. I believe the difference between mutable
and immutable objects comes into play. I have no clear
answers here .. I still get caught once in a while .. keep
your eyes open.

Read the Tutorial once, skim the Library Reference .. at
least the table of contents, then skim the Language
Reference and you will probably have encountered everything
you need.

Regards. Mel.

Manuel M. Garcia

unread,
Oct 22, 2002, 1:12:06 PM10/22/02
to
This is one of the shortest and best summaries of Python programming I
have ever read! Perfect for people coming to Python from other
languages. We have to get it on python.org or pythonquotes!

On Tue, 22 Oct 2002 09:47:24 -0400, mwi...@the-wire.com (Mel Wilson)
wrote:

Martin Rand

unread,
Oct 24, 2002, 2:46:35 AM10/24/02
to
On Sun, 20 Oct 2002 19:56:56 +0100, "e-tones.co.uk"
<ad...@e-tones.co.uk> wrote:

>Hi all, im new to python, i have an oriely book on order, should get me
>going.
>
>Are there any decent reference sites I can peek at (im a seased programmer
>btw, so the fundamentals will be fine). I see that if you want to use a
>function you have to import it from the library at the top (grr :P), anyhow,
>are there any more 'quirks' such as this I should know about ?
>

If you're a seasoned programmer, you've probably worked on large
multi-person programming projects. In that case, I'm surprised you
object to explicit imports. But anyway, you don't have to import at
the top. As long as you import before you use, you can do it where you
please. Import conditionally, if you want.

The main thing to know about imports is that the code they contain is
executed the first time, and only the first time, they are 'import'ed.
OTOH the code they contain will be re-executed each time they are
'reload()'ed. I wouldn't consider that a quirk (I spent many happy
years programming Modula-2), but it's worth knowing about.

--
Martin Rand
Highfield Software Ltd
m...@highfield-software.co.uk
Phone: +44 (0)23 8025 2445
Fax: +44 (0)23 8025 2445

Andres Rosado

unread,
Oct 30, 2002, 8:34:54 PM10/30/02
to
At 06:46 AM 10/22/2002 -0400, you wrote:
>I'm a very experienced C++/Java programmer. Can anyone recommend papers or
>books that will help me avoid programming C++ using Python syntax and to
>learn to do things the "Python way".

For the "Python way", checking the tutorials at python.org helped me a lot.

For the other way around, it's difficult. But it helps you clean your C++ code.


--
Andres Rosado
Email: and...@despammed.com
ICQ: 66750646
Homepage: http://andres980.tripod.com/

Christianity has not been tried and found wanting; it has been found
difficult and not tried.
-- G.K. Chesterton


Andrei Sosnin505999200

unread,
Oct 31, 2002, 8:09:43 AM10/31/02
to

Andres Rosado wrote:
> At 06:46 AM 10/22/2002 -0400, you wrote:
>
>> I'm a very experienced C++/Java programmer. Can anyone recommend
>> papers or
>> books that will help me avoid programming C++ using Python syntax and to
>> learn to do things the "Python way".


I'd recommend "Dive into Python". It's available online:
http://www.diveintopython.org/

It's quite good for experienced programmers. It helped me a lot, too.

--
Andrei Sosnin
http://zzx.ath.cx
http://www.hot.ee/tomatensaft
---
<!-- : it all depends on your vision : -->

Reply all
Reply to author
Forward
0 new messages