Re: [Tutor] classmethod, staticmethod functions (decorator related)

2010-09-12 Thread Huy Ton That
Hm, thanks guys; I just had to verify I was thinking sanely about it. I am going to pick up classmethods next. Do any of you have common design patterns for the usage. They are just items I haven't integrated in my coding, and I want to be certain I'm off on the right foot (: On Sun, Sep 12, 2010

Re: [Tutor] classmethod, staticmethod functions (decorator related)

2010-09-12 Thread Alan Gauld
"Steven D'Aprano" wrote A little more information... static methods are quite common[1] in Java and C++, where people feel the need (or in the case of Java, are forced by the language) to make every function a method. static methods in C++ are normally reserved for use as class methods (alt

Re: [Tutor] classmethod, staticmethod functions (decorator related)

2010-09-12 Thread Steven D'Aprano
On Mon, 13 Sep 2010 09:13:25 am Steven D'Aprano wrote: > On Mon, 13 Sep 2010 06:05:23 am Alan Gauld wrote: > > I think static methjods are largely a mistake of history. ISTR They > > were > > introduced into python before class methods (not by much - one > > release?) > > No, they were introduced a

Re: [Tutor] classmethod, staticmethod functions (decorator related)

2010-09-12 Thread Steven D'Aprano
On Mon, 13 Sep 2010 06:05:23 am Alan Gauld wrote: > I think static methjods are largely a mistake of history. ISTR They > were > introduced into python before class methods (not by much - one > release?) No, they were introduced at the same time. But it turned out that the use cases Guido van Ro

Re: [Tutor] list index out of range

2010-09-12 Thread Steven D'Aprano
On Fri, 10 Sep 2010 07:52:20 am Todd Ballard wrote: > I am attempting to have a cummalative total of the y values and > receive a "list index out of range" error message How unfortunate. Do you have an actual question to ask, or are you just sharing? If you are having problems fixing the error,

Re: [Tutor] py-postgressql v1.0.1 question

2010-09-12 Thread Rance Hall
On Sun, Sep 12, 2010 at 4:54 PM, Luke Paireepinart wrote: >> >> Thanks for the tip.  I'll do some more research but this sounds promising. >> >> Rance >> > Just be aware that some methods of list building will iterate over the list > and evaluate it. So if you only want to retrieve the first 10 r

Re: [Tutor] py-postgressql v1.0.1 question

2010-09-12 Thread Luke Paireepinart
> > Thanks for the tip. I'll do some more research but this sounds promising. > > Rance > Just be aware that some methods of list building will iterate over the list and evaluate it. So if you only want to retrieve the first 10 results but you do something like Results = [I.fetch() for I in c

Re: [Tutor] py-postgressql v1.0.1 question

2010-09-12 Thread Rance Hall
On Sun, Sep 12, 2010 at 3:53 PM, Bill Allen wrote: > Rance, > > I was doing something similar, except I was querying an Oracle database, > using the cx_Oracle module.  I wanted the non-duplicated count of parts in > my database that met certain criteria.  All the output that met the criteria > of

Re: [Tutor] py-postgressql v1.0.1 question

2010-09-12 Thread Bill Allen
> >> Second question is more of a performance question: >> >> I don't suspect a "large" # of items in the to_do list, so I *think* >> that it would be better to just have one SQL statement and then loop >> through the results 10 times to get the first few records rather than >> having a seperate sq

Re: [Tutor] recursive problem

2010-09-12 Thread ALAN GAULD
> > If you do need to avoid accidentally launching missiles then you need > > to do some type checking - although ideally using isinstance() instead > > of type(). But in the majority of cases some sensible documentation > > and Python's culture that we are all adults here usually means you >

Re: [Tutor] py-postgressql v1.0.1 question

2010-09-12 Thread Bill Allen
Rance, I was doing something similar, except I was querying an Oracle database, using the cx_Oracle module. I wanted the non-duplicated count of parts in my database that met certain criteria. All the output that met the criteria of the select statements is loaded into the cursor object. I then

Re: [Tutor] forcing hashlib to has string variables

2010-09-12 Thread Rance Hall
On Sun, Sep 12, 2010 at 2:29 PM, Dave Angel wrote: >  On 2:59 PM, Rance Hall wrote: > Convert the string to bytes.  If the string is ASCII, you can simply use the > bytes() function.  If not, you may need to specify an encoding. Thanks Dave, this is what I needed, I looked in the function refer

Re: [Tutor] tree problem

2010-09-12 Thread Alan Gauld
"Lie Ryan" wrote In this case, the only reason why you hit the recursion limit is if you have a directory which is 1000 deep (quite unlikely, Windows has a directory depth limit much lower than that). Or you accidentally have a recursive directory - one that contains a shortcut to a folder

Re: [Tutor] classmethod, staticmethod functions (decorator related)

2010-09-12 Thread Alan Gauld
"Huy Ton That" wrote class WhatFor(object): def it(cls): print 'work with %s' % cls it = classmethod(it) def uncommon(): print 'I could be a global function' uncommon = staticmethod(uncommon) But I can't seem to understand the above. Under what circumstance would st

Re: [Tutor] design question

2010-09-12 Thread Alan Gauld
"Albert-Jan Roskam" wrote following classes: Menu (responsible for the widget creation), Autocomplete (a subclass of the tkinter text entry widget which I've found on the internet, I wanted to keep this intact), Convert (responsible for the conversion/cropping of the images, which is somewha

Re: [Tutor] recursive problem

2010-09-12 Thread Alan Gauld
"Roelof Wobben" wrote Because I follow this book "Thinking like a computer scientist" and I have only read the chapters about strings. lists and tuples. And that book tries to use Python to teach a general Computing Science degree 101 course. So it teaches you what are classically considered g

Re: [Tutor] recursive problem

2010-09-12 Thread Roelof Wobben
> To: tutor@python.org > From: alan.ga...@btinternet.com > Date: Sun, 12 Sep 2010 20:52:06 +0100 > Subject: Re: [Tutor] recursive problem > > "Roelof Wobben" wrote > I guess the question to ask/consider is: How can be establish whether a pa

Re: [Tutor] recursive problem

2010-09-12 Thread Alan Gauld
"Roelof Wobben" wrote I guess the question to ask/consider is: How can be establish whether a particular object supports a particular interface/set of behaviours In general we "try" it and handle the exceptions that we require? E.g. how do we most pythonically check whether some object "wa

Re: [Tutor] What Design Pattern for Document class (NOT URGENT)

2010-09-12 Thread Alan Gauld
"Karim" wrote My first idea is to create an *docrules* class which holds my document. Why not create a Document class that is your document. This class will use 2 other instances from 2 respectives classes reader and writer. The main method of reader is get(). The main method of writer is

Re: [Tutor] forcing hashlib to has string variables

2010-09-12 Thread Dave Angel
On 2:59 PM, Rance Hall wrote: Luke: On python3.1 I get the following error using your (untested) two line snippet: TypeError: Unicode-objects must be encoded before hashing If I add the b back into the mix, I get a hash with no error messages. But I still can't quite figure out how to get th

Re: [Tutor] (no subject)

2010-09-12 Thread Alan Gauld
"Miss Soraya Nabizadeh" wrote I am new to python Welcome, and I am doing an assignment which asks about writing python functions. The rules of the forum are that we don;t do assignments for you but we will offer suggestions ior answer specific qquestions. That works best if you start by

Re: [Tutor] forcing hashlib to has string variables

2010-09-12 Thread Dave Angel
On 2:59 PM, Rance Hall wrote: Everybody knows you don't store plain text passwords in a database, you store hashes instead consider: userpass = getpass.getpass("User password? ") encuserpass = hashlib.md5() encuserpass.update(userpass) del userpass Now the documentation clearly states th

[Tutor] smtp connection problem --- socket error 10061

2010-09-12 Thread Jack (Geliang) Song
I could not connect with gmail smtp server in Vista 32( worked ok in XP 32). Both vista and xp have same anti-virus software. >>> smtplib.SMTP("smtp.gmail.com",587) Traceback (most recent call last): File "", line 1, in smtplib.SMTP("smtp.gmail.com",587) File "C:\Program Files\Python2

[Tutor] list index out of range

2010-09-12 Thread Todd Ballard
I am attempting to have a cummalative total of the y values and receive a "list index out of range" error message import numpy import matplotlib.pyplot as plt import filereader from filereader import * My_Path="C:\\Python26\\assignment2\\datadownload.txt" My_Data_Type=numpy.dtype([("year","

Re: [Tutor] forcing hashlib to has string variables

2010-09-12 Thread Luke Paireepinart
Ah, it works differently on py3 i guess. Py2 was pretty lax with string handling. I would suggest researching Unicode encode functions rather than looking at the hashlib for info. There is probably a string.encode or something like that. - Sent from a mobile device w

Re: [Tutor] forcing hashlib to has string variables

2010-09-12 Thread Rance Hall
Luke: On python3.1 I get the following error using your (untested) two line snippet: TypeError: Unicode-objects must be encoded before hashing If I add the b back into the mix, I get a hash with no error messages. But I still can't quite figure out how to get the variable contents into the hash

Re: [Tutor] SOLVED: Re: Trapping HTTP Authentication Failure

2010-09-12 Thread Bill Allen
Just in case it is not a known issue or well documented, do take the time if you can to report it. Especially since you have got the symptom isolated and demonstrated that it is limited to a particular OS build. http://docs.python.org/bugs.html -Bill On Sat, Sep 11, 2010 at 1:44 PM, Michael P

Re: [Tutor] forcing hashlib to has string variables

2010-09-12 Thread Luke Paireepinart
This is how I use it (untested) Import hashlib Print hashlib.md5("somestr").hexdigest() Works fine without using binary string. On Sep 12, 2010, at 1:19 PM, Rance Hall wrote: > Everybody knows you don't store plain text passwords in a database, > you store hashes instead > > consider: > > us

[Tutor] forcing hashlib to has string variables

2010-09-12 Thread Rance Hall
Everybody knows you don't store plain text passwords in a database, you store hashes instead consider: userpass = getpass.getpass("User password? ") encuserpass = hashlib.md5() encuserpass.update(userpass) del userpass Now the documentation clearly states that if you are hashing a string you

Re: [Tutor] tree problem

2010-09-12 Thread Roelof Wobben
> Date: Sun, 12 Sep 2010 13:40:09 -0400 > Subject: Re: [Tutor] tree problem > From: joel.goldst...@gmail.com > To: rwob...@hotmail.com > > > > On Sun, Sep 12, 2010 at 1:20 PM, Roelof Wobben >> wrote: > > > > >> Date: Sun, 12 Sep 2

Re: [Tutor] tree problem

2010-09-12 Thread Joel Goldstick
On Sun, Sep 12, 2010 at 10:48 AM, Roelof Wobben wrote: > > > > > > Date: Sun, 12 Sep 2010 09:46:08 -0400 > > From: joel.goldst...@gmail.com > > To: tutor@python.org > > Subject: Re: [Tutor] tree problem > > > > > > > > On Sun, Sep 12, 2010 at 9:32 AM, Roelof Wobbe

[Tutor] py-postgressql v1.0.1 question

2010-09-12 Thread Rance Hall
I'm not sure if this is the right forum for this or not, if there is a better place to ask this question please let me know and I'll re-post elsewhere. I'm using python v3.1 and the py-postgresql v1.0.1 module located at http://python.projects.postgresql.org/docs/1.0/ I'm using prepared sql state

Re: [Tutor] Function object

2010-09-12 Thread Daniel
What can I say except, thanks so much everyone for taking your time and writing me an explication. I finally understood what function objects are. Thanks, really thanks for helping me out. I wish everyone the best. ___ Tutor maillist - Tutor@python.org

Re: [Tutor] tree problem

2010-09-12 Thread Roelof Wobben
> Date: Sun, 12 Sep 2010 09:46:08 -0400 > From: joel.goldst...@gmail.com > To: tutor@python.org > Subject: Re: [Tutor] tree problem > > > > On Sun, Sep 12, 2010 at 9:32 AM, Roelof Wobben >> wrote: > > > >> Date: Sun, 12 Sep 2010 0

Re: [Tutor] tree problem

2010-09-12 Thread Joel Goldstick
On Sun, Sep 12, 2010 at 9:32 AM, Roelof Wobben wrote: > > > > > Date: Sun, 12 Sep 2010 09:08:18 -0400 > > From: joel.goldst...@gmail.com > > To: tutor@python.org > > > Subject: Re: [Tutor] tree problem > > > > > > > > On Sun, Sep 12, 2010 at 7:54 AM, Lie Ryan > >

Re: [Tutor] tree problem

2010-09-12 Thread Joel Goldstick
On Sun, Sep 12, 2010 at 7:54 AM, Lie Ryan wrote: > On 09/12/10 21:15, Roelof Wobben wrote: > > > > > > Hello, > > > > I have this problem. > > > > Write a program named litter.py that creates an empty file named > trash.txt in each subdirectory of a directory tree given the root of the > tree as

Re: [Tutor] tree problem

2010-09-12 Thread Roelof Wobben
> Subject: Re: [Tutor] tree problem > From: evert@gmail.com > Date: Sun, 12 Sep 2010 13:29:12 +0200 > CC: tutor@python.org > To: rwob...@hotmail.com > >> Write a program named litter.py that creates an empty file named trash.txt >> in each subdirecto

Re: [Tutor] tree problem

2010-09-12 Thread Lie Ryan
On 09/12/10 21:15, Roelof Wobben wrote: > > > Hello, > > I have this problem. > > Write a program named litter.py that creates an empty file named trash.txt in > each subdirectory of a directory tree given the root of the tree as an > argument (or the current directory as a default). By de

Re: [Tutor] tree problem

2010-09-12 Thread Evert Rol
> Write a program named litter.py that creates an empty file named trash.txt in > each subdirectory of a directory tree given the root of the tree as an > argument (or the current directory as a default). > > So I change the example to this : > > def traverse(path, s='.\n', f=0, d=0): > path2f

[Tutor] tree problem

2010-09-12 Thread Roelof Wobben
Hello, I have this problem. Write a program named litter.py that creates an empty file named trash.txt in each subdirectory of a directory tree given the root of the tree as an argument (or the current directory as a default). So I change the example to this : def traverse(path, s='.\n',

[Tutor] recursive problem

2010-09-12 Thread Roelof Wobben
> From: rwob...@hotmail.com > To: st...@pearwood.info > Subject: RE: [Tutor] recursive problem > Date: Sun, 12 Sep 2010 07:58:48 + > > > > > >> From: st...@pearwood.info >> To: tutor@python.org >> Date: Sun, 12