Re: [Tutor] __init__() - is it required?

2011-01-09 Thread bob gailer
On 1/9/2011 4:42 PM, Alan Gauld wrote: "Corey Richardson" wrote Do all classes need an __init__() method? I have classes that look much like this one starts out: No, init() is only for initialising the object instance. If you have no local instance spwecific initialisation you can leave it

[Tutor] Checkbox problem in Tkinter

2011-01-09 Thread ANKUR AGGARWAL
Hey I write this code up from Tkinter import * root=Tk() var=StringVar() c=Checkbutton(root,text="hello",variable=var,onvalue="",offvalue="") c.pack() root.mainloop() and i got the output as - [image: Screenshot.png] When i take the var as of string variable type i am unable to edit the

Re: [Tutor] Try except really better than if?

2011-01-09 Thread Alan Gauld
"Karim" wrote I am using more and more try except statement. But I discussed with a very experienced C++ programmer. And he told me that at least in C++ using too many try -catch statements are making the code slower. That's true, but Bjarne Stroustrup put them in for a reason - and they are

Re: [Tutor] Try except really better than if?

2011-01-09 Thread Modulok
On 1/9/11, Karim wrote: > > Hello all, > > I am using more and more try except statement. But I discussed with a > very experienced C++ programmer. > And he told me that at least in C++ using too many try -catch statements > are making the code slower. And it should > does the same for python (C i

Re: [Tutor] Try except really better than if?

2011-01-09 Thread Steven D'Aprano
Karim wrote: Hello all, I am using more and more try except statement. But I discussed with a very experienced C++ programmer. And he told me that at least in C++ using too many try -catch statements are making the code slower. And it should does the same for python (C implementation). He

Re: [Tutor] Named-value formatting fails

2011-01-09 Thread Tim Johnson
* Steven D'Aprano [110109 13:23]: > Tim Johnson wrote: <...> >>> Are you aware that this is non-portable and subject to change without >>> notice? >> No! 1)Can you explain further? <.> Wow! You've given me a huge amount of technical information. I can't thank you enough for the time and

[Tutor] Try except really better than if?

2011-01-09 Thread Karim
Hello all, I am using more and more try except statement. But I discussed with a very experienced C++ programmer. And he told me that at least in C++ using too many try -catch statements are making the code slower. And it should does the same for python (C implementation). My simple question:

Re: [Tutor] Named-value formatting fails

2011-01-09 Thread Steven D'Aprano
Tim Johnson wrote: * Steven D'Aprano [110108 19:46]: A more detailed response. Dear me... messing with globals and locals. That's always a bad sign. But let's assume this is that one time in 100 that it is actually justified... if localvals is None: self.locals = sys

Re: [Tutor] __init__() - is it required?

2011-01-09 Thread Alan Gauld
"Corey Richardson" wrote Do all classes need an __init__() method? I have classes that look much like this one starts out: No, init() is only for initialising the object instance. If you have no local instance spwecific initialisation you can leave it to the inherited init() aor have no ini

Re: [Tutor] __init__() - is it required?

2011-01-09 Thread Steven D'Aprano
Corey Richardson wrote: Do all classes need an __init__() method? I have classes that look much like this one starts out: class GenerateXML(object): """Defines methods to be inherited for StaticXML and AnimationXML""" def __init__(self): pass I would rather not do that. Code wit

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread Dave Angel
(Don't top-post. You keep putting your responses out of order.) On 01/-10/-28163 02:59 PM, tee chwee liong wrote: i modified the code to be: fname = "sampledata.txt" pattern = "-1" failed = False for line in open(fname): data=line.split() if len(data)==4: port, channel, lane

[Tutor] __init__() - is it required?

2011-01-09 Thread Corey Richardson
Do all classes need an __init__() method? I have classes that look much like this one starts out: class GenerateXML(object): """Defines methods to be inherited for StaticXML and AnimationXML""" def __init__(self): pass I would rather not do that. Code without it runs fine, but wil

Re: [Tutor] Named-value formatting fails

2011-01-09 Thread Tim Johnson
* Steven D'Aprano [110108 19:46]: > A more detailed response. > > Dear me... messing with globals and locals. That's always a bad sign. > But let's assume this is that one time in 100 that it is actually > justified... > >> if localvals is None: self.locals = >> sys._getfr

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread tee chwee liong
hi all, thanks for all your advice, i really learn a lot. finally i modified the code to be working as: fname = "sampledata.txt" pattern = "-1" failure = False for search in open(fname): if pattern in search: #print search #print failure failure=True prin

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread tee chwee liong
i modified the code to be: fname = "sampledata.txt" pattern = "-1" failed = False for line in open(fname): data=line.split() if len(data)==4: port, channel, lane, eyvt = data else: if int(eyvt) == -1: failed = True print "Lane %s failed."

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread ALAN GAULD
> thanks this solve the error but running the code produces another error ie >index out of range. > if line[3] == pattern: > IndexError: list index out of range So you need to check that there are at least 4 elements in the line before trying to access it. Or else catch the exception (see my

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread tee chwee liong
thanks this solve the error but running the code produces another error ie index out of range. Traceback (most recent call last): File "C:\Python25\myscript\log\readfile9.py", line 22, in if line[3] == pattern: IndexError: list index out of range > To: tutor@python.org > From: alan.ga...

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread Alan Gauld
"tee chwee liong" wrote File "C:/Python25/myscript/log/readfile9.py", line 5, in port, channel, lane, eyvt = line.split() ValueError: need more than 2 values to unpack So you need to ensure that you unpack when you have the right number of fields: either: data = line.split() if len(dat

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread tee chwee liong
hi, thanks for the explanation. if i print out line=line.split(), below is the result: ['Platform:', 'PC'] ['Tempt', ':', '25'] ['TAP0', ':0'] ['TAP1', ':1'] [] ['+'] ['Port', 'Chnl', 'Lane', 'EyVt'] ['+']

Re: [Tutor] Command line scripts

2011-01-09 Thread ALAN GAULD
> The following line is what I mean by calling a command line from within the >app > using subprocess. > > self.espeak = subprocess.Popen(['espeak', word],stdout = > subprocess.PIPE).communicate()[0] OK, Now I understand. You want to call an external application from within your code via

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread Alan Gauld
"tee chwee liong" wrote i got syntax error when running this line: data = for line in open(filename) if not line.startswith("#") Should be: data = [ line for line in open(filename) if not line.startswith("#") ] Notice the extra line at the beginning and the fact that it is surrounded by []

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread tee chwee liong
hi, yes you are right, the output below is my desired outcome. the sampledata i have can't be added with #. i got syntax error when running this line: data = for line in open(filename) if not line.startswith("#") pls advise. thanks tcl76 > Date: Sun, 9 Jan 2011 01:41:43 -0500 > From: kb1..

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread Steven D'Aprano
tee chwee liong wrote: hi, there is error when running the code: Traceback (most recent call last): File "C:/Python25/myscript/log/readfile9.py", line 5, in port, channel, lane, eyvt = line.split() ValueError: need more than 2 values to unpack the error is due to below line code: port, cha

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread tee chwee liong
hi, there is error when running the code: > Traceback (most recent call last): > File "C:/Python25/myscript/log/readfile9.py", line 5, in > port, channel, lane, eyvt = line.split() > ValueError: need more than 2 values to unpack the error is due to below line code: >port, channel, lane, eyvt =

Re: [Tutor] Command line scripts

2011-01-09 Thread David Hutto
On Sat, Jan 8, 2011 at 9:10 AM, Alan Gauld wrote: > "David Hutto" wrote > >> If I use as command line script, is there any disruption in the >> execution of the code using wxpython. > > I don't understand the question. > wxPython is a GUI toolkit so how would you have a command > line script usin