Re: [Tutor] Callbacks and exception handling

2010-08-12 Thread Pete
> By the way, don't be tempted to write a bare except clause: > > try: > ... > except: > ... > > There are very few reasons for such a thing, as they are too broad and > catch too many things, masking errors, preventing user keyboard > interrupts, etc. Avoid them. Doh! That is what I did :)

Re: [Tutor] Executing Python from TCL

2010-08-12 Thread Karim
Thanks Alan, For clarify that. The speed is not an issue people just need config files generated from xml to feed EDA simulations and validations tools. Karim On 08/12/2010 09:39 AM, Alan Gauld wrote: "Karim" wrote Anyway, you're right I found what I needed at: http://sourceforge.net/pro

Re: [Tutor] Callbacks and exception handling

2010-08-12 Thread Steven D'Aprano
On Fri, 13 Aug 2010 11:56:31 am Pete wrote: > Hi, > > I've been writing some code which uses callbacks. I have not used > callbacks much before, but it does not seem too difficult so far. > > One thing though - I noticed that when an exception is raised in the > callback function, that exception do

[Tutor] Callbacks and exception handling

2010-08-12 Thread Pete
Hi, I've been writing some code which uses callbacks. I have not used callbacks much before, but it does not seem too difficult so far. One thing though - I noticed that when an exception is raised in the callback function, that exception doesn't actually "show up" in the calling program. Two

Re: [Tutor] elif statement

2010-08-12 Thread Sudarshana Banerjee
Hi: Thank you very much for the detailed reply. My problem is I know I am doing the indentation wrong; but I cannot get it right in IDLE. Could you take a look at this please: >>> x=3 >>> if x==0: print "x is 0" >>> elif x&1==1: SyntaxError: invalid syntax See, the moment I am pressing Enter the

Re: [Tutor] elif statement

2010-08-12 Thread Sudarshana Banerjee
Thank you Karim.. the code is not actually part of anything... but is a textbook example, literally (Python Power by Matt Telles). On Wed, Aug 11, 2010 at 9:59 AM, Karim wrote: > > Hello, > > This code works for me: > > > >>> x=3 > >>> if x==0: > ... print "x is 0" > ... elif x&1 ==1: > ...

Re: [Tutor] elif statement

2010-08-12 Thread Sudarshana Banerjee
Thank you Adam. On Tue, Aug 10, 2010 at 7:03 PM, Adam Bark wrote: > On 11/08/10 02:34, Sudarshana Banerjee wrote: > > Hi: I am trying to teach myself Python, and am stuck at the indentation > with the elif statement. > > This is what I am trying to type (as copied from the textbook): > > x=3 >

Re: [Tutor] a graceful program exit

2010-08-12 Thread Bill Allen
On Thu, Aug 12, 2010 at 6:35 AM, Steven D'Aprano wrote: > On Thu, 12 Aug 2010 04:59:26 pm Chris Fuller wrote: > > The preferred and most graceful way is to use neither, as others have > > pointed out. However, you can't return an exit code that way > > Of course you can. Exiting out the end of th

Re: [Tutor] is it possible to call a setter property during class instantiation?

2010-08-12 Thread Serdar Tumgoren
> > def __init__(self, value): > > self.text(value) > > self.text = value # is the way to do this, if you're using it as a > property. > > That worked perfectly! So it seems I was botching the syntax. Many thanks for the quick response!! Serdar

Re: [Tutor] is it possible to call a setter property during class instantiation?

2010-08-12 Thread Evert Rol
> Does anyone know if it's possible to call a property setter inside of a > class's init method? Below is a code sample of what I'm trying to do. Just a quick guess: > class Question(object); replace the semi-colon with a colon (I assume it's just a typo, since you don't get an error for th

[Tutor] is it possible to call a setter property during class instantiation?

2010-08-12 Thread Serdar Tumgoren
Hey all, Does anyone know if it's possible to call a property setter inside of a class's init method? Below is a code sample of what I'm trying to do. class Question(object); def __init__(self, value): self.text(value) @property def text(self): return self._text

Re: [Tutor] string conversion according to the terminal

2010-08-12 Thread Peter Otten
ANKUR AGGARWAL wrote: > Hey- suppose we have a file name-"my file number" > if we want to execute it into the terminal it would be like - my\ file\ > number > > so wondering is there any one in the python that change the enter string > into the terminal string one- > like if user enter the file n

Re: [Tutor] a graceful program exit

