Re: [Tutor] What is this an example of (and how can i use it?)

2009-09-22 Thread kevin parks
On Sep 21, 2009, at 9:52 AM, Kent Johnson wrote: Calling a generator function gives you something that can be iterated. You can create a list out of it (by passing it to the list() function) or you can iterate the items in it directly with a for loop. Using the example above, you could say fo

Re: [Tutor] Challenge

2009-09-22 Thread Tim Bowden
On Tue, 2009-09-22 at 05:13 -0700, Ali Sina wrote: > Hello tutor > > I downloaded a guide about learning Python by Michael Dawson which has > challenges at the end of each chapter. I'm a novice so I encountered a > problem with this challenge: > > > > "Write a program that flips a coin 100 time

Re: [Tutor] How to get homework help (was need to hire a tutor... )

2009-09-22 Thread Tim Bowden
On Tue, 2009-09-22 at 09:20 +0100, Alan Gauld wrote: > > I'm new on this list <*waves hello to everyone*>, > > welcome to the tutor list <*waves back*> :-) > > > trick to getting help here with homework is pretty much the same as > > most > other tech lists. > > Absolutely so, and well summari

Re: [Tutor] how to define a function with multple parameters

2009-09-22 Thread David
shellc...@juno.com wrote: I want to know how to use multiple parameters for 1 function def display(message): print message def rate_score(): score = rate_score if rate_score <= 999: print "that's nothing." elif rate_score <= 1: print "ok." elif rate_score >=

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Dave Angel
Serdar Tumgoren wrote: def add_name(self): try: self.name = SPECIALIZED_SQLcall_for_child() except SpecialSQLError: #default to the superclass's add_name method super(Child, self).add_name() That certainly is a lot easier to read. So if I were to

Re: [Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 7:56 PM, Sander Sweers wrote: > On Tue, 2009-09-22 at 18:04 -0400, Kent Johnson wrote: >> > def reader(fobject, encoding='UTF-8'): >> >    '''Read a fileobject with specified encoding, defaults UTF-8.''' >> >    r = codecs.getreader(encoding) >> >    data = r(fobject) >> >

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
>   def add_name(self): >       try: >           self.name = SPECIALIZED_SQLcall_for_child() >       except SpecialSQLError: >           #default to the superclass's add_name method >           super(Child, self).add_name() > That certainly is a lot easier to read. So if I were to go that route, wo

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread ALAN GAULD
> In this case, is there any argument against checking for None? Or is > it better to do a type check for a string? > > if name is None: > super() > else: > # do stuff That might be ok if string or None are the only types you could get. Checking for not string will catch any number

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
>>>            self.name =ame > > I assume this is a typo? And it never gets executed because the error is > always raised. yep. that was a typo that should be "name" > I don't mind using exceptions for a simple test but not where the test is > being forced by a piece of code that does nothing. I

Re: [Tutor] how to define a function with multple parameters

2009-09-22 Thread Alan Gauld
wrote I want to know how to use multiple parameters for 1 function Do you by any chance come from a Visual Basic background? def display(message): print message def rate_score(): score = rate_score This does nothing. It assigns the function rate_score to a local variable which is

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Dave Angel
Serdar Tumgoren wrote: An "if" test would be more readable, I agree. But I was trying to apply the "Easier to Ask Permission Forgiveness" style, discussed in the Python Cookbook: , Err..."Easier to Ask Forgiveness than Permission" approach is what I meant (perhaps proving my point about n

Re: [Tutor] how to define a function with multple parameters

2009-09-22 Thread Dave Angel
shellc...@juno.com wrote: I want to know how to use multiple parameters for 1 function def display(message): print message def rate_score(): score =ate_score if rate_score <=99: print "that's nothing." elif rate_score <=: print "ok." elif rate_score >=:

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Alan Gauld
"Dave Angel" wrote def result_of_SPECIALIZED_SQLcall_for_child(): name =None return name I assume this is a placeholder for more complex code to follow? class Child(Parent): def add_name(self): name = result_of_SPECIALIZED_SQLcall_for_child() try: na

Re: [Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Sander Sweers
On Tue, 2009-09-22 at 18:04 -0400, Kent Johnson wrote: > > def reader(fobject, encoding='UTF-8'): > >'''Read a fileobject with specified encoding, defaults UTF-8.''' > >r = codecs.getreader(encoding) > >data = r(fobject) > >return data > > > > I would call it like reader(urllib2.url

Re: [Tutor] ex-ftp

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 12:39 AM, prasad rao wrote: > hello  friends >   I am trying to write a class to save a url.page. > But it is not working.It is saving the html.page.But not getting > images.I am unable to show the list (object.links). > Please take a look at it and show me how to rectify i

Re: [Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 5:04 PM, Sander Sweers wrote: > Hello Tutors, Because a website was giving me issues with unicode > character I created a function to force the encoding. I am not sure it > is the correct way to handle these things. > > def reader(fobject, encoding='UTF-8'): >    '''Read a

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> An "if" test would be more readable, I agree.  But I was trying to > apply the "Easier to Ask Permission Forgiveness" style, discussed in > the Python Cookbook: , > Err..."Easier to Ask Forgiveness than Permission" approach is what I meant (perhaps proving my point about not fully understanding t

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> I know this is a simplified example, but I'd still like to point out that > using exceptions when there's a simple test is not reasonable.   You can > just check for None with a simple if test. An "if" test would be more readable, I agree. But I was trying to apply the "Easier to Ask Permission

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Dave Angel
Serdar Tumgoren wrote: def result_of_SPECIALIZED_SQLcall_for_child(): name =None return name class Child(Parent): def __init__(self): super(Child, self).__init__() def add_name(self): name = result_of_SPECIALIZED_SQLcall_for_child() try:

[Tutor] how to define a function with multple parameters

2009-09-22 Thread shellc...@juno.com
I want to know how to use multiple parameters for 1 function def display(message): print message def rate_score(): score = rate_score if rate_score <= 999: print "that's nothing." elif rate_score <= 1: print "ok." elif rate_score >= 1: print "great."

[Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Sander Sweers
Hello Tutors, Because a website was giving me issues with unicode character I created a function to force the encoding. I am not sure it is the correct way to handle these things. def reader(fobject, encoding='UTF-8'): '''Read a fileobject with specified encoding, defaults UTF-8.''' r = co

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> I know that when you need super(), you have to use it everywhere. So I > would stick with what you have. > > Kent > Okay. Thanks as always to all. Best, Serdar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http:

Re: [Tutor] module not found problem

2009-09-22 Thread Parag Shah
Hi Luke, Kent, Thanks the solution worked. -- Thanks & Regards Parag Shah http://blog.adaptivesoftware.biz On 9/23/09, Luke Paireepinart wrote: > Yeah looks like Kent had the same recommendation.I would suggest you don't > import from draft, because they will probably change the version numbe

Re: [Tutor] module not found problem

2009-09-22 Thread Luke Paireepinart
Yeah looks like Kent had the same recommendation.I would suggest you don't import from draft, because they will probably change the version number of pape at some point. That's why they aliased it as openid.extensions.pape, so they can update it without breaking your code. Seems odd that they woul

Re: [Tutor] module not found problem

2009-09-22 Thread Parag Shah
Hi Luke, If I get into the Python prompt, the following line does succeed (so it seems like __init__.py is being processed): >>> from openid.extensions import pape But this one fails because pape is not found... this is very strange: >>> from openid.extensions.pape import Request as PapeRequest

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 2:20 PM, Serdar Tumgoren wrote: > Is my case isolated enough here that I could use the old syntax, but > leave my remain usages of super in tact? My worry is that I'd have to > convert all of my subclasses (quite a few at this point) to the > old-style... I know that when

Re: [Tutor] module not found problem

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 1:56 PM, Parag Shah wrote: > Hi, > > I am using django-openid-consumer, which has a line in it's views.py > which results in an error due to module not found - > > from openid.extensions.pape import Request as PapeRequest > > where 'openid.extensions' comes from python-open

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> I prefer the older approach too, it is simple and explicit. super() > comes with a raft of complications (google "super considered harmful") > and AFAIK it is only really needed in the case of "diamond" > inheritance. > The explicit method does indeed seem...well...more explicit and easier to und

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 1:27 PM, Alan Gauld wrote: > I tend to prefer the explicit approach since it is explicit which > class/method is getting called, but I suspect the preferred mechanism > nowadays is to use super() I prefer the older approach too, it is simple and explicit. super() comes wi

Re: [Tutor] module not found problem

2009-09-22 Thread Luke Paireepinart
It looks to me like your __init__.py is transparently mapping openid.extensions.pape to openid.extensions.pape5 but when you try to do a direct import from openid.extensions.pape it doesn't process the __init__.py. I've never seen something like this but from your example that's my first guess.Try

[Tutor] module not found problem

2009-09-22 Thread Parag Shah
Hi, I am using django-openid-consumer, which has a line in it's views.py which results in an error due to module not found - from openid.extensions.pape import Request as PapeRequest where 'openid.extensions' comes from python-openid-2.2.4 (installed using 'python setup.py install'), which has a

Re: [Tutor] python win32 drive mapping help

2009-09-22 Thread Alan Gauld
"Dave Angel" wrote Traceback (most recent call last): File "test.py", line 31, in import win32wnet ImportError: No module named win32net But I'd point out an essential problem in your message: your error message isn't self-consistent, What Dave is getting at is that the import use

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Alan Gauld
"Serdar Tumgoren" wrote Is there a way to call a superclass method after I've overridden it in a subclass? Yes, you can do it as you have iin __init__ using super() class Child(Parent): def __init__(self): super(Child, self).__init__() Or you can do it explicitly: Par

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> You're actually already doing it:  look at __init__. > > __init__ is overridden in your subclass, so you call super(Child, > self).__init__() to initialise the class using the parent > (superclass)'s __init__ method. Yes indeed. Thanks for pointing it out. In case it helps anyone else out down t

[Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
Hi everyone, Is there a way to call a superclass method after I've overridden it in a subclass? Specifically, what I'm trying to is something like the following: class Parent(object): def add_name(self): self.name = result_of_GENERIC_SQLcall() class Child(Parent): def __init__(se

Re: [Tutor] python win32 drive mapping help

2009-09-22 Thread Dave Angel
Vineet Kothari wrote: Hi Everyone I saw alot of responses for python on this mailing list. I thought any python guru might wish to help me with little code to map two network drives on windows systems I have 3computers at different locations in a network A,B,C I want to ma

Re: [Tutor] Challenge

2009-09-22 Thread Daniel Sarmiento
Date: Tue, 22 Sep 2009 05:13:32 -0700 (PDT) From: Ali Sina To: tutor@python.org Subject: [Tutor] Challenge Message-ID: <826729.63168...@web45911.mail.sp1.yahoo.com> Content-Type: text/plain; charset="iso-8859-1" Hello tutor I downloaded a guide about learning Python by Michael Dawson which ha

Re: [Tutor] Challenge

2009-09-22 Thread Che M
> I wrote this code but I know its wrong. Although it works properly: > flips=0 > h='heads' > t='tails' > while True: >flips+=1 >if flips>100: >break >if True: >print(flips,'=',h or t) > But it prints every number with the string 'heads'. I'm really blank at this. It

Re: [Tutor] Challenge

2009-09-22 Thread Alan Gauld
Ali Sina wrote: I wrote this code but I know its wrong. Although it works properly: Thereis adfference between "works properly" (ie does what it should) and "runs without errors" :-) You need to read up a bit more on boolean expressions flips=0 h='heads' t='tails' while True: flips+=1

Re: [Tutor] Challenge

2009-09-22 Thread Eric Walker
Ali, I am new at this but here is my interpretation. 1) flip coin 100 times, and print out the number of heads and number of tails. from random import Random score = [0,0]# first position will be heads and second position will be tails count=0#counter to find out how many times we have flipped. a

Re: [Tutor] Challenge

2009-09-22 Thread Lucas Prado Melo
On Tue, Sep 22, 2009 at 9:13 AM, Ali Sina wrote: > But it prints every number with the string 'heads'. I'm really blank at > this. It may have something to do with the 'random' module. > > You could use the choice function on random. Given a list, the choice function returns a random element of

[Tutor] Challenge

2009-09-22 Thread Ali Sina
Hello tutor I downloaded a guide about learning Python by Michael Dawson which has challenges at the end of each chapter. I'm a novice so I encountered a problem with this challenge: "Write a program that flips a coin 100 times and then tells you the number of heads and tails." I wrote this co

Re: [Tutor] python win32 drive mapping help

2009-09-22 Thread vishwajeet singh
On Tue, Sep 22, 2009 at 5:38 AM, Vineet Kothari wrote: > > Hi Everyone > > I saw alot of responses for python on this mailing > list. I thought any python guru might wish to help me with little code to > map two network drives on windows systems > > > I have 3computers at diffe

[Tutor] python win32 drive mapping help

2009-09-22 Thread Vineet Kothari
Hi Everyone I saw alot of responses for python on this mailing list. I thought any python guru might wish to help me with little code to map two network drives on windows systems I have 3computers at different locations in a network A,B,C I want to map c:/temp folder of A to

Re: [Tutor] How to get homework help (was need to hire a tutor... )

2009-09-22 Thread Alan Gauld
I'm new on this list <*waves hello to everyone*>, welcome to the tutor list <*waves back*> :-) trick to getting help here with homework is pretty much the same as most other tech lists. Absolutely so, and well summarised. Alan G. http://www.alan-g.me.uk/