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

2011-01-10 Thread Alan Gauld
bob gailer bgai...@gmail.com wrote 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 init() at all. Well I'd like to expand that a bit. There are cases where I create a class

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

2011-01-10 Thread Karim
Thank you Steven, Modulok and Alan for your precious and detailed explanations! I understood that I must not overuse try-except statement and usually when the exception could happen exceptionally. By the way I have this piece of code using elementTree standard module and according to Alan

Re: [Tutor] Checkbox problem in Tkinter

2011-01-10 Thread Alan Gauld
ANKUR AGGARWAL coolankur2...@gmail.com wrote from Tkinter import * root=Tk() var=StringVar() c=Checkbutton(root,text=hello,variable=var,onvalue=,offvalue=) c.pack() root.mainloop() FWIW I get a different problem, namely that the var does not seem to get updated nor does changling the

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

2011-01-10 Thread ALAN GAULD
By the way I have this piece of code using elementTree standard module and according to Alan this is bad code I guess: Which just proves there are no absolute rules in programming :-) try: devdb.setDescription(dev.attrib['description']) except KeyError: pass try:

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

2011-01-10 Thread Karim
Thanks Alan this reassures me! Regards Karim On 01/10/2011 10:39 AM, ALAN GAULD wrote: By the way I have this piece of code using elementTree standard module and according to Alan this is bad code I guess: Which just proves there are no absolute rules in programming :-)

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

2011-01-10 Thread Steven D'Aprano
Karim wrote: Thank you Steven, Modulok and Alan for your precious and detailed explanations! I understood that I must not overuse try-except statement and usually when the exception could happen exceptionally. By the way I have this piece of code using elementTree standard module and

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

2011-01-10 Thread Karim
Steven many thanks for this useful hint! I will modify my code. Many thanks! Regards Karim On 01/10/2011 11:32 AM, Steven D'Aprano wrote: Karim wrote: Thank you Steven, Modulok and Alan for your precious and detailed explanations! I understood that I must not overuse try-except statement

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

2011-01-10 Thread Steven D'Aprano
Alan Gauld wrote: However, using exceptions like if/else blocks is bad practice. I'm afraid I disagree strongly with that! You need to use them like a commit in SQL - to protect a whole block of code. Putting try/except around every line of code defeats the purpose, wrap atomic blocks of

Re: [Tutor] Checkbox problem in Tkinter

2011-01-10 Thread Peter Otten
ANKUR AGGARWAL wrote: and i got the output as - [image: Screenshot.png] The image doesn't survive. When i take the var as of string variable type i am unable to edit the checkbox. It comes slected predefined and the widget in kindof Invisible and u can say uneditable. Can anybody tell

Re: [Tutor] Checkbox problem in Tkinter

2011-01-10 Thread Peter Otten
Alan Gauld wrote: ANKUR AGGARWAL coolankur2...@gmail.com wrote from Tkinter import * root=Tk() var=StringVar() c=Checkbutton(root,text=hello,variable=var,onvalue=,offvalue=) c.pack() root.mainloop() FWIW I get a different problem, namely that the var does not seem to get

Re: [Tutor] Checkbox problem in Tkinter

2011-01-10 Thread Peter Otten
ANKUR AGGARWAL wrote: 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

[Tutor] about import statement

2011-01-10 Thread arun kumar
Hi Friends, I'm Arun Kumar from India, Just a month ago i started learning programming .learned some basics of python. I'm really enjoying programming in python. I have some doubts in python. When we write programs,we write some import statements at the beginning of the code. how to know that we

Re: [Tutor] about import statement

2011-01-10 Thread bob gailer
On 1/10/2011 7:58 AM, arun kumar wrote: Hi Friends, I'm Arun Kumar from India, Just a month ago i started learning programming .learned some basics of python. I'm really enjoying programming in python. I have some doubts in python. When we write programs,we write some import statements at the

Re: [Tutor] about import statement

2011-01-10 Thread Max Countryman
On Jan 10, 2011, at 7:58 AM, arun kumar wrote: how to know that we should import something. How do we know that certain classes are in particular module? You know to import a module if you need part of that module. Perhaps you need a class or function defined in the module. There are

[Tutor] Equality of numbers and Strings

2011-01-10 Thread Karim
Hello All, I am not a beginner in Python language but I discovered a hidden property of immutable elements as Numbers and Strings. s ='xyz' t = str('xyz') id(s) == id(t) True Thus if I create 2 different instances of string if the string is identical (numerically). I get the same object

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread Emile van Sebille
On 1/10/2011 8:07 AM Karim said... Hello All, I am not a beginner in Python language but I discovered a hidden property of immutable elements as Numbers and Strings. s ='xyz' t = str('xyz') id(s) == id(t) True Thus if I create 2 different instances of string if the string is identical

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread bob gailer
On 1/10/2011 11:07 AM, Karim wrote: Hello All, I am not a beginner in Python language but I discovered a hidden property of immutable elements as Numbers and Strings. s ='xyz' t = str('xyz') id(s) == id(t) True Thus if I create 2 different instances of string if the string is identical

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread bob gailer
On 1/10/2011 11:51 AM, Emile van Sebille wrote: well, not predictably unless you understand the specifics of the implementation you're running under. from string import letters longstring = letters*100 otherstring = letters*100 id(longstring) 12491608 id (otherstring) 12100288

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread wesley chun
On Mon, Jan 10, 2011 at 8:54 AM, bob gailer bgai...@gmail.com wrote: On 1/10/2011 11:07 AM, Karim wrote: s ='xyz' t = str('xyz') id(s) == id(t) True Thus if I create 2 different instances of string if the string is identical (numerically). Python interns certain literal strings -

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread Emile van Sebille
On 1/10/2011 9:23 AM bob gailer said... On 1/10/2011 11:51 AM, Emile van Sebille wrote: well, not predictably unless you understand the specifics of the implementation you're running under. from string import letters longstring = letters*100 otherstring = letters*100 id(longstring)

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread Stefan Behnel
Emile van Sebille, 10.01.2011 18:42: On 1/10/2011 9:23 AM bob gailer said... On 1/10/2011 11:51 AM, Emile van Sebille wrote: well, not predictably unless you understand the specifics of the implementation you're running under. from string import letters longstring = letters*100

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread Stefan Behnel
Karim, 10.01.2011 17:07: I am not a beginner in Python language but I discovered a hidden property of immutable elements as Numbers and Strings. s ='xyz' t = str('xyz') id(s) == id(t) True Thus if I create 2 different instances of string if the string is identical (numerically). I get the

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

2011-01-10 Thread Alan Gauld
Steven D'Aprano st...@pearwood.info wrote Wrapping an atomic block of code, so long as it actually *can* be treated as atomic (including backing out any changes if it fails), is a good use of try...except. That's exactly what I meant by atomic. A (smallish) group of instructions that must

Re: [Tutor] Checkbox problem in Tkinter

2011-01-10 Thread Alan Gauld
Peter Otten __pete...@web.de wrote I can select/deselect it with the mouse. its just the change to the variable that is broken. This was the problem using the Stringvar. Then var changes OK. Here is my code(from Pythonwin): def f(): global var; var = 'on' if var == 'off' else

Re: [Tutor] about import statement

2011-01-10 Thread Alan Gauld
arun kumar arunkumar...@gmail.com wrote I have some doubts in python. When we write programs,we write some import statements at the beginning of the code. how to know that we should import something. Trial and error, experience and mainly reading the documentation. You try to do something

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread Karim
Many thanks Emile, Bob, Stefan, Wesley! Now, I see now that the point is more related to implementation details and optimization instead of a true property. But it could mistaken people not aware. Regards Karim On 01/10/2011 06:56 PM, Stefan Behnel wrote: Karim, 10.01.2011 17:07: I am not

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

2011-01-10 Thread Corey Richardson
On 01/09/2011 04:27 PM, Steven D'Aprano wrote: 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):

[Tutor] Missing Data in Txt Files

2011-01-10 Thread Benson, Randall
Hello, Does anyone have a program that will read txt file data and insert - or similar for missing data? I have 10minute data and there are hour chunks that are missing that need a missing data insert for that missing hour but not the 10min period. The txt file has a date column (yymmdd), a

Re: [Tutor] Missing Data in Txt Files

2011-01-10 Thread Emile van Sebille
On 1/10/2011 4:10 PM Benson, Randall said... Hello, Does anyone have a program that will read txt file data and insert - or similar for missing data? I have 10minute data and there are hour chunks that are missing that need a missing data insert for that missing hour but not the 10min

Re: [Tutor] Missing Data in Txt Files

2011-01-10 Thread Alan Gauld
Benson, Randall randall.ben...@iberdrolaren.com wrote hour but not the 10min period. The txt file has a date column (yymmdd), a time (hhmm) column and the rest are data columns shown below. See column 1 below with i Not sure what the last sentence merans? Was there supposed to be more? Or

Re: [Tutor] Missing Data in Txt Files

2011-01-10 Thread bob gailer
On 1/10/2011 7:10 PM, Benson, Randall wrote: Hello, Does anyone have a program that will read txt file data and insert - or similar for missing data? I have 10minute data and there are hour chunks that are missing that need a missing data insert for that missing hour but not the 10min