[Tutor] Question about string

2008-07-02 Thread Dong Li
Hi, everyone I am new to python, so what I ask may be so basic. I don't know the difference between s = 'a' 'b' and s = 'a'+'b' They have the same results. Thanks for relying! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/li

Re: [Tutor] Inheritance help

2008-07-02 Thread Kent Johnson
On Wed, Jul 2, 2008 at 9:05 PM, Alan Gauld <[EMAIL PROTECTED]> wrote: > "sean_mcdaniel" <[EMAIL PROTECTED]> wrote > >> I am having problems with classes and subclasses. Do the different >> __init__ >> statements have to have different argument lists? > > You got the solution to your specific questi

Re: [Tutor] random.choice()

2008-07-02 Thread John Fouhy
On 03/07/2008, Alan Gauld <[EMAIL PROTECTED]> wrote: > "John Fouhy" <[EMAIL PROTECTED]> wrote > > you can instead say: > > > > try: > > foo() > > except TypeError: > > # do something else > This makes slightly more sense, although a TypeError seems a bit > too vague, if it had bveen a Callab

Re: [Tutor] random.choice()

2008-07-02 Thread Alan Gauld
"John Fouhy" <[EMAIL PROTECTED]> wrote otherwise. this will be removed for Python 3.x because you can just use hasattr(obj, '__call__'). I was about to go BOO HISS because callable() is much more readable than hasattr() but... you can instead say: try: foo() except TypeError: # do

Re: [Tutor] Inheritance help

2008-07-02 Thread Alan Gauld
"sean_mcdaniel" <[EMAIL PROTECTED]> wrote I am having problems with classes and subclasses. Do the different __init__ statements have to have different argument lists? You got the solution to your specific question but to answer your more pholosophical one: sub classes should ideally have th

Re: [Tutor] Fibonacci series(perhaps slightly off topic)

2008-07-02 Thread John Fouhy
On 03/07/2008, Emil <[EMAIL PROTECTED]> wrote: > I have created a class called Fibs which allow you to access a specific > number in the > Fibonacci series(http://en.wikipedia.org/wiki/Fibonacci_number) But it seems > to me that it > is a bit inefficient, any suggestions on how to make it more e

Re: [Tutor] General design question

2008-07-02 Thread Alan Gauld
"Paul Melvin" <[EMAIL PROTECTED]> wrote For example, if I generate some numbers using range the only way I could easily sum them was to append them to a list and then call the sum function, if I tried without the list I couldn't sum them at all. Lots of good general answers but specifically

[Tutor] Fibonacci series(perhaps slightly off topic)

2008-07-02 Thread Emil
Hello all I have created a class called Fibs which allow you to access a specific number in the Fibonacci series(http://en.wikipedia.org/wiki/Fibonacci_number) But it seems to me that it is a bit inefficient, any suggestions on how to make it more efficient? Here is the code: class Fibs(obje

Re: [Tutor] random.choice()

2008-07-02 Thread John Fouhy
On 03/07/2008, wesley chun <[EMAIL PROTECTED]> wrote: > on a related note, currently in Python, there is a callable() Boolean > function that returns True if the object's callable and False > otherwise. this will be removed for Python 3.x because you can just > use hasattr(obj, '__call__'). I

Re: [Tutor] TypeError: not enough arguments for format string

2008-07-02 Thread broek
- Message from [EMAIL PROTECTED] - Date: Wed, 02 Jul 2008 14:32:27 -0400 From: bob gailer <[EMAIL PROTECTED]> [EMAIL PROTECTED] wrote: [snip] In a case like print '%s%s' %42 , 333 ... TypeError: not enough arguments for format string it would be ambiguous whether 3

Re: [Tutor] Inheritance help

2008-07-02 Thread sean_mcdaniel
Hi y'all, I found the problem. My __init__ statement in the subclass had an extra underscore, which is why the baseclass __init__ was the only one called. Duh! Sean sean_mcdaniel wrote: > > Thank you for the reply. > > I have made the substitution, but I still receive the same error. I > pr

Re: [Tutor] TypeError: not enough arguments for format string

2008-07-02 Thread bob gailer
[EMAIL PROTECTED] wrote: [snip] In a case like print '%s%s' %42 , 333 ... TypeError: not enough arguments for format string it would be ambiguous whether 333 was intended as a second formatting argument or as a second thing to be printed. Here's where the Language Reference comes in ha

Re: [Tutor] random.choice()

2008-07-02 Thread wesley chun
> > It seems to me that Wes is saying only that all function objects are > > callable, not that all callable objects are functions. > > Wesley said that function objects have a "heaping distinction" of > being callable. Only he can say for sure what that means; I took it to > mean that being ca

Re: [Tutor] Inheritance help

2008-07-02 Thread sean_mcdaniel
Thank you for the reply. I have made the substitution, but I still receive the same error. I previously defined the __init__ statements in the old way, i.e. FileParse.__init__(self) but with the same problematic outcome. Thank you, Sean Lie Ryan wrote: > >> Hi Folks, >> >> I can redefine

Re: [Tutor] TypeError: not enough arguments for format string

2008-07-02 Thread broek
- Message from [EMAIL PROTECTED] - Date: Wed, 2 Jul 2008 16:49:19 +1200 From: John Fouhy <[EMAIL PROTECTED]> On 02/07/2008, Christopher Spears <[EMAIL PROTECTED]> wrote: File "point.py", line 13, in __str__ point_str = "(%f,%f)" % self.x, self.y TypeError: not enoug

Re: [Tutor] General design question

2008-07-02 Thread Paul Melvin
mponents now, its just putting them together to make something meaningful :) If anyone has any tips/link/experiences to help me on my way I would appreciate it Cheers paul __ Information from ESET Smart Security, version of virus signature

Re: [Tutor] Inheritance help

2008-07-02 Thread Lie Ryan
> Hi Folks, > > I can redefine the class and I get a "TypeError: __init__() takes > exactly 1 > argument (2 given)" error. I'm creating a SinglePeakFit object and > not a > FileParse one. Still puzzled... In this: class SinglePeakFit(FileParse): ... def __init___(self, filename):

Re: [Tutor] random.choice()

2008-07-02 Thread Kent Johnson
On Wed, Jul 2, 2008 at 11:50 AM, Dick Moores <[EMAIL PROTECTED]> wrote: > It seems to me that Wes is saying only that all function objects are > callable, not that all callable objects are functions. Wesley said that function objects have a "heaping distinction" of being callable. Only he can say

[Tutor] Inheritance help

2008-07-02 Thread sean_mcdaniel
Hi folks, I am having problems with classes and subclasses. Do the different __init__ statements have to have different argument lists? I expected my code to print out "location 1" and "location 2" indicating that both __init__ statements had been successfully called, but it seems like only the s

Re: [Tutor] Inheritance help

2008-07-02 Thread sean_mcdaniel
Hi Folks, I can redefine the class and I get a "TypeError: __init__() takes exactly 1 argument (2 given)" error. I'm creating a SinglePeakFit object and not a FileParse one. Still puzzled... Thanks, Sean New definition: """Contains various classes for parsing input files. Used for various fi

Re: [Tutor] random.choice()

2008-07-02 Thread Dick Moores
At 03:46 AM 7/2/2008, Kent Johnson wrote: On Wed, Jul 2, 2008 at 3:54 AM, wesley chun <[EMAIL PROTECTED]> wrote: > in the former, you have a function object. it's just like any other > Python object, but with one heaping distinction: it's callable -- > this means that u can slap on a pair of p

Re: [Tutor] General design question (Tim Golden)

2008-07-02 Thread Lie Ryan
> If I have a set of numbers, or strings etc. which have been generated > and I then want to do something with them, for example a sum function > call. Is the best way to put those items in a list, or similar > container, before applying the function. The best design tips I could give is not

Re: [Tutor] General design question

2008-07-02 Thread Kent Johnson
On Wed, Jul 2, 2008 at 6:31 AM, Daniele <[EMAIL PROTECTED]> wrote: >>> If I have a set of numbers, or strings etc. which have been generated and I >>> then want to do something with them, for example a sum function call. Is >>> the best way to put those items in a list, or similar container, bef

Re: [Tutor] General design question

2008-07-02 Thread Kent Johnson
On Wed, Jul 2, 2008 at 5:54 AM, Tim Golden <[EMAIL PROTECTED]> wrote: > Paul Melvin wrote: >> >> If I have a set of numbers, or strings etc. which have been generated and >> I then want to do something with them, for example a sum function call. Is >> the best way to put those items in a list, or

Re: [Tutor] random.choice()

2008-07-02 Thread Kent Johnson
On Wed, Jul 2, 2008 at 3:54 AM, wesley chun <[EMAIL PROTECTED]> wrote: > in the former, you have a function object. it's just like any other > Python object, but with one heaping distinction: it's callable -- > this means that u can slap on a pair of parentheses after the object > and execute it

Re: [Tutor] General design question

2008-07-02 Thread Daniele
>> If I have a set of numbers, or strings etc. which have been generated and I >> then want to do something with them, for example a sum function call. Is >> the best way to put those items in a list, or similar container, before >> applying the function. > > Not only "best" but "necessary". th

Re: [Tutor] General design question

2008-07-02 Thread Tim Golden
Paul Melvin wrote: If I have a set of numbers, or strings etc. which have been generated and I then want to do something with them, for example a sum function call. Is the best way to put those items in a list, or similar container, before applying the function. Not only "best" but "necessar

[Tutor] General design question

2008-07-02 Thread Paul Melvin
Hi, I am new to python and although have done basic many, many years ago it has all gone, replaced by rubbish! My question is this: If I have a set of numbers, or strings etc. which have been generated and I then want to do something with them, for example a sum function call. Is the b

Re: [Tutor] random.choice()

2008-07-02 Thread Dick Moores
At 12:54 AM 7/2/2008, wesley chun wrote: ok, someone has to be the bad guy and show an example of equivalent code that's more difficult to read: choice([use_for_float_demo, use_for_integer_demo])() seriously tho, the bottom line of what people have been telling you is that for the function (or

Re: [Tutor] random.choice()

2008-07-02 Thread wesley chun
ok, someone has to be the bad guy and show an example of equivalent code that's more difficult to read: choice([use_for_float_demo, use_for_integer_demo])() seriously tho, the bottom line of what people have been telling you is that for the function (or method) foo(): def foo(): : there is