2010-08-12 Thread Steven D'Aprano
On Thu, 12 Aug 2010 04:59:26 pm Chris Fuller wrote: > The preferred and most graceful way is to use neither, as others have > pointed out. However, you can't return an exit code that way Of course you can. Exiting out the end of the program returns an exit code of zero, and raising an uncaught e

Re: [Tutor] string conversion according to the terminal

2010-08-12 Thread Evert Rol
> Ok. I appreciate ur response and its gud somewhat... But we dont have only > space=" " . this '\' rules also applies to '(' ')' and all that stuff also... > so i was looking for the builtin function that fully converts it... Is there > any one?? This may depend on your system, but generally,

Re: [Tutor] UTF-8 character

2010-08-12 Thread Dave Angel
Evidenca B d.o.o. wrote: Hi. I have a problem. I am making pa program which, makes a .txt document, the problem is in my language have special character like this: č,š,ž. They don t appear in aschi code, but you can find them in UTF-8 code. So wen I wont to save with writelines a string with

Re: [Tutor] string conversion according to the terminal

2010-08-12 Thread Evert Rol
> a = "my file number" > a.replace(' ', '\\ ') >> 'my\\ file\\ number' > > What if a has more than 1 space between words? Then I think this would > be a safer way. > print "\\ ".join("my file number".split()) > my\ file\ number If those spaces are in the actual filename, you'll wa

Re: [Tutor] Performance list vs. deque for [-1]

2010-08-12 Thread Sander Sweers
On 12 August 2010 12:07, Sander Sweers wrote: > Deque took 0.009195 seconds > 693.01178383827209 / 10 (default times run by timeit) Messed up the deque results :( Deque took 0.009195 seconds 919.49732708930969 / 10 (default times run by timeit) Greets Sander

Re: [Tutor] string conversion according to the terminal

2010-08-12 Thread Sander Sweers
On 12 August 2010 10:40, Evert Rol wrote: a = "my file number" a.replace(' ', '\\ ') > 'my\\ file\\ number' What if a has more than 1 space between words? Then I think this would be a safer way. >>> print "\\ ".join("my file number".split()) my\ file\ number Greets Sander __

Re: [Tutor] Performance list vs. deque for [-1]

2010-08-12 Thread Dave Angel
Knacktus wrote: Hi everyone, I'm wondering what's the fastet datatype in python to lookup the last element in an ordered collection. I know about lists, of course, and read about deques. As I understand deques have better performance for popping and adding elements, but I didn't understand wh

Re: [Tutor] Performance list vs. deque for [-1]

2010-08-12 Thread Sander Sweers
On 12 August 2010 09:44, Alan Gauld wrote: >> I'm wondering what's the fastet datatype in python to lookup the last >> element in an ordered collection. > > When in doubt timeit() Out of curiosity I used timeit and lists are faster if we iterate over them one by one. Now this is my first go with

Re: [Tutor] string conversion according to the terminal

2010-08-12 Thread Evert Rol
> Hey- suppose we have a file name-"my file number" > if we want to execute it into the terminal it would be like - my\ file\ number > > so wondering is there any one in the python that change the enter string into > the terminal string one- > like if user enter the file name with path- "my file

[Tutor] string conversion according to the terminal

2010-08-12 Thread ANKUR AGGARWAL
Hey- suppose we have a file name-"my file number" if we want to execute it into the terminal it would be like - my\ file\ number so wondering is there any one in the python that change the enter string into the terminal string one- like if user enter the file name with path- "my file number". i wa

Re: [Tutor] a graceful program exit

2010-08-12 Thread Chris Fuller
The preferred and most graceful way is to use neither, as others have pointed out. However, you can't return an exit code that way, and it sometimes isn't feasible to structure your code to allow it. I prefer SystemExit, because it doesn't require adding something to the namespace (the sys mo

Re: [Tutor] Performance list vs. deque for [-1]

2010-08-12 Thread Alan Gauld
"Knacktus" wrote I'm wondering what's the fastet datatype in python to lookup the last element in an ordered collection. When in doubt timeit() But I would expect a standard list to be prettyy fast isf you are only concerned about accessing the last element [-1] Also, the collections will

Re: [Tutor] Executing Python from TCL

2010-08-12 Thread Alan Gauld
"Karim" wrote Anyway, you're right I found what I needed at: http://sourceforge.net/projects/elmer/files/elmer/elmer1.1.5/elmer1.1.5.tar.gz/download This is the open source Elmer distribution. OK, glad you found something and I'm sure it will be worth a try. But I'm pretty sure it will hav