Re: [Tutor] Function design

2009-10-27 Thread Benno Lang
On Tue, Oct 27, 2009 at 8:21 AM, Dave Angel  wrote:
> I agree with Luke's comments.  But I'd like to point out an apparent bug (I
> haven't tried the code, this is just by inspection).
>
> You use the test
>     if '0' in row[.]
>
> that's not going to check for a zero value, it's going to check for a zero
> digit character somewhere in the value.  So 504 would also be recognized, as
> well as 540.

I thought this sounded rather fishy, along the following lines:
row is a list, so slicing it returns a list, so 'in' should compare
the list elements (i.e. the strings contained therein) with '0'; this
seems perfectly normal.

I have checked, and thankfully the world is not upside down. It would
only work the way you describe if row was a string, or if 'in' called
itself recursively when it found a list.

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


Re: [Tutor] Compute data usage from log

2009-10-27 Thread bibi midi
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
Calculate internet data consumption
of service provider
Code as per help of python tutor mailing list
Created: 26-Oct-2009
'''

intro = raw_input('press enter to view your internet data consumption: ')
log_file = '/home/bboymen/mobily.data.plan'
total_consumed = 0
for line in open(log_file):
total_consumed += int(line.split(' ')[9])

total_consumed = total_consumed/100.0
print "total data consumed is: %0.3f MB\n" % total_consumed


#TODO:
#1) show the list comprehension alternative method
#2) add exception handling e.g. when log_file cant be found or when
key interrupt is pressed
#  or when index[9] is not a number, etc
#3) print latest date of calculated data


I'm working on TODO no. 3 e.g. I want to show the latest date when wvdial
generated the ppp data. This is normally the date of last line of the ppd:

Oct 14 11:03:45 cc02695 pppd[3092]: Sent 3489538 bytes, received
43317854 bytes.
^

For the exception handling i *think* i just use the general exception method
e.g. will catch all kinds of error. I really dont know what other errors
will show up aside from the ones i listed in the TODO. Advise is
appreciated.





On Mon, Oct 26, 2009 at 2:12 PM, Luke Paireepinart
wrote:

>
>
> On Mon, Oct 26, 2009 at 3:20 AM, Christian Witts 
> wrote:
>
>> fInput = open('/path/to/log.file', 'rb')
>> total_usage = 0
>> for line in fInput:
>>   total_usage += int(line.split(' ')[9].strip())
>> print total_usage
>>
>
> It's actually bad to assign a variable to the file object in this case
> (flinput = ) because Python will automatically close a file after you're
> done with it if you iterate over it directly, but if you include a reference
> it will stay open until the python program ends or you explicitly call
> flinput.close().  It doesn't matter much in this example but in general it
> is good practice to either
> 1) call foo.close() immediately after you're done using a file object, or
> 2) don't alias the file object and just over it directly so Python will
> auto-close it.
>
> Therefore a better (and simpler) way to do the above would be:
>
> total_usage = 0
> for line in open('/path/to/log.file'):
> total_usage += int(line.split(' ')[9])
>
> Also note you don't need to strip the input because int() coersion ignores
> whitespace anyway. And additionally you shouldn't be opening this in binary
> mode unless you're sure you want to, and I'm guessing the log file is ascii
> so there's no need for the 'rb'.  (reading is default so we don't specify an
> 'r'.)
>
>
> And since I like list comprehensions a lot, I'd probably do it like this
> instead:
>
> total_usage = sum([int(line.split(' ')[9]) for line in
> open('/path/to/log.file')])
>
> Which incidentally is even shorter, but may be less readable if you don't
> use list comprehensions often.
>
> Also, the list comprehension version is likely to be more efficient, both
> because of the use of sum rather than repeated addition (sum is implemented
> in C) and because list comprehensions in general are a tad faster than
> explicit iteration, if i recall correctly (don't hold me to that though, I
> may be wrong.)
>
>>
>> Of course this has no error checking and or niceties, but I will leave
>> that up to you.
>
> The same applies to my modifications.
>
> Good luck, and let us know if you need anything else!
>
> -Luke
>



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


Re: [Tutor] Compute data usage from log

2009-10-27 Thread Christian Witts

bibi midi wrote:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
Calculate internet data consumption
of service provider
Code as per help of python tutor mailing list
Created: 26-Oct-2009

'''

intro = raw_input('press enter to view your internet data consumption: ')
log_file = '/home/bboymen/mobily.data.plan'
total_consumed = 0
for line in open(log_file):
total_consumed += int(line.split(' ')[9])


total_consumed = total_consumed/100.0
print "total data consumed is: %0.3f MB\n" % total_consumed


#TODO: 
#1) show the list comprehension alternative method

#2) add exception handling e.g. when log_file cant be found or when key 
interrupt is pressed

#  or when index[9] is not a number, etc
#3) print latest date of calculated data
  

I'm working on TODO no. 3 e.g. I want to show the latest date when 
wvdial generated the ppp data. This is normally the date of last line 
of the ppd:


Oct 14 11:03:45 cc02695 pppd[3092]: Sent 3489538 bytes, received 
43317854 bytes.

^

For the exception handling i *think* i just use the general exception 
method e.g. will catch all kinds of error. I really dont know what 
other errors will show up aside from the ones i listed in the TODO. 
Advise is appreciated.






On Mon, Oct 26, 2009 at 2:12 PM, Luke Paireepinart 
mailto:rabidpoob...@gmail.com>> wrote:




On Mon, Oct 26, 2009 at 3:20 AM, Christian Witts
mailto:cwi...@compuscan.co.za>> wrote:

fInput = open('/path/to/log.file', 'rb')
total_usage = 0
for line in fInput:
  total_usage += int(line.split(' ')[9].strip())
print total_usage


It's actually bad to assign a variable to the file object in this
case (flinput = ) because Python will automatically close a
file after you're done with it if you iterate over it directly,
but if you include a reference it will stay open until the python
program ends or you explicitly call flinput.close().  It doesn't
matter much in this example but in general it is good practice to
either
1) call foo.close() immediately after you're done using a file
object, or
2) don't alias the file object and just over it directly so Python
will auto-close it.

Therefore a better (and simpler) way to do the above would be:

total_usage = 0
for line in open('/path/to/log.file'):
total_usage += int(line.split(' ')[9])

Also note you don't need to strip the input because int() coersion
ignores whitespace anyway. And additionally you shouldn't be
opening this in binary mode unless you're sure you want to, and
I'm guessing the log file is ascii so there's no need for the
'rb'.  (reading is default so we don't specify an 'r'.)


And since I like list comprehensions a lot, I'd probably do it
like this instead:

total_usage = sum([int(line.split(' ')[9]) for line in
open('/path/to/log.file')])

Which incidentally is even shorter, but may be less readable if
you don't use list comprehensions often.

Also, the list comprehension version is likely to be more
efficient, both because of the use of sum rather than repeated
addition (sum is implemented in C) and because list comprehensions
in general are a tad faster than explicit iteration, if i recall
correctly (don't hold me to that though, I may be wrong.)


Of course this has no error checking and or niceties, but I
will leave that up to you.

The same applies to my modifications.

Good luck, and let us know if you need anything else!

-Luke




--
Best Regards,
bibimidi




Exceptions:
* Not finding the log file would be IOError.
* Casting an alphanumeric or alpha string to integer would be a 
ValueError, in this context you won't have a None so you shouldn't need 
to worry about a TypeError
* Selecting the 10th element in your list can raise an IndexError if 
your line did not contain enough delimiters to create a large enough list.


Pedantic:
1MB = 1,024KB = 1,024*1,024B
So your total consumed should be div (1024*1024.0) or div 1048576.0

For the date you can look at the time module to get a nice string 
representation of the date/time.  Or as you said you want the last date 
listed in the log file then you could add something like


for line in open(log_file):
   last_log_date = ' '.join(line.split(' ')[:3]

which would take the first 3 elements in your list and combine them 
again.  Of course this is again just a simple representation of what to do.


--
Kind Regards,
Christian Witts


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


[Tutor] How to load a dict into a dict subclass?

2009-10-27 Thread Modulok
List,

I'm new to the list, (somewhat new to python too). My code feels
hacky. I'd like to know if there is a more eloquent way (more below).
If not, a general thumbs up from more experienced programmers would be
great!

Assume I have a dict, 'foo'. I also have my own class, 'Bar', which
subclasses (i.e. is a derived class) of a dict. How do I eloquently
get foo into an instace of Bar? Example:


### BEGIN CODE:
class Bar(dict):
   pass # Act like a dict for now.

foo = {'a': 100, 'b': 200, 'c': 300} # This could be a function return value.
myvar = Bar()
# The hacky feeling part:
for k,v in foo.items(): myvar[k] = v

### END CODE

Obviously I can put the dict into an instance variable, but then
methods like 'keys()' and such won't work. If that makes any sense...

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


Re: [Tutor] Compute data usage from log

2009-10-27 Thread bibi midi
Hey Christian,

There seems to be a missing parenthesis in your join function below. Correct
me if I'm wrong.

I can live with ppp's time format for now. My script is not world-changing
anyway :-). How do i know I'm on the last line of the log file per the code
below? Just asking as I'm away from my linux box atm.

for line in open(log_file):
last_log_date = ' '.join(line.split(' ')[:3])

Thanks.


On Tue, Oct 27, 2009 at 2:56 PM, Christian Witts wrote:

> bibi midi wrote:
>
>> #!/usr/bin/env python
>> # -*- coding: utf-8 -*-
>>
>> '''
>> Calculate internet data consumption
>> of service provider
>> Code as per help of python tutor mailing list
>> Created: 26-Oct-2009
>>
>> '''
>>
>> intro = raw_input('press enter to view your internet data consumption: ')
>> log_file = '/home/bboymen/mobily.data.plan'
>> total_consumed = 0
>> for line in open(log_file):
>>total_consumed += int(line.split(' ')[9])
>>
>>
>> total_consumed = total_consumed/100.0
>> print "total data consumed is: %0.3f MB\n" % total_consumed
>>
>>
>> #TODO: #1) show the list comprehension alternative method
>> #2) add exception handling e.g. when log_file cant be found or when key
>> interrupt is pressed
>>
>> #  or when index[9] is not a number, etc
>> #3) print latest date of calculated data
>>
>> I'm working on TODO no. 3 e.g. I want to show the latest date when wvdial
>> generated the ppp data. This is normally the date of last line of the ppd:
>>
>> Oct 14 11:03:45 cc02695 pppd[3092]: Sent 3489538 bytes, received
>> 43317854 bytes.
>> ^
>>
>> For the exception handling i *think* i just use the general exception
>> method e.g. will catch all kinds of error. I really dont know what other
>> errors will show up aside from the ones i listed in the TODO. Advise is
>> appreciated.
>>
>>
>>
>>
>>
>> On Mon, Oct 26, 2009 at 2:12 PM, Luke Paireepinart <
>> rabidpoob...@gmail.com > wrote:
>>
>>
>>
>>On Mon, Oct 26, 2009 at 3:20 AM, Christian Witts
>>mailto:cwi...@compuscan.co.za>> wrote:
>>
>>fInput = open('/path/to/log.file', 'rb')
>>total_usage = 0
>>for line in fInput:
>>  total_usage += int(line.split(' ')[9].strip())
>>print total_usage
>>
>>
>>It's actually bad to assign a variable to the file object in this
>>case (flinput = ) because Python will automatically close a
>>file after you're done with it if you iterate over it directly,
>>but if you include a reference it will stay open until the python
>>program ends or you explicitly call flinput.close().  It doesn't
>>matter much in this example but in general it is good practice to
>>either
>>1) call foo.close() immediately after you're done using a file
>>object, or
>>2) don't alias the file object and just over it directly so Python
>>will auto-close it.
>>
>>Therefore a better (and simpler) way to do the above would be:
>>
>>total_usage = 0
>>for line in open('/path/to/log.file'):
>>total_usage += int(line.split(' ')[9])
>>
>>Also note you don't need to strip the input because int() coersion
>>ignores whitespace anyway. And additionally you shouldn't be
>>opening this in binary mode unless you're sure you want to, and
>>I'm guessing the log file is ascii so there's no need for the
>>'rb'.  (reading is default so we don't specify an 'r'.)
>>
>>
>>And since I like list comprehensions a lot, I'd probably do it
>>like this instead:
>>
>>total_usage = sum([int(line.split(' ')[9]) for line in
>>open('/path/to/log.file')])
>>
>>Which incidentally is even shorter, but may be less readable if
>>you don't use list comprehensions often.
>>
>>Also, the list comprehension version is likely to be more
>>efficient, both because of the use of sum rather than repeated
>>addition (sum is implemented in C) and because list comprehensions
>>in general are a tad faster than explicit iteration, if i recall
>>correctly (don't hold me to that though, I may be wrong.)
>>
>>
>>Of course this has no error checking and or niceties, but I
>>will leave that up to you.
>>
>>The same applies to my modifications.
>>
>>Good luck, and let us know if you need anything else!
>>
>>-Luke
>>
>>
>>
>>
>> --
>> Best Regards,
>> bibimidi
>>
>>
>>
> Exceptions:
> * Not finding the log file would be IOError.
> * Casting an alphanumeric or alpha string to integer would be a ValueError,
> in this context you won't have a None so you shouldn't need to worry about a
> TypeError
> * Selecting the 10th element in your list can raise an IndexError if your
> line did not contain enough delimiters to create a large enough list.
>
> Pedantic:
> 1MB = 1,024KB = 1,024*1,024B
> So your total consumed should be div (1024*1024.0) or div 1048576.0
>
> For the date you can look at the time module to get a nice string
> representation of the date/time.  Or as you said you want the last d

Re: [Tutor] Compute data usage from log

2009-10-27 Thread Christian Witts

bibi midi wrote:

Hey Christian,

There seems to be a missing parenthesis in your join function below. 
Correct me if I'm wrong.


I can live with ppp's time format for now. My script is not 
world-changing anyway :-). How do i know I'm on the last line of the 
log file per the code below? Just asking as I'm away from my linux box 
atm.


for line in open(log_file):
last_log_date = ' '.join(line.split(' ')[:3])

Thanks.


On Tue, Oct 27, 2009 at 2:56 PM, Christian Witts 
mailto:cwi...@compuscan.co.za>> wrote:


bibi midi wrote:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
Calculate internet data consumption
of service provider
Code as per help of python tutor mailing list
Created: 26-Oct-2009

'''

intro = raw_input('press enter to view your internet data
consumption: ')
log_file = '/home/bboymen/mobily.data.plan'
total_consumed = 0
for line in open(log_file):
   total_consumed += int(line.split(' ')[9])


total_consumed = total_consumed/100.0
print "total data consumed is: %0.3f MB\n" % total_consumed


#TODO: #1) show the list comprehension alternative method
#2) add exception handling e.g. when log_file cant be found or
when key interrupt is pressed

#  or when index[9] is not a number, etc
#3) print latest date of calculated data
 
I'm working on TODO no. 3 e.g. I want to show the latest date

when wvdial generated the ppp data. This is normally the date
of last line of the ppd:

Oct 14 11:03:45 cc02695 pppd[3092]: Sent 3489538 bytes,
received 43317854 bytes.
^

For the exception handling i *think* i just use the general
exception method e.g. will catch all kinds of error. I really
dont know what other errors will show up aside from the ones i
listed in the TODO. Advise is appreciated.





On Mon, Oct 26, 2009 at 2:12 PM, Luke Paireepinart
mailto:rabidpoob...@gmail.com>
>> wrote:



   On Mon, Oct 26, 2009 at 3:20 AM, Christian Witts
   mailto:cwi...@compuscan.co.za>
>> wrote:

   fInput = open('/path/to/log.file', 'rb')
   total_usage = 0
   for line in fInput:
 total_usage += int(line.split(' ')[9].strip())
   print total_usage


   It's actually bad to assign a variable to the file object
in this
   case (flinput = ) because Python will automatically close a
   file after you're done with it if you iterate over it directly,
   but if you include a reference it will stay open until the
python
   program ends or you explicitly call flinput.close().  It
doesn't
   matter much in this example but in general it is good
practice to
   either
   1) call foo.close() immediately after you're done using a file
   object, or
   2) don't alias the file object and just over it directly so
Python
   will auto-close it.

   Therefore a better (and simpler) way to do the above would be:

   total_usage = 0
   for line in open('/path/to/log.file'):
   total_usage += int(line.split(' ')[9])

   Also note you don't need to strip the input because int()
coersion
   ignores whitespace anyway. And additionally you shouldn't be
   opening this in binary mode unless you're sure you want to, and
   I'm guessing the log file is ascii so there's no need for the
   'rb'.  (reading is default so we don't specify an 'r'.)


   And since I like list comprehensions a lot, I'd probably do it
   like this instead:

   total_usage = sum([int(line.split(' ')[9]) for line in
   open('/path/to/log.file')])

   Which incidentally is even shorter, but may be less readable if
   you don't use list comprehensions often.

   Also, the list comprehension version is likely to be more
   efficient, both because of the use of sum rather than repeated
   addition (sum is implemented in C) and because list
comprehensions
   in general are a tad faster than explicit iteration, if i
recall
   correctly (don't hold me to that though, I may be wrong.)


   Of course this has no error checking and or niceties, but I
   will leave that up to you.

   The same applies to my modifications.

   Good luck, and let us know if you need anything else!

   -Luke




-- 
Best Regards,

bibimidi



Exceptions:
* Not finding the log file

Re: [Tutor] How to load a dict into a dict subclass?

2009-10-27 Thread Christian Witts

Modulok wrote:

List,

I'm new to the list, (somewhat new to python too). My code feels
hacky. I'd like to know if there is a more eloquent way (more below).
If not, a general thumbs up from more experienced programmers would be
great!

Assume I have a dict, 'foo'. I also have my own class, 'Bar', which
subclasses (i.e. is a derived class) of a dict. How do I eloquently
get foo into an instace of Bar? Example:


### BEGIN CODE:
class Bar(dict):
   pass # Act like a dict for now.

foo = {'a': 100, 'b': 200, 'c': 300} # This could be a function return value.
myvar = Bar()
# The hacky feeling part:
for k,v in foo.items(): myvar[k] = v

### END CODE

Obviously I can put the dict into an instance variable, but then
methods like 'keys()' and such won't work. If that makes any sense...

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

  


You can use the built-in function for dictionaries called update.  So

>>> class Bar(dict):
>>> pass

>>> foo = {'a':100, 'b':200, 'c': 300}
>>> myvar = Bar()
>>> myvar.update(foo)
>>> myvar
{'a': 100, 'c': 300, 'b': 200}

--
Kind Regards,
Christian Witts


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


Re: [Tutor] Compute data usage from log

2009-10-27 Thread bibi midi
Yep it works! I understand now it iterates on each line and replaces the old
elements with the new ones. In the end you get the latest date of the last
line of log.

I will work on the exception handling and other refinements. Thanks.



On Tue, Oct 27, 2009 at 8:41 AM, Christian Witts wrote:

>
>
>>for line in open(log_file):
>>  last_log_date = ' '.join(line.split(' ')[:3]
>>
>>which would take the first 3 elements in your list and combine
>>them again.  Of course this is again just a simple representation
>>of what to do.
>>
>>--Kind Regards,
>>Christian Witts
>>
>>
>>
>>
>>
>> --
>> Best Regards,
>> bibimidi
>>
>> Sent from Riyadh, 01, Saudi Arabia
>>
>
>
> Hi Bibi,
>
> Yeah there was a missing parenthesis, I was just typing away.
> As for knowing if you're on the last line of your log file, basically what
> will happen is for every line you iterate through it will parse the first 3
> elements of your line and use that for the last_log_date.
> If you know for certain that every line will start with the time stamp then
> it will work fine, if that is not the case then you will need to build in
> some checking to ensure you get the correct information.
>
> --
> Kind Regards,
> Christian Witts
>
>
>


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


Re: [Tutor] How to load a dict into a dict subclass?

2009-10-27 Thread John
I use a 'SuperDict' all the time in my code. Not sure it's a good idea, but
I find it convenient. Also, I wouldn't mind comments on why/why not to use
something like this:

class SuperDict(dict):
def __getattr__(self, attr):
return self[attr]
def __setattr__(self, attr, value):
self[attr] = value

def set_with_dict(self,D):
""" set attributes with a dict """
for k in D.keys():
self.__setattr__(k,D[k])

Here's the original thread (NOTE: I have also been trying to use more
structured arrays as recommended by one poster):
http://www.nabble.com/creating-a-dict-like-class---asigning-variables...-this-one-may-take-some-thought--%29-td23759398.html

On Tue, Oct 27, 2009 at 1:45 PM, Christian Witts wrote:

> Modulok wrote:
>
>> List,
>>
>> I'm new to the list, (somewhat new to python too). My code feels
>> hacky. I'd like to know if there is a more eloquent way (more below).
>> If not, a general thumbs up from more experienced programmers would be
>> great!
>>
>> Assume I have a dict, 'foo'. I also have my own class, 'Bar', which
>> subclasses (i.e. is a derived class) of a dict. How do I eloquently
>> get foo into an instace of Bar? Example:
>>
>>
>> ### BEGIN CODE:
>> class Bar(dict):
>>   pass # Act like a dict for now.
>>
>> foo = {'a': 100, 'b': 200, 'c': 300} # This could be a function return
>> value.
>> myvar = Bar()
>> # The hacky feeling part:
>> for k,v in foo.items(): myvar[k] = v
>>
>> ### END CODE
>>
>> Obviously I can put the dict into an instance variable, but then
>> methods like 'keys()' and such won't work. If that makes any sense...
>>
>> Thanks guys!
>> -Modulok-
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>
>
> You can use the built-in function for dictionaries called update.  So
>
> >>> class Bar(dict):
> >>> pass
>
>
> >>> foo = {'a':100, 'b':200, 'c': 300}
> >>> myvar = Bar()
> >>> myvar.update(foo)
> >>> myvar
> {'a': 100, 'c': 300, 'b': 200}
>
> --
> Kind Regards,
> Christian Witts
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Configuration
``
Plone 2.5.3-final,
CMF-1.6.4,
Zope (Zope 2.9.7-final, python 2.4.4, linux2),
Five 1.4.1,
Python 2.4.4 (#1, Jul 3 2007, 22:58:17) [GCC 4.1.1 20070105 (Red Hat
4.1.1-51)],
PIL 1.1.6
Mailman 2.1.9
Postfix 2.4.5
Procmail v3.22 2001/09/10
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to load a dict into a dict subclass?

2009-10-27 Thread John
On Tuesday 27 October 2009 06:25:13 am John wrote:
> I use a 'SuperDict' all the time in my code. Not sure it's a good idea, but
> I find it convenient. Also, I wouldn't mind comments on why/why not to use
> something like this:
>
> class SuperDict(dict):
> def __getattr__(self, attr):
> return self[attr]
> def __setattr__(self, attr, value):
> self[attr] = value
>
> def set_with_dict(self,D):
> """ set attributes with a dict """
> for k in D.keys():
> self.__setattr__(k,D[k])
>
> Here's the original thread (NOTE: I have also been trying to use more
> structured arrays as recommended by one poster):
> http://www.nabble.com/creating-a-dict-like-class---asigning-variables...-th
>is-one-may-take-some-thought--%29-td23759398.html
>
> On Tue, Oct 27, 2009 at 1:45 PM, Christian Witts 
wrote:
> > Modulok wrote:
> >> List,
> >>
> >> I'm new to the list, (somewhat new to python too). My code feels
> >> hacky. I'd like to know if there is a more eloquent way (more below).
> >> If not, a general thumbs up from more experienced programmers would be
> >> great!
> >>
> >> Assume I have a dict, 'foo'. I also have my own class, 'Bar', which
> >> subclasses (i.e. is a derived class) of a dict. How do I eloquently
> >> get foo into an instace of Bar? Example:
> >>
> >>
> >> ### BEGIN CODE:
> >> class Bar(dict):
> >>   pass # Act like a dict for now.
> >>
> >> foo = {'a': 100, 'b': 200, 'c': 300} # This could be a function return
> >> value.
> >> myvar = Bar()
> >> # The hacky feeling part:
> >> for k,v in foo.items(): myvar[k] = v
> >>
> >> ### END CODE
> >>
> >> Obviously I can put the dict into an instance variable, but then
> >> methods like 'keys()' and such won't work. If that makes any sense...
> >>
> >> Thanks guys!
> >> -Modulok-
> >> ___
> >> Tutor maillist  -  Tutor@python.org
> >> To unsubscribe or change subscription options:
> >> http://mail.python.org/mailman/listinfo/tutor
> >
> > You can use the built-in function for dictionaries called update.  So
> >
> > >>> class Bar(dict):
> > >>> pass
> > >>>
> > >>>
> > >>> foo = {'a':100, 'b':200, 'c': 300}
> > >>> myvar = Bar()
> > >>> myvar.update(foo)
> > >>> myvar
> >
> > {'a': 100, 'c': 300, 'b': 200}
> >
> > --
> > Kind Regards,
> > Christian Witts


Hey guru's could one of you explain why such a subclass is needed.  How would 
it be used.  I'm not sure but does not the deepcopy() work as above?


Thanks
Johnf


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


Re: [Tutor] How to load a dict into a dict subclass?

2009-10-27 Thread Wayne
On Tue, Oct 27, 2009 at 10:20 AM, John  wrote:

>
> Hey guru's could one of you explain why such a subclass is needed.  How
> would
> it be used.  I'm not sure but does not the deepcopy() work as above?


A subclass is useful for when you want to do pretty much what another class
does, only with some modifications.

My favorite example (and the easiest to understand) deals with shapes:

class Shape:
 def __init__(self):
self.sides = 0
self.area = 0

class Triangle(Shape):
 Shape.__init__(self)
 def __init__(self, base=0, height=0):
 self.sides = 3
 self.area = base/2*height

class Circle(Shape):
  Shape.__init__(self)
  def __init__(self, radius):
  self.sides = 1
  self.area = 2*3.14*radius


There are many other times when subclasses are useful, but that's a nice
simple example. The "is-a" relationship can tell you when it's useful to
have a superclass. "This collection is a list of (un)ordered elements" would
tell you it should be a list. Though, TBH most python objects are so
"batteries" included that I have little (no) reason to subclass - my only
real exception is GUI programming.

Here's something Google pulled up on the subject:
http://www.gidnetwork.com/b-137.html

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


Re: [Tutor] Function design

2009-10-27 Thread Dave Angel

Benno Lang wrote:

On Tue, Oct 27, 2009 at 8:21 AM, Dave Angel  wrote:
  

I agree with Luke's comments.  But I'd like to point out an apparent bug (I
haven't tried the code, this is just by inspection).

You use the test
if '0' in row[.]

that's not going to check for a zero value, it's going to check for a zero
digit character somewhere in the value.  So 504 would also be recognized, as
well as 540.



I thought this sounded rather fishy, along the following lines:
row is a list, so slicing it returns a list, so 'in' should compare
the list elements (i.e. the strings contained therein) with '0'; this
seems perfectly normal.

I have checked, and thankfully the world is not upside down. It would
only work the way you describe if row was a string, or if 'in' called
itself recursively when it found a list.

HTH,
benno

  
You are quite right, of course.  I somehow missed that it was a slice, 
and took it instead to be a simple subscript.


But if the file contained  0.00 as one of its items, this code would 
still have the other problem I mentioned.


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


Re: [Tutor] Compute data usage from log

2009-10-27 Thread Dave Angel
(For some reason you keep top-posting.  Add your comments to the end, or 
inline if appropriate)


bibi midi wrote:

Yep it works! I understand now it iterates on each line and replaces the old
elements with the new ones. In the end you get the latest date of the last
line of log.

I will work on the exception handling and other refinements. Thanks.



On Tue, Oct 27, 2009 at 8:41 AM, Christian Witts wrote:

  




   for line in open(log_file):
 last_log_date = ' '.join(line.split(' ')[:3]

  


In an earlier example, you already had a for loop on the log_file so the 
last line would still be in the variable "line".  If you put the date 
logic right after the loop, there'd be nothing wrong with using the last 
line that way.   Beats going back through the file and repeating it all 
again.


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


[Tutor] New to Python

2009-10-27 Thread asterix09

Hi there,

How do you connect to a different server using python? (I have not used python 
before)

Your help would be much appreciated.

Kindest Regards,

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


Re: [Tutor] New to Python

2009-10-27 Thread Wayne
On Tue, Oct 27, 2009 at 10:35 AM,  wrote:

>  Hi there,
>
> How do you connect to a different server using python? (I have not used
> python before)
>

What kind of server? What do you ultimately want to do?

see:  http://catb.org/~esr/faqs/smart-questions.html#beprecise

for more info about asking good questions. We can't help you if we don't
know what you want.
-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to Python

2009-10-27 Thread Kent Johnson
On Tue, Oct 27, 2009 at 11:35 AM,   wrote:
> Hi there,
>
> How do you connect to a different server using python? (I have not used
> python before)

What kind of connection? The Python standard library includes modules
which support raw sockets, http, ftp, smtp, xml-rpc and probably a few
others. Paramiko is an add-on that supports ssh2 connection.

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


[Tutor] ANN: Python course, San Francisco, Nov 9-11

2009-10-27 Thread wesley chun
hey gang, not sure i made the original announcement on this list a few
months ago, but if you're on this list because you need to learn
Python as quickly and as in-depth as possible for an immediate need, i
have few more openings in my upcoming course in San Francisco, and
below is the reminder i've just sent out recently to the community
at-large:

*FINAL REMINDER*

come join us for another hardcore Python training course in San
Francisco coming up in a few weeks! we have a few more slots
available. bring your co-workers to take advantage of our multiple
registration discount. we also feature a steeper discount for those
who are primary/secondary teachers, students, as well as to those who
have been more severely impacted by the economy. here is my original
announcement for more info:

http://mail.python.org/pipermail/python-list/2009-September/196228.html

hope to meet you soon!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
   http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to Python

2009-10-27 Thread Alan Gauld
 wrote 

How do you connect to a different server using python? 
(I have not used python before)


Have you programmed before? If so in what languages?
If you are a complete novice any kind of network programming 
is quite a challenge. If you are experienced can you give us 
a bit more context?


--
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] How to load a dict into a dict subclass?

2009-10-27 Thread Alan Gauld


"John"  wrote


> >>> class Bar(dict):
> >>> pass
> >>>
> >>> foo = {'a':100, 'b':200, 'c': 300}
> >>> myvar = Bar()
> >>> myvar.update(foo)
> >>> myvar
>
> {'a': 100, 'c': 300, 'b': 200}


Hey guru's could one of you explain why such a subclass is needed.  How 
would

it be used.  I'm not sure but does not the deepcopy() work as above?


This particular subclass does nothing different to the normal dict so its
never needed. But it's only a demo of how to use the standard dict
methods in a subclass.

In general you might subclass a dict if you wanted to change the
behaviour of some specific method, or maybe add some new methods.
Or maybe you wanted a dictionary that could take a list as a key...
or even take a list of keys and return a list of values.

Lots of reasons for wanting to modify the standard dict behaviour.

--
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] How to load a dict into a dict subclass?

2009-10-27 Thread Alan Gauld


"Wayne"  wrote 


My favorite example (and the easiest to understand) deals with shapes:

class Shape:
def __init__(self):
   self.sides = 0
   self.area = 0

class Triangle(Shape):
Shape.__init__(self)
def __init__(self, base=0, height=0):
self.sides = 3
self.area = base/2*height


Shouldn't the Shape.__init__() call be inside the constructor?
Or is there some deep subtle thing going on here that I'm missing?

Also how does subclassing Shape add any value here since 
we just create local instance vars for sides and area anyway

if they don't already exist?

Or is this a case of simplifying an example one step too far?

Confusedly,

--
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] Function design

2009-10-27 Thread Eduardo Vieira
On Tue, Oct 27, 2009 at 10:14 AM, Dave Angel  wrote:
> Benno Lang wrote:
>>
>> On Tue, Oct 27, 2009 at 8:21 AM, Dave Angel  wrote:
>>
>>>
>>> I agree with Luke's comments.  But I'd like to point out an apparent bug
>>> (I
>>> haven't tried the code, this is just by inspection).
>>>
>>> You use the test
>>>    if '0' in row[.]
>>>
>>> that's not going to check for a zero value, it's going to check for a
>>> zero
>>> digit character somewhere in the value.  So 504 would also be recognized,
>>> as
>>> well as 540.
>>>
>>
>> I thought this sounded rather fishy, along the following lines:
>> row is a list, so slicing it returns a list, so 'in' should compare
>> the list elements (i.e. the strings contained therein) with '0'; this
>> seems perfectly normal.
>>
>> I have checked, and thankfully the world is not upside down. It would
>> only work the way you describe if row was a string, or if 'in' called
>> itself recursively when it found a list.
>>
>> HTH,
>> benno
>>
>>
>
> You are quite right, of course.  I somehow missed that it was a slice, and
> took it instead to be a simple subscript.
>
> But if the file contained  0.00 as one of its items, this code would still
> have the other problem I mentioned.
>
> DaveA
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
Thanks for your pointers, Dave. Actually the csv file have data like this:
CAOCA-SD3,OCA - Sign Design Elements Vol. 3,0,0,0,0,0,0,0,0,0,0,0,0
At first I thought that the csv module would do type coercion and my
original code was:
if 0 in row
but nothing was caught.
so I change it to:
if '0' in row
and all was well.

Especially to Luke and Alan:
Yes. A function returning the number of rows with zeros seems like a
sensible decision.
I'm enjoying the input from this community. I first started diving
into programming using AutoHotkey, for a lot of automation stuff on
windows. Autohotkey is very much procedure oriented, and you can even
record macros. The scripting language allows functions and several
other advanced features.
Sometimes I have a need and think. Let me quick do this using either
Autohotkey or Python. Sometimes both. I am glad that especially being
exposed to Python I am learning how to design my code for reuse,
making things more flexible, etc.
Thanks again.


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


Re: [Tutor] Compute data usage from log

2009-10-27 Thread Eduardo Vieira
On Tue, Oct 27, 2009 at 5:33 AM, bibi midi  wrote:
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> '''
> Calculate internet data consumption
> of service provider
> Code as per help of python tutor mailing list
> Created: 26-Oct-2009
>
> '''
>
> intro = raw_input('press enter to view your internet data consumption: ')
> log_file = '/home/bboymen/mobily.data.plan'
> total_consumed = 0
> for line in open(log_file):
> total_consumed += int(line.split(' ')[9])
>
>
> total_consumed = total_consumed/100.0
> print "total data consumed is: %0.3f MB\n" % total_consumed
>
>
> #TODO:
> #1) show the list comprehension alternative method
> #2) add exception handling e.g. when log_file cant be found or when key
> interrupt is pressed
>
> #  or when index[9] is not a number, etc
> #3) print latest date of calculated data
>
> I'm working on TODO no. 3 e.g. I want to show the latest date when wvdial
> generated the ppp data. This is normally the date of last line of the ppd:
>
> Oct 14 11:03:45 cc02695 pppd[3092]: Sent 3489538 bytes, received
> 43317854 bytes.
> ^
>
> For the exception handling i *think* i just use the general exception method
> e.g. will catch all kinds of error. I really dont know what other errors
> will show up aside from the ones i listed in the TODO. Advise is
> appreciated.
>
>
>
>
>
> On Mon, Oct 26, 2009 at 2:12 PM, Luke Paireepinart 
> wrote:
>>
>>
>> On Mon, Oct 26, 2009 at 3:20 AM, Christian Witts 
>> wrote:
>>>
>>> fInput = open('/path/to/log.file', 'rb')
>>> total_usage = 0
>>> for line in fInput:
>>>   total_usage += int(line.split(' ')[9].strip())
>>> print total_usage
>>
>> It's actually bad to assign a variable to the file object in this case
>> (flinput = ) because Python will automatically close a file after you're
>> done with it if you iterate over it directly, but if you include a reference
>> it will stay open until the python program ends or you explicitly call
>> flinput.close().  It doesn't matter much in this example but in general it
>> is good practice to either
>> 1) call foo.close() immediately after you're done using a file object, or
>> 2) don't alias the file object and just over it directly so Python will
>> auto-close it.
>>
>> Therefore a better (and simpler) way to do the above would be:
>>
>> total_usage = 0
>> for line in open('/path/to/log.file'):
>>     total_usage += int(line.split(' ')[9])
>>
>> Also note you don't need to strip the input because int() coersion ignores
>> whitespace anyway. And additionally you shouldn't be opening this in binary
>> mode unless you're sure you want to, and I'm guessing the log file is ascii
>> so there's no need for the 'rb'.  (reading is default so we don't specify an
>> 'r'.)
>>
>>
>> And since I like list comprehensions a lot, I'd probably do it like this
>> instead:
>>
>> total_usage = sum([int(line.split(' ')[9]) for line in
>> open('/path/to/log.file')])
>>
>> Which incidentally is even shorter, but may be less readable if you don't
>> use list comprehensions often.
>>
>> Also, the list comprehension version is likely to be more efficient, both
>> because of the use of sum rather than repeated addition (sum is implemented
>> in C) and because list comprehensions in general are a tad faster than
>> explicit iteration, if i recall correctly (don't hold me to that though, I
>> may be wrong.)
>>>
>>> Of course this has no error checking and or niceties, but I will leave
>>> that up to you.
>>
>> The same applies to my modifications.
>>
>> Good luck, and let us know if you need anything else!
>>
>> -Luke
>
>
>
> --
> Best Regards,
> bibimidi
>
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

I think you could benefit a lot from the code examples given by Dave
Beazley in his presentation about generators. There are scripts that
deal with just about exactly what you're looking for. Very informative
material: http://www.dabeaz.com/generators/
See the presentation slides

HTH

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


Re: [Tutor] How to load a dict into a dict subclass?

2009-10-27 Thread Albert-Jan Roskam
I thought reimplementing dict was a matter of defining a __dict__ attribute in 
the Bar class? And isn't the normal dict inherited anyway? (through __super__)

Or, if one would want to disable inheritance of the normal dict, one could use 
__slots__. Right?

Or did I misinterpret the New Testament of my Python Bible?

Cheers!!
Albert-Jan

~~
Before you criticize someone, walk a mile in their shoes, that way 
when you do criticize them, you're a mile away and you have their shoes! 
~~


--- On Tue, 10/27/09, Alan Gauld  wrote:

> From: Alan Gauld 
> Subject: Re: [Tutor] How to load a dict into a dict subclass?
> To: tutor@python.org
> Date: Tuesday, October 27, 2009, 6:45 PM
> 
> "John" 
> wrote
> 
> >> > >>> class Bar(dict):
> >> > >>>     pass
> >> > >>>
> >> > >>> foo = {'a':100, 'b':200, 'c':
> 300}
> >> > >>> myvar = Bar()
> >> > >>> myvar.update(foo)
> >> > >>> myvar
> >> >
> >> > {'a': 100, 'c': 300, 'b': 200}
> > 
> > Hey guru's could one of you explain why such a
> subclass is needed.  How would
> > it be used.  I'm not sure but does not the
> deepcopy() work as above?
> 
> This particular subclass does nothing different to the
> normal dict so its
> never needed. But it's only a demo of how to use the
> standard dict
> methods in a subclass.
> 
> In general you might subclass a dict if you wanted to
> change the
> behaviour of some specific method, or maybe add some new
> methods.
> Or maybe you wanted a dictionary that could take a list as
> a key...
> or even take a list of keys and return a list of values.
> 
> Lots of reasons for wanting to modify the standard dict
> behaviour.
> 
> -- 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
> 


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


[Tutor] Error

2009-10-27 Thread Vincent Jones
I created database using the 'python manage.py sycdb'

then proceeded to 'python manage.py sql bookmarks'

and i receive this error:
Error: App with label bookmarks could not be found. Are you sure your
INSTALLED_APPS settings is correct?

I go to Settings py and the INSTALLED_APPS is 'django_bookmarks.bookmarks',

I also looked in the directory 'django_bookmarks' and there is a directory
bookmarks within it so what am i doing wrong?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to load a dict into a dict subclass?

2009-10-27 Thread Wayne
On Tue, Oct 27, 2009 at 12:49 PM, Alan Gauld wrote:

>
> "Wayne"  wrote
>
>> My favorite example (and the easiest to understand) deals with shapes:
>>
>> class Shape:
>>def __init__(self):
>>   self.sides = 0
>>   self.area = 0
>>
>> class Triangle(Shape):
>>Shape.__init__(self)
>>def __init__(self, base=0, height=0):
>>self.sides = 3
>>self.area = base/2*height
>>
>
> Shouldn't the Shape.__init__() call be inside the constructor?
> Or is there some deep subtle thing going on here that I'm missing?
>
> Also how does subclassing Shape add any value here since we just create
> local instance vars for sides and area anyway
> if they don't already exist?
>
> Or is this a case of simplifying an example one step too far?
>
> Confusedly,
>
>
Probably, to all of the above it's applicable to - I've (1) been coding in
C++ all morning, (2) was kinda in a hurry, and (3) haven't seen the *actual*
example I saw in my CS class for at least a year - it was just the concept
of using subclasses that stayed with me.

There's probably a wealth of better information out there for the curious
individual, and I probably should have just grabbed a link.

I'm presuming if you were really doing something like that, the Shape class
would take more arguments for instantiation, as well as do some other more
useful things.

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


Re: [Tutor] Function design

2009-10-27 Thread Eduardo Vieira
On Tue, Oct 27, 2009 at 10:14 AM, Dave Angel  wrote:

>
> But if the file contained  0.00 as one of its items, this code would still
> have the other problem I mentioned.
>
> DaveA
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Yes. I noticed that in another file: I had to change the line to:
if '0' in row[:lastcolumn] or '0.0' in row[:lastcolumn]:

I tried to express that by doing this:
if '0' or '0.0' in row[:lastcolumn]:
and I got very wrong results... Ouch! Don't think python is that close
to English...
Eduardo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to load a dict into a dict subclass?

2009-10-27 Thread Kent Johnson
On Tue, Oct 27, 2009 at 3:02 PM, Albert-Jan Roskam  wrote:
> I thought reimplementing dict was a matter of defining a __dict__ attribute 
> in the Bar class? And isn't the normal dict inherited anyway? (through 
> __super__)
>
> Or, if one would want to disable inheritance of the normal dict, one could 
> use __slots__. Right?
>
> Or did I misinterpret the New Testament of my Python Bible?

You are confusing the __dict__ attribute of most objects with the dict
(dictionary) type. The OP is interested in subclassing the dict type.

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


Re: [Tutor] Error

2009-10-27 Thread Emile van Sebille

On 10/27/2009 12:15 PM Vincent Jones said...

I created database using the 'python manage.py sycdb'


You're likely to get answers quickly on the django mailing list.

Emile


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


Re: [Tutor] Compute data usage from log

2009-10-27 Thread Eri Mendz
On Tue, Oct 27, 2009 at 7:24 PM, Dave Angel  wrote:
> (For some reason you keep top-posting.  Add your comments to the end, or
> inline if appropriate)
>

Hi Dave,

Noted the top posting thing thanks for reminding :-)

> 
> In an earlier example, you already had a for loop on the log_file so the
> last line would still be in the variable "line".  If you put the date logic
> right after the loop, there'd be nothing wrong with using the last line that
> way.   Beats going back through the file and repeating it all again.
>
> DaveA

Yes i agree. I put the date variable after last line of the for loop.
And it works as expected.


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