Re: [Tutor] pattern searching

2009-11-07 Thread Ajith Gopinath
Thanks folks. || a j i t || On Sat, Nov 7, 2009 at 7:49 AM, bob gailer wrote: > Shashwat Anand wrote: > >> @Bob: the solution seems promising, and it's fast. Thanks for the >> improvement. However I would like to do a minor change to the code to >> prevent it going to infinite loop. >> >> impo

[Tutor] Classes that do operator overloading

2009-11-07 Thread C.T. Matsumoto
Hello All, I'm reading Learning Python's section 'Operator Overloading' and I was wondering why class headers that implement and overload are lowercase? Cheers, T ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] Local vs global

2009-11-07 Thread Alan Gauld
"bibi midi" wrote in Although i have read up quite a lot about local and global scope in functions i still 'suffer' understanding it, ... I tried removing it but i get error variable undeclared or something. It is in the function choose_Cave. We need to see the exact error text, the whole

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread Alan Gauld
"C.T. Matsumoto" wrote I'm reading Learning Python's section 'Operator Overloading' and I was wondering why class headers that implement and overload are lowercase? I'm not sure what you mean by class headers? Can you post an example? -- Alan Gauld Author of the Learn to Program web site

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread C.T. Matsumoto
yes, class Foo: # the book says this is a class header pass As for my question it looks like the convention is if a class only has operator overloading then the class receives a lowercase class name. If the class has a mix, operator overloading and a normal method then the class name gets sta

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread Hugo Arts
On Sat, Nov 7, 2009 at 10:39 AM, C.T. Matsumoto wrote: > yes, > > class Foo: # the book says this is a class header >   pass > > As for my question it looks like the convention is if a class only has > operator overloading then the class receives a lowercase class name. > If the class has a mix, o

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread C.T. Matsumoto
Thanks Hugo, Do methods like __add__, __del__, count as built-in types? I'm aware of the rule you explained and use it and that's why when I saw: class indexer(): def ___getitem__(self, index): return index ** 2 I thought I was missing some special style, or rule. The class above i

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread Hugo Arts
On Sat, Nov 7, 2009 at 12:25 PM, C.T. Matsumoto wrote: > Thanks Hugo, > > Do methods like __add__, __del__, count as built-in types? I'm aware of the > rule you explained and use it and that's why when  I saw: > Built-in types are only those classes 'built in' to the python interpreter. They incl

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread Tim Golden
Hugo Arts wrote: On Sat, Nov 7, 2009 at 12:25 PM, C.T. Matsumoto wrote: class indexer(): def ___getitem__(self, index): return index ** 2 I thought I was missing some special style, or rule. The class above is take from Learning Python, and there are several other examples too. fo

Re: [Tutor] Local vs global

2009-11-07 Thread Dave Angel
Alan Gauld wrote: "bibi midi" wrote in Although i have read up quite a lot about local and global scope in functions i still 'suffer' understanding it, ... I tried removing it but i get error variable undeclared or something. It is in the function choose_Cave. We need to see the exact erro

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread Alan Gauld
"C.T. Matsumoto" wrote class Foo: # the book says this is a class header pass Hmm, that's pretty dubious usage of header in my view. Its the class definition and there is nothing "header" about it. As for my question it looks like the convention is if a class only has operator overload

[Tutor] can anyone help me in solving this problem this is urgent

2009-11-07 Thread surjit khakh
Write a python program to read a text file named “text.txt” and show the number of times each article is found in the file. Articles in the English language are the words “a”, “an”, and “the”. ___ Tutor maillist - Tutor@python.org To unsubscribe or chan

Re: [Tutor] can anyone help me in solving this problem this is urgent

2009-11-07 Thread Shashwat Anand
naive and unoptimized method: >>> file = open("text.txt", 'r') >>> s = file.read() >>> s 'an elephant jump across the room\nhe met a guy\nthe guy was an moron\n' >>> s = " "+s.replace('\n', ' ')+" " >>> s.count(' a ') 1 >>> s.count(' an ') 2 >>> s.count(' the ') 2 On Sat, Nov 7, 2009 at 5:54 AM,

[Tutor] class Knights vs class Knights(object)

2009-11-07 Thread Wayne Werner
Hi, For class definitions I've always used class Knights: but I've just seen an example using: class Knights(object): So I did a quick little test and see this: >>> a = Knights() >>> b = Knights2() >>> a <__main__.Knights instance at 0xb7e12bec> >>> b <__main__.Knights2 object at 0xb7e12b2c>

Re: [Tutor] can anyone help me in solving this problem this is urgent

2009-11-07 Thread Emile van Sebille
On 11/6/2009 4:24 PM surjit khakh said... Write a python program to read a text file named “text.txt” and show the number of times each article is found in the file. Articles in the English language are the words “a”, “an”, and “the”. Sounds like you're taking a python class. Great! It's p

Re: [Tutor] class Knights vs class Knights(object)

2009-11-07 Thread Patrick Sabin
Wayne Werner wrote: and my question is what is the difference between the two? Is there a difference other than one is an object the other is an instance? I googled "python object vs. instance" and didn't find anything terribly useful. Yes there is a difference. One class inherits from objec

Re: [Tutor] can anyone help me in solving this problem this is urgent

2009-11-07 Thread Alan Gauld
"surjit khakh" wrote Write a python program to read a text file named “text.txt” and show the number of times each article is found in the file. In general we don't provide answers to homework questions on this list. But we will try to point you in the right direction. But it helps if you sh

[Tutor] Printing Sideway...

2009-11-07 Thread Ken G.
It is possible to print letters sideway in Python? Instead of printing from left to right on the long side of a #10 envelope, I wish to print sideway, printing from the left short edge of envelope to its right short edge. Thanks, Ken ___ Tutor mailli

Re: [Tutor] Local vs global

2009-11-07 Thread bibi midi
On Sat, Nov 7, 2009 at 3:26 PM, Dave Angel wrote: > Alan Gauld wrote: >> > Alan - Excellent comments, as usual. > > bibimidi - I would point out that after you remove the 'global choose' line > as Alan said, you should rename the global variable you're using to store > the return value. They're a

Re: [Tutor] Printing Sideway...

2009-11-07 Thread bob gailer
Ken G. wrote: It is possible to print letters sideway in Python? Python is a programming language, not a printer driver. So this is not the best place to ask the question. But tell us more - what OS? (Windows or what) what printer? (Make and model) what are you doing in Python to print th

Re: [Tutor] can anyone help me in solving this problem this is urgent

2009-11-07 Thread Prasad Mehendale
On Sunday 08 November 2009 07:43 am, tutor-requ...@python.org wrote: > > In general we don't provide answers to homework questions on this list. > But we will try to point you in the right direction. But it helps if you > show us what you've tried so far and tell us what went wrong. Include any

Re: [Tutor] Printing Sideway...

2009-11-07 Thread bob gailer
Please always reply-all so a copy goes to the list. I am ccing this to the lists for you. Ken G. wrote: I am using Ubuntu 9.04 as my primary OS. I have Windows XP installed in the first partition (dual boot). I have Python 2.6.2 installed on both OS. The printer is a Cannon MX300. To print o

[Tutor] operator overloading considered harmful ;-)

2009-11-07 Thread spir
Hello, I jump on the opportunity offered by the previous thread to tell a little story (serious only people disgard). Guess this is a candidate for Bug of the Year. I was filtering (parse) results to keep only nodes from a given set of types: for child in node: if child.pattern in item_type

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread spir
Le Sat, 7 Nov 2009 14:06:15 -, "Alan Gauld" s'exprima ainsi: > "C.T. Matsumoto" wrote > > > class Foo: # the book says this is a class header > >pass > > Hmm, that's pretty dubious usage of header in my view. > Its the class definition and there is nothing "header" about it. Engli