Re: [Tutor] Which version to start with?

2009-10-06 Thread Ken G.
I am just starting on Python 2.6.2 on Ubuntu 9.04 and I am slightly 
confused with the numerous tutorials and books available for learning 
the language.  Is there any good recommendation for a good but easy 
tutorial on the Internet to learn Python?


Ken

wesley chun wrote:

On Mon, Oct 5, 2009 at 2:24 PM, Nick Hird  wrote:
  

What is the best version of python to start out with? I see some
discussions on the net about not going to 3.1 but staying with the 2.x
releases. But then i see that 3.1 is better if your just starting.




greetings nick!

ironically, i just gave a talk on this very subject yesterday afternoon(!)
http://www.siliconvalley-codecamp.com/Sessions.aspx?OnlyOne=true&id=227

basically, if you're starting from scratch as a hobby with no
pre-existing code, then learning 3.x is okay. however, since most of
the world still runs on Python 2, most printed and online books and
tutorials are still on Python 2, and the code at most companies using
Python is still on version 2, i would recommended any release 2.6 (and
newer). the reason is because 2.6 is the first release that has
3.x-specific features backported to it, so really, it's the first
Python 2 release that lets you start coding against a 3.x interpreter.

you can learn Python using 2.6+ then absorb the differences and move
to Python 3.x quite easily.

hope this helps!
-- wesley

  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if n == 0 vs if not n

2009-10-06 Thread Wayne
On Mon, Oct 5, 2009 at 3:37 PM, Sander Sweers wrote:

> Thanks Wesly/Vern for the replies.
>
> On Mon, 2009-10-05 at 21:56 +0200, Luke Paireepinart wrote:
> > if not n == 0
> >
> > if b == True can be written as if b.
> >
> >
> > However,
> > if not n == 0 can be written as if n != 0 but NOT as if n.
> > The reason why is that 0 is not equivalent to False even though it
> > evaluates to False.
> > So
> > if not n:
> > would be true for n = 0 and for n = "" and for n = None
> > but
> > if n != 0:
> > would be true for n = "" and n = None but not n = 0.
>
> Ah, have not thought about this one. In this case it checks the return
> code of a subprocess command which if not zero means build failure. I am
> leaving these as they are because in my opinion "if not returncode == 0"
> shows clearer what is going on than "if returncode".
>

If it's checking the returncode against a value, Vern makes a good point:

if returncode != 0 makes a whole lot more sense than "if not returncode ==
0"

Though when dealing with an integer return code, doesn't it make more sense
to use the "is" operator?

if returncode is 0:
#do something

if returncode is not 0:
#do something

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which version to start with?

2009-10-06 Thread Wayne
On Tue, Oct 6, 2009 at 7:59 AM, Ken G.  wrote:

>  I am just starting on Python 2.6.2 on Ubuntu 9.04 and I am slightly
> confused with the numerous tutorials and books available for learning the
> language.  Is there any good recommendation for a good but easy tutorial on
> the Internet to learn Python?
>
> Ken
>

Alan has a good tutorial:
www.alan-g.me.uk/

I haven't read it, but a lot of others on here are big fans of Wesley's
book:
http://python.net/crew/wesc/cpp/

There are several other sources and tutorials around, those are just the
first two that popped into my mind :)

I kinda hopped around to various tutorials, especially since I've programmed
before (and am a CS major), so a lot of the concepts were a bit easier for
me to grasp.

Alan's tutorial does a great job explaining a lot of concepts behind
programming in general and ties them to programming in python.

HTH,
Wayne



>
> wesley chun wrote:
>
> On Mon, Oct 5, 2009 at 2:24 PM, Nick Hird  
>  wrote:
>
>
>  What is the best version of python to start out with? I see some
> discussions on the net about not going to 3.1 but staying with the 2.x
> releases. But then i see that 3.1 is better if your just starting.
>
>
>  greetings nick!
>
> ironically, i just gave a talk on this very subject yesterday 
> afternoon(!)http://www.siliconvalley-codecamp.com/Sessions.aspx?OnlyOne=true&id=227
>
> basically, if you're starting from scratch as a hobby with no
> pre-existing code, then learning 3.x is okay. however, since most of
> the world still runs on Python 2, most printed and online books and
> tutorials are still on Python 2, and the code at most companies using
> Python is still on version 2, i would recommended any release 2.6 (and
> newer). the reason is because 2.6 is the first release that has
> 3.x-specific features backported to it, so really, it's the first
> Python 2 release that lets you start coding against a 3.x interpreter.
>
> you can learn Python using 2.6+ then absorb the differences and move
> to Python 3.x quite easily.
>
> hope this helps!
> -- wesley
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Checking for Python version

2009-10-06 Thread Didar Hossain
Hi,

I am using the following code to check for the Python version -

import os

t = os.sys.version_info[0:2]
if (t[0] + t[1]) < 6:
os.sys.exit("Need at least Python 2.4")
del t

This snippet is put at the beginning of the single script file before
the rest of the code.
I need to check for the minimum specific version because I am using
the "@staticmethod"
directive.

Is there a prettier way or is this fine?

Regards,
Didar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which version to start with?

2009-10-06 Thread Lewis Chuang
As someone who learned (about) programming by copying and pasting code, 
I really appreciate," Python for software design - how to think like a 
computer scientist" by Allen Downey. It really talks you through the 
workflow of programming, rather than just give you a long list of things 
that you can do if you learn to program in X.


A legally free manuscript is available here:
http://www.greenteapress.com/thinkpython/

Best wishes,
Lewis

Wayne wrote:



On Tue, Oct 6, 2009 at 7:59 AM, Ken G. > wrote:


I am just starting on Python 2.6.2 on Ubuntu 9.04 and I am
slightly confused with the numerous tutorials and books available
for learning the language.  Is there any good recommendation for a
good but easy tutorial on the Internet to learn Python?

Ken


Alan has a good tutorial:
www.alan-g.me.uk/ 

I haven't read it, but a lot of others on here are big fans of 
Wesley's book:

http://python.net/crew/wesc/cpp/

There are several other sources and tutorials around, those are just 
the first two that popped into my mind :)


I kinda hopped around to various tutorials, especially since I've 
programmed before (and am a CS major), so a lot of the concepts were a 
bit easier for me to grasp.


Alan's tutorial does a great job explaining a lot of concepts behind 
programming in general and ties them to programming in python.


HTH,
Wayne

 



wesley chun wrote:

On Mon, Oct 5, 2009 at 2:24 PM, Nick Hird  
 wrote:
  

What is the best version of python to start out with? I see some
discussions on the net about not going to 3.1 but staying with the 2.x
releases. But then i see that 3.1 is better if your just starting.


greetings nick!

ironically, i just gave a talk on this very subject yesterday afternoon(!)
http://www.siliconvalley-codecamp.com/Sessions.aspx?OnlyOne=true&id=227 


basically, if you're starting from scratch as a hobby with no
pre-existing code, then learning 3.x is okay. however, since most of
the world still runs on Python 2, most printed and online books and
tutorials are still on Python 2, and the code at most companies using
Python is still on version 2, i would recommended any release 2.6 (and
newer). the reason is because 2.6 is the first release that has
3.x-specific features backported to it, so really, it's the first
Python 2 release that lets you start coding against a 3.x interpreter.

you can learn Python using 2.6+ then absorb the differences and move
to Python 3.x quite easily.

hope this helps!
-- wesley

  


___
Tutor maillist  -  Tutor@python.org 
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor




--
To be considered stupid and to be told so is more painful than being 
called gluttonous, mendacious, violent, lascivious, lazy, cowardly: 
every weakness, every vice, has found its defenders, its rhetoric, its 
ennoblement and exaltation, but stupidity hasn’t. - Primo Levi



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
  

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checking for Python version

2009-10-06 Thread Christian Witts

Didar Hossain wrote:

Hi,

I am using the following code to check for the Python version -

import os

t = os.sys.version_info[0:2]
if (t[0] + t[1]) < 6:
os.sys.exit("Need at least Python 2.4")
del t

This snippet is put at the beginning of the single script file before
the rest of the code.
I need to check for the minimum specific version because I am using
the "@staticmethod"
directive.

Is there a prettier way or is this fine?

Regards,
Didar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

  
Your version will fail if the person is running Python 3.0, 3.1 up until 
the 3.3 series which is not good.  Neater looking (imo) code below.


from sys import version_info, exit

if version_info[0] == 1 or (version_info[0] == 2 and version_info[1] < 4):
   exit("Please upgrade to Python 2.4 or greater.")

--
Kind Regards,
Christian Witts


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checking for Python version

2009-10-06 Thread Wayne
On Tue, Oct 6, 2009 at 9:26 AM, Christian Witts wrote:

> Didar Hossain wrote:
>
>> Hi,
>>
>> I am using the following code to check for the Python version -
>>
>> import os
>>
>> t = os.sys.version_info[0:2]
>> if (t[0] + t[1]) < 6:
>>os.sys.exit("Need at least Python 2.4")
>> del t
>>
>> This snippet is put at the beginning of the single script file before
>> the rest of the code.
>> I need to check for the minimum specific version because I am using
>> the "@staticmethod"
>> directive.
>>
>> Is there a prettier way or is this fine?
>
>
Is there anything wrong with using this?

import sys

if sys.version < '2.4':
   sys.exit("Need at least Python 2.4")

AFAIK the string comparison is reliable
-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checking for Python version

2009-10-06 Thread Steve Willoughby
On Tue, Oct 06, 2009 at 09:42:04AM -0500, Wayne wrote:
> On Tue, Oct 6, 2009 at 9:26 AM, Christian Witts wrote:
> if sys.version < '2.4':
>sys.exit("Need at least Python 2.4")
> 
> AFAIK the string comparison is reliable

Not quite. What happens when you compare '2.4' and '2.10'?


-- 
Steve Willoughby|  Using billion-dollar satellites
st...@alchemy.com   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checking for Python version

2009-10-06 Thread Wayne
On Tue, Oct 6, 2009 at 9:46 AM, Steve Willoughby  wrote:

> On Tue, Oct 06, 2009 at 09:42:04AM -0500, Wayne wrote:
> > On Tue, Oct 6, 2009 at 9:26 AM, Christian Witts  >wrote:
> > if sys.version < '2.4':
> >sys.exit("Need at least Python 2.4")
> >
> > AFAIK the string comparison is reliable
>
> Not quite. What happens when you compare '2.4' and '2.10'?
>

>>> '2.4' > '2.10'
True



>
>
> --
> Steve Willoughby|  Using billion-dollar satellites
> st...@alchemy.com   |  to hunt for Tupperware.
>



-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checking for Python version

2009-10-06 Thread Steve Willoughby
On Tue, Oct 06, 2009 at 09:47:43AM -0500, Wayne wrote:
> On Tue, Oct 6, 2009 at 9:46 AM, Steve Willoughby  wrote:
> 
> > On Tue, Oct 06, 2009 at 09:42:04AM -0500, Wayne wrote:
> > > On Tue, Oct 6, 2009 at 9:26 AM, Christian Witts  > >wrote:
> > > if sys.version < '2.4':
> > >sys.exit("Need at least Python 2.4")
> > >
> > > AFAIK the string comparison is reliable
> >
> > Not quite. What happens when you compare '2.4' and '2.10'?
> >
> 
> >>> '2.4' > '2.10'
> True

Exactly.  So it doesn't work.

In typical software release numbering, 2.10 is the tenth
minor version of the 2.x major version series, so 2.10 is
later than 2.4, but comparing as ASCII strings, it comes
out the other way around.

Also note that '10.1' < '5.7'

-- 
Steve Willoughby|  Using billion-dollar satellites
st...@alchemy.com   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if n == 0 vs if not n

2009-10-06 Thread Dave Angel

Wayne wrote:

On Mon, Oct 5, 2009 at 3:37 PM, Sander Sweers wrote:

  

Thanks Wesly/Vern for the replies.

On Mon, 2009-10-05 at 21:56 +0200, Luke Paireepinart wrote:


if not n == 0

if b == True can be written as if b.


However,
if not n == 0 can be written as if n != 0 but NOT as if n.
The reason why is that 0 is not equivalent to False even though it
evaluates to False.
So
if not n:
would be true for n = 0 and for n = "" and for n = None
but
if n != 0:
would be true for n = "" and n = None but not n = 0.
  

Ah, have not thought about this one. In this case it checks the return
code of a subprocess command which if not zero means build failure. I am
leaving these as they are because in my opinion "if not returncode == 0"
shows clearer what is going on than "if returncode".




If it's checking the returncode against a value, Vern makes a good point:

if returncode != 0 makes a whole lot more sense than "if not returncode ==
0"

Though when dealing with an integer return code, doesn't it make more sense
to use the "is" operator?

if returncode is 0:
#do something

if returncode is not 0:
#do something

-Wayne

  
No, because you're not assured that all integers that are equal are the 
same object.  Python optimizes that for small integers, but there's no 
documented range that you can count on it.


>>> x = 374
>>> y = 374
>>> print id(x), id(y)
12721272 12721296
>>> x==y
True
>>> x is y
False

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checking for Python version

2009-10-06 Thread Todd Zullinger
Christian Witts wrote:
> Your version will fail if the person is running Python 3.0, 3.1 up
> until the 3.3 series which is not good.  Neater looking (imo) code
> below.
>
> from sys import version_info, exit
>
> if version_info[0] == 1 or (version_info[0] == 2 and version_info[1] < 4):
>exit("Please upgrade to Python 2.4 or greater.")

This would fail on python < 2.0, as version_info is not available.  So
you'd want to catch that, if you want to gracefully handle ancient
versions of python.  You could also just compare the version_info
tuple.

This is a bit ugly, but it works at least back to 1.5.2:

import sys

min_version = '2.4'
upgrade_msg = 'Please upgrade to Python %s or greater' % min_version

try:
min = tuple(map(int, min_version.split('.')))
ver = sys.version_info[:3]
if ver < min:
sys.exit(upgrade_msg)
except AttributeError:
sys.exit(upgrade_msg)

I don't have any python 3.x systems to test though.

-- 
ToddOpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~
Suppose I were a member of Congress, and suppose I were an idiot. But,
I repeat myself.
-- Mark Twain



pgpHQ1caffg6U.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checking for Python version

2009-10-06 Thread Wayne
On Tue, Oct 6, 2009 at 9:57 AM, Steve Willoughby  wrote:

> On Tue, Oct 06, 2009 at 09:47:43AM -0500, Wayne wrote:
> > On Tue, Oct 6, 2009 at 9:46 AM, Steve Willoughby 
> wrote:
> >
> > > On Tue, Oct 06, 2009 at 09:42:04AM -0500, Wayne wrote:
> > > > On Tue, Oct 6, 2009 at 9:26 AM, Christian Witts <
> cwi...@compuscan.co.za
> > > >wrote:
> > > > if sys.version < '2.4':
> > > >sys.exit("Need at least Python 2.4")
> > > >
> > > > AFAIK the string comparison is reliable
> > >
> > > Not quite. What happens when you compare '2.4' and '2.10'?
> > >
> >
> > >>> '2.4' > '2.10'
> > True
>
> Exactly.  So it doesn't work.
>
> In typical software release numbering, 2.10 is the tenth
> minor version of the 2.x major version series, so 2.10 is
> later than 2.4, but comparing as ASCII strings, it comes
> out the other way around.
>
> Also note that '10.1' < '5.7'
>

Ah... I see now. A tuple comparison would work against the version though,
correct?

>>> import sys
>>> sys.version_info
(2, 6, 2, 'final', 0)
>>> sys.version_info > (2, 4, 0)
True
>>> sys.version_info > (2, 10, 0)
False
>>> sys.version_info > (1, 10, 0)
True

Which looks a lot cleaner (at least to me) than the OP... and has the
advantage of working for all versions ;)

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checking for Python version

2009-10-06 Thread Dave Angel

Didar Hossain wrote:

Hi,

I am using the following code to check for the Python version -

import os

t = os.sys.version_info[0:2]
if (t[0] + t[1]) < 6:
os.sys.exit("Need at least Python 2.4")
del t

This snippet is put at the beginning of the single script file before
the rest of the code.
I need to check for the minimum specific version because I am using
the "@staticmethod"
directive.

Is there a prettier way or is this fine?

Regards,
Didar

  

How about
 if sys.version_info < (2,4):

Incidentally, your particular approach has the problem of failing for 
3.1.  Perhaps that was intended, but it wasn't obvious.


DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checking for Python version

2009-10-06 Thread Christian Witts

Todd Zullinger wrote:

Christian Witts wrote:
  

Your version will fail if the person is running Python 3.0, 3.1 up
until the 3.3 series which is not good.  Neater looking (imo) code
below.

from sys import version_info, exit

if version_info[0] == 1 or (version_info[0] == 2 and version_info[1] < 4):
   exit("Please upgrade to Python 2.4 or greater.")



This would fail on python < 2.0, as version_info is not available.  So
you'd want to catch that, if you want to gracefully handle ancient
versions of python.  You could also just compare the version_info
tuple.

This is a bit ugly, but it works at least back to 1.5.2:

import sys

min_version = '2.4'
upgrade_msg = 'Please upgrade to Python %s or greater' % min_version

try:
min = tuple(map(int, min_version.split('.')))
ver = sys.version_info[:3]
if ver < min:
sys.exit(upgrade_msg)
except AttributeError:
sys.exit(upgrade_msg)

I don't have any python 3.x systems to test though.

  



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
  
Ah, I've only been using python since 2.2 so was not aware of this.  
Thanks for the heads-up.


--
Kind Regards,
Christian Witts


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if n == 0 vs if not n

2009-10-06 Thread Wayne
On Tue, Oct 6, 2009 at 9:58 AM, Dave Angel  wrote:

> 

No, because you're not assured that all integers that are equal are the same
> object.  Python optimizes that for small integers, but there's no documented
> range that you can count on it.
>
>
But for this specific case - checking a return code against zero, should it
still be considered unreliable? The only case that you are looking for
correctness is 0 == 0, any other case should evaluate as false, so I guess
the question is does python always optimize for zero? Any other optimization
is irrelevant, AFAIK.

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if n == 0 vs if not n

2009-10-06 Thread Andre Engels
On Tue, Oct 6, 2009 at 5:08 PM, Wayne  wrote:
> On Tue, Oct 6, 2009 at 9:58 AM, Dave Angel  wrote:
>>
>> 
>>
>> No, because you're not assured that all integers that are equal are the
>> same object.  Python optimizes that for small integers, but there's no
>> documented range that you can count on it.
>>
>
> But for this specific case - checking a return code against zero, should it
> still be considered unreliable? The only case that you are looking for
> correctness is 0 == 0, any other case should evaluate as false, so I guess
> the question is does python always optimize for zero? Any other optimization
> is irrelevant, AFAIK.

Never rely on optimizations like this being done, or on them not being
done. The only save way to code is having your code work in both
cases.


-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checking for Python version

2009-10-06 Thread Luke Paireepinart
On Tue, Oct 6, 2009 at 4:47 PM, Wayne  wrote:

>
> On Tue, Oct 6, 2009 at 9:46 AM, Steve Willoughby wrote:
>
>> On Tue, Oct 06, 2009 at 09:42:04AM -0500, Wayne wrote:
>> > On Tue, Oct 6, 2009 at 9:26 AM, Christian Witts > >wrote:
>> > if sys.version < '2.4':
>> >sys.exit("Need at least Python 2.4")
>> >
>> > AFAIK the string comparison is reliable
>>
>> Not quite. What happens when you compare '2.4' and '2.10'?
>>
>
> >>> '2.4' > '2.10'
> True
>
That was his point, 2.4 should be a lesser version than 2.10, so it should
not ask you to upgrade if you have 2.10, but this code will.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] advice on structuring a project

2009-10-06 Thread Serdar Tumgoren
Hi everyone,

I was wondering if anyone could offer advice as I try to simplify a
project I've been working on.

I have a set of classes that I've named models.py (following the
Django convention, though it's not technically a Django project or
app).

Inside that file, I had initially grouped together a number of
classes, subclasses and mixin classes. I've broken out the mixins into
a separate file and am now importing those as a module, which has
helped tame models.py quite a bit. Now I'm left with a number of
subclasses that add in certain functionalities that are not central to
the models themselves.

For instance, I have a class called FilingsParser and then a
FilingsParserAuto subclass which just triggers methods on the
FilingsParser when an instance is created:

class FilingsParserAuto(FilingsParser):
"""
A subclass of FilingsParser that adds methods for handling
House candidate committee filings.
"""
def __init__(self):
super(FilingsParserAuto, self).__init__()
self.get_filings()
self.purge_dupes()
self.extract_committee_ids()
self.create_committees()
self.add_reports()

That subclass is the one I'm using in a separate program that relies
on the "autofire" behavior. I have a number of these Auto subclasses
and it's resulted in a bit of bloat inside models.py.

So to finally ask the question -- would the above subclasses be better
defined as part of the program that requires the "auto" behavior? Or
is it preferable to create some sort of API or Auto module where these
sublasses live? I can see myself needing this behavior for other
projects, but again, it really isn't part of the core functionality of
the classes defined in models.py. I guess I'm wondering if there's a
convention for how to handle this type of thing...

Advice is greatly appreciated.

Serdar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to python: some advises for image processing tool

2009-10-06 Thread Nicola De Quattro
Excuse me for the mistake, this list is a little different with respect 
to Yahoo Groups. Below my comments:



Now I think I could begin with some simple script to come into the
Python world, so I'll start building the easiest components of final
tool (perhaps opening the image and rotate it).


That one should be fairly simple - my guess is it should take < 5 lines 
to do something like that with PIL or ImageMagick


I've read some documentation about this libraries, for now I think I'll 
use PIL(*), because it apparentely seems more similar to the approach I 
have just meet in the other programming language. On the other hand I 
think that starting with one or the other would be quitely unimportant 
for now.


My suggestion is this: Work with what you're comfortable with. If you 
want to use gedit and python interpreter, go ahead.


I'm agree, I'm starting with an automatic-parser editor with IDLE.

Thank you very much for your help, I shall return telling you my 
progression.


(*) PIL seems to support FITS file manipulation from release 1.1.5a1
http://effbot.org/zone/pil-changes-115.htm
It seems enough for my purposes.

Nik
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which version to start with?

2009-10-06 Thread Jerry Hill
On Tue, Oct 6, 2009 at 8:59 AM, Ken G.  wrote:
> I am just starting on Python 2.6.2 on Ubuntu 9.04 and I am slightly confused
> with the numerous tutorials and books available for learning the language.
> Is there any good recommendation for a good but easy tutorial on the
> Internet to learn Python?

I'm fond of the official python tutorial: http://docs.python.org/tutorial/

-- 
Jerry
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What language should I learn after Python?

2009-10-06 Thread Mark Young
I'm now fairly familiar with Python, so I'm thinking about starting to learn
a second programming language. The problem is, I don't know which to learn.
I want a language that will be good for me to learn, but is not so different
from python that I will be totally confused. I tried learning C++ and it was
a massive failure, so I definitely think I'd like to stay closer to a
high-level language. I know that this is a subjective question, but I'd
still like to hear some suggestions if anyone has any.

Also, I wasn't really sure if it was okay to ask this on tutor, if it's the
wrong place, I'm sorry.

Mark Young
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Serdar Tumgoren
Hi Mark,

I recently started dabbling with Java, which has some great texts on
object-oriented design and patterns (a skill that I'm finding helps
with Python).

If you have time on your hands, you might want to consider learning a
programming language that has a different philosophy or approach than
Python. So instead of Ruby (which I've found is strikingly similar to
Python in many respects), you might want to consider a language like
Lisp or Erlang.

I'm no expert though, so I'll just point you to the article where I
first encountered that advice:

Teach Yourself Programming in Ten Years
http://www.norvig.com/21-days.html

And the portion relevant to your question:

"Learn at least a half dozen programming languages. Include one
language that supports class abstractions (like Java or C++), one that
supports functional abstraction (like Lisp or ML), one that supports
syntactic abstraction (like Lisp), one that supports declarative
specifications (like Prolog or C++ templates), one that supports
coroutines (like Icon or Scheme), and one that supports parallelism
(like Sisal)."

Good luck with the learning!

Regards,
Serdar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Che M



> programming language. The problem is, I don't know which to learn. I want a 
> language 
> that will be good for me to learn, 

Good for you in what way?  Is there a general "good for you" for programming, 
or do you need to achieve a certain goal?  From a jobs point of view, Java 
seems pretty in-demand.  From a stretching-your-mind point of view, maybe a 
rather different language would be better?

> I tried learning C++ and it was a massive failure, 

Earlier today today I picked up "C++ for Dummies" for $0.25 at a library sale 
bin just on the off chance I might try to learn a bit of it.  Not sure I will.  
But I'm curious:  why was it a massive failure?  

Che
  
_
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141664/direct/01/___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if n == 0 vs if not n

2009-10-06 Thread Sander Sweers
Thanks all for the informative discussion. To re-confirm it was mostly
for boolean checks like "if b == True".

Greets
Sander

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] advice on structuring a project

2009-10-06 Thread Serdar Tumgoren
> I don't think there is a "right" answer to this question. It depends
> on how the classes are used and related to each other. If the Auto
> classes are related or if they are useful to more than one client,
> perhaps you should make an auto_models.py to hold them. If they are
> only useful to individual projects you might include each one with its
> client.
>
I kinda figured there might not be any one way to do this. I do like
the auto_models idea though. Thanks as always for the help.

Serdar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Mark Young
 I have no real need to learn anything for a job, it's just a hobby right
now. I mostly just want "a programming language that has a different
philosophy or approach than
Python".  However, you guys are right, if I just learn a language without a
reason, it will be worthless.

When I tried to learn C++, I just got extremely confused, I didn't even
understand the basic "Hello World" script. I may have given up too quickly;
maybe I should try again, or maybe I'll try C.

I was thinking about Java, and I heard about Lisp, I heard that it would
supposedly make you a better programmer or something. I looked at Lisp, but
I wasn't sure which one to use, Scheme or Common Lisp. I think I heard the
same about Haskell, but I'm not sure if I'm remembering correctly.

Thanks for the suggestions so far. I'm thinking about trying to go back to
C++ or C, to study a a lower level language, or maybe Lisp, just to see
different techniques in a high level language. I guess I have to accept that
things will be different in any language, and if I want to learn different
methods and gain new abilities, I'll just have suck it up and start reading.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Serdar Tumgoren
Well, it's admirable that you're wiling to stick with it and learn
something new.

One other resource that I've personally been meaning to look into but
just haven't had time is Programming from the Ground Up. It teaches
computer science using Assembly language, quite literally from the
"ground up."

Here's the intro graf from the site:

"This is an introductory book to programming and computer science
using assembly language. It assumes the reader has never programmed
before, and introduces the concepts of variables, functions, and flow
control. The reason for using assembly language is to get the reader
thinking in terms of how the computer actually works underneath.
Knowing how the computer works from a "bare-metal" standpoint is often
the difference between top-level programmers and programmers who can
never quite master their art."

Using that as a starting point might help you wrap your brain around
some of the concepts in C, C++, etc. (though again, I'd defer to the
experts on this list).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Serdar Tumgoren
Sorry, forgot the link:

Programming from the Ground Up
http://savannah.nongnu.org/projects/pgubook/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Luke Paireepinart
On Tue, Oct 6, 2009 at 9:39 PM, Mark Young  wrote:

> I'm now fairly familiar with Python, so I'm thinking about starting to
> learn a second programming language. The problem is, I don't know which to
> learn. I want a language that will be good for me to learn, but is not so
> different from python that I will be totally confused. I tried learning C++
> and it was a massive failure, so I definitely think I'd like to stay closer
> to a high-level language. I know that this is a subjective question, but I'd
> still like to hear some suggestions if anyone has any.
>
> Also, I wasn't really sure if it was okay to ask this on tutor, if it's the
> wrong place, I'm sorry.
>

We generally don't mind questions regarding other programming languages.
 It's really important for professionals to have multiple languages in their
background, and it helps hobbyists too.

What sorts of things do you want to write?  If you're interested in web
development, Ruby may be a good choice.  Perl and PHP are common as well,
but (IMHO) have some quirks and design issues that always frustrate me.

Depending on your requirements, you may not even need to learn another
language, but it's definitely helpful if you do want to do it anyway.  You
may want to look at Java, although I personally do not like Java very much.
 I think the most useful second language would probably be C++, because you
can extend Python with it, and cover Python's only real weakness, the
interpreter speed.  But if you can't seem to wrap your head around it,
that's understandable.  It's not a very user-friendly language.  Have you
tried learning C?  That might be easier for you to pick up.

Anyway, you really need to learn a language that you can use for something
you want to accomplish, otherwise there will be no point in learning the
language other than learning it, and you really have to write code to get
familiar with a language (not just its syntax), so it would help if it were
something you wanted to do.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] advice on structuring a project

2009-10-06 Thread Kent Johnson
On Tue, Oct 6, 2009 at 2:26 PM, Serdar Tumgoren  wrote:

> I have a set of classes that I've named models.py (following the
> Django convention, though it's not technically a Django project or
> app).
>
> Inside that file, I had initially grouped together a number of
> classes, subclasses and mixin classes. I've broken out the mixins into
> a separate file and am now importing those as a module, which has
> helped tame models.py quite a bit. Now I'm left with a number of
> subclasses that add in certain functionalities that are not central to
> the models themselves.
>
> For instance, I have a class called FilingsParser and then a
> FilingsParserAuto subclass which just triggers methods on the
> FilingsParser when an instance is created:
>
> class FilingsParserAuto(FilingsParser):
>
> That subclass is the one I'm using in a separate program that relies
> on the "autofire" behavior. I have a number of these Auto subclasses
> and it's resulted in a bit of bloat inside models.py.
>
> So to finally ask the question -- would the above subclasses be better
> defined as part of the program that requires the "auto" behavior? Or
> is it preferable to create some sort of API or Auto module where these
> sublasses live?

I don't think there is a "right" answer to this question. It depends
on how the classes are used and related to each other. If the Auto
classes are related or if they are useful to more than one client,
perhaps you should make an auto_models.py to hold them. If they are
only useful to individual projects you might include each one with its
client.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Marc Tompkins
On Tue, Oct 6, 2009 at 12:39 PM, Mark Young  wrote:

> I'm now fairly familiar with Python, so I'm thinking about starting to
> learn a second programming language. The problem is, I don't know which to
> learn. I want a language that will be good for me to learn, but is not so
> different from python that I will be totally confused.
>

May I suggest (some dialect of) SQL?  It _is_ quite different from Python,
but learning it will familiarise you with some concepts that will be very
useful if you want to use your Python skillz in a data-driven application.
 It's true that you can use Python modules to interface with databases, and
maybe never write more than a line or two of real SQL - but those modules
are a lot easier to understand if you know what they're doing under the
hood.

-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if n == 0 vs if not n

2009-10-06 Thread Kent Johnson
On Tue, Oct 6, 2009 at 11:08 AM, Wayne  wrote:
> On Tue, Oct 6, 2009 at 9:58 AM, Dave Angel  wrote:
>>
>> 
>>
>> No, because you're not assured that all integers that are equal are the
>> same object.  Python optimizes that for small integers, but there's no
>> documented range that you can count on it.
>>
>
> But for this specific case - checking a return code against zero, should it
> still be considered unreliable?

Yes. It is undocumented, implementation-specific behaviour and you
should not depend on it without good reason. In this case, there is no
reason at all to prefer "if x is 0" to "if x == 0".

> The only case that you are looking for
> correctness is 0 == 0, any other case should evaluate as false, so I guess
> the question is does python always optimize for zero? Any other optimization
> is irrelevant, AFAIK.

Define "always". In all past and future versions of every
implementation of Python? Unlikely and unknowable. In all current
versions of CPython? Yes, AFAIK.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if n == 0 vs if not n

2009-10-06 Thread Kent Johnson
On Tue, Oct 6, 2009 at 9:04 AM, Wayne  wrote:

> If it's checking the returncode against a value, Vern makes a good point:
> if returncode != 0 makes a whole lot more sense than "if not returncode ==
> 0"
> Though when dealing with an integer return code, doesn't it make more sense
> to use the "is" operator?
> if returncode is 0:
>     #do something
> if returncode is not 0:
>     #do something

No! Equality and identity are different. CPython does cache small
integers but that is an implementation detail that you should not rely
on. For large values you cannot presume that equal numbers are also
identical. For example:

In [1]: a=10

In [2]: b=10

In [3]: a==b
Out[3]: True

In [4]: a is b
Out[4]: False

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Alan Gauld

"Mark Young"  wrote


I have no real need to learn anything for a job, it's just a hobby right
now. I mostly just want "a programming language that has a different
philosophy or approach


In that case consider Lisp (probably via Scheme) or SmallTalk.
Both are apparemtly different to Python but once you get under
the covers you wuill see where a lot of the thought behind Python
originated. And there are some very good free books for both.

Given a choice I'd  recommend Scheme (I'm actually going through
a Scheme course myself just now so maybe I'm biased!). One of
the best books from a widening horizons perspective is Hiow to
Design Programs (HTDP) and then try the slighlty more academic
Structure and Interpretation of Computer Programs(SICP). Both
are paper books that are also on the web.

If they prove too heavy then try and find a library copy of the Little
Lisper (or nowadays the Little Schemer). This short book takes a very
unusual approach to teaching program but has a lot in common
with HTDP in teaching a "formula" for writing well designed functons.


When I tried to learn C++, I just got extremely confused, I didn't even
understand the basic "Hello World" script. I may have given up too 
quickly;

maybe I should try again, or maybe I'll try C.


I'd definitely go for C before C++. For one thing you can do a lot in
Linux and Python without any C++ and for another most of the complexity
in C++ stems from the fact it is a very near superset of C and bolting OOP
onto C leads to some wierd things happening!

supposedly make you a better programmer or something. I looked at Lisp, 
but
I wasn't sure which one to use, Scheme or Common Lisp. I think I heard 
the

same about Haskell, but I'm not sure if I'm remembering correctly.


Haskell is another interesting option but p[robably too far from mainstream
to be worthwhile just yet. THe principles of functional programming can be
learned just as well using Lisp. And Lisp crops up a lot more often in real 
life

(in Emacs for one thing!)

things will be different in any language, and if I want to learn 
different
methods and gain new abilities, I'll just have suck it up and start 
reading.


Finally somebody already suggested SQL and thats a must do at some stage.
Also if you want to do anything on the Web you will need a minimal 
JavaScript

knowledge and it too has some interesting concepts behind it once you get
past doing cut n paste mash ups. (eg protocol based OOP). You can get
the basics of JavaScript by comparing it with Python in my tutorial...

Pick one and have fun. If its not fun don't bust a gut, try another.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Senthil Kumaran
On Tue, Oct 06, 2009 at 03:39:36PM -0400, Mark Young wrote:
> I'm now fairly familiar with Python, so I'm thinking about starting to learn a
> second programming language. The problem is, I don't know which to learn. I

You have already got a lot of healthy advice in this thread.
I would like to suggest that you might take up some project which
involves a lot of python and little bit of a different language (Java
Script, if it's a webbased project). In that way, you will hone your
python skills and additionally start learning the new language.

Just look around at Google App Engine and see if you can think of any
project (simple one), and try implmenting it. You might end up using
JavaScript/HTML.

I am learning www.alice.org after Python. It is too much fun!

-- 
Senthil
Be careful of reading health books, you might die of a misprint.
-- Mark Twain
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Mark Young
Ok, thanks alot everybody. I think I'll start with either Scheme or C, I
haven't decided yet. I was pleasantly surprised by how Scheme looks, it's
much prettier than some other languages I looked at.

Contributing to a project actually sounds like a good idea, I've never done
a project with other people before, so it would definitely be helpful, for
both my Python and for whatever language I pick up. I think I may wait a bit
though, so I can actually help someone instead of slowing them down.

Anyway, thanks everyone for the input, you've helped alot.

Mark Young
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Dave Angel

Mark Young wrote:

 I have no real need to learn anything for a job, it's just a hobby right
now. I mostly just want "a programming language that has a different
philosophy or approach than
Python".  However, you guys are right, if I just learn a language without a
reason, it will be worthless.

When I tried to learn C++, I just got extremely confused, I didn't even
understand the basic "Hello World" script. I may have given up too quickly;
maybe I should try again, or maybe I'll try C.

I was thinking about Java, and I heard about Lisp, I heard that it would
supposedly make you a better programmer or something. I looked at Lisp, but
I wasn't sure which one to use, Scheme or Common Lisp. I think I heard the
same about Haskell, but I'm not sure if I'm remembering correctly.

Thanks for the suggestions so far. I'm thinking about trying to go back to
C++ or C, to study a a lower level language, or maybe Lisp, just to see
different techniques in a high level language. I guess I have to accept that
things will be different in any language, and if I want to learn different
methods and gain new abilities, I'll just have suck it up and start reading.

  
One of the problems with C++ is that it insisted on being a superset of 
C, in order to gain acceptability.  And although it evolved away, C 
started evolving towards it, so they've been chasing each other down an 
interesting road.  And one of the advantages is that you can generally 
use the same compiler for both, and even link files made with one with 
ones made with the other.  I'd mention that out of the 25+ languages 
I've used professionally over the years, C++ is one of my top three 
favorites.


On the other hand, perhaps you should learn something that has 
practically nothing in common with Python.  Forth is at a different 
extreme.  The entire interpreter/compiler can be defined in maybe 50 
lines of (Forth) code.  It essentially has no syntax, and the programmer 
is free to add things that in other languages would be considered 
syntax.  To put it another way, IF is a library function that changes 
how the subsequent code gets compiled.  And although it's standard (or 
builtin if you prefer), there's nothing stopping you from building your 
own language extensions.  Symbols have no restrictions on character set, 
although generally it's tough to have embedded spaces in them.


I don't know how the language has evolved since the ANS standard (XJ14 I 
believe it was 1994);  I got into other things.  When I used it, 
extensive libraries were not a strong point.  But some of the concepts 
are mind-blowing.


Forth was originally conceived and used for astronomy, where the 
computer controls for a telescope had to be reprogrammed in minutes for 
changing weather conditions.  It then expanded many places where small 
execution size was essential, in embedded systems, pda's, etc.  There 
have been a few processors that essentially used Forth as their machine 
language, and programming was essentially the art of adding instructions 
to the machine.  I have such a machine in storage somewhere, which had 
4k of RAM and 4k of Prom.  Nearly half of that PROM was unneeded, as the 
compiler, interpreter, debugger and editor didn't need that much space.  
The RAM was limiting however, for doing problems involving lots of data.


DaveA


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread root
Want another functional language besides scheme? Haskell.

It looks pretty cool, and I want to learn it too.

Here's some resources:

A speach about haskell
http://www.infoq.com/interviews/armstrong-peyton-jones-erlang-haskell

Beginner's book
http://learnyouahaskell.com/introduction

Another book
http://book.realworldhaskell.org/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor