Re: [Tutor] Exception Handling

2008-12-29 Thread Alan Gauld
"spir" wrote I often use the else clause of try...except. This allows putting only the minimum problematic code lines inside the try block, which is good both for legibility andto avoid catching unexpected errors. The else will be executed only in case of no exception: try: problematic_inst

Re: [Tutor] Modifying a QIF

2008-12-29 Thread spir
On Mon, 29 Dec 2008 13:18:55 -0700 "Eduardo Vieira" wrote: > Hello, this weekend I had fun using Python for text processing. I > needed to change a qif converted from a ofx, using the tool MT2OFX > (http://www.xs4all.nl/~csmale/mt2ofx/en/index.htm) > I wanted to change transactions like these: >

[Tutor] Modifying a QIF

2008-12-29 Thread Eduardo Vieira
Hello, this weekend I had fun using Python for text processing. I needed to change a qif converted from a ofx, using the tool MT2OFX (http://www.xs4all.nl/~csmale/mt2ofx/en/index.htm) I wanted to change transactions like these: D11/14/2008 MCHEQUE 102 17590807;Cheque or Preauth. Debit T-500.00 N102

Re: [Tutor] Printing the code of a function

2008-12-29 Thread Kent Johnson
On Sun, Dec 28, 2008 at 8:49 PM, wormwood_3 wrote: > Hello all, > > This might be trivially easy, but I was having a hard time searching on it > since all the component terms are overloaded:-) I am wondering if there is a > way to print out the code of a defined function. If the source code is av

Re: [Tutor] Printing the code of a function

2008-12-29 Thread spir
On Mon, 29 Dec 2008 09:18:43 - "Alan Gauld" wrote: > > "wormwood_3" wrote > > > I am wondering if there is a way to print out the code of a defined > > function. > > Its not reliable but I think you can use > > func.func_code.filename > func.func_code.firstlineno > > To find the first

Re: [Tutor] Exception Handling

2008-12-29 Thread spir
On Mon, 29 Dec 2008 09:10:45 - "Alan Gauld" wrote: > > "bob gailer" wrote > > > Also IMHO it is bad design to put a lot of code inside a try block. > > In this case the user might make a mistake on day and then is forced > > to reenter the year and month! > > Obviously there is no absol

Re: [Tutor] optional parameter in list comprehension

2008-12-29 Thread bob gailer
prasad rao wrote: hello! I am a novice looking up to the tutor as my Guide. I got a problem while using optional parameter. #! user/bin/env python import os def myfiles(directory,extension=None): change that to def myfiles(directory,extension=""): for x in [os.path.join(x,i) f

Re: [Tutor] optional parameter in list comprehension

2008-12-29 Thread bob gailer
Dj Gilcrease wrote: def myfiles(directory,extension=None): for x in [os.path.join(x,i) for x,y,z in os.walk(directory)\ if extension: << SYNTAX ERROR! for i in z if i.endswith(extension)]:print x -- Bob Gailer Chapel Hill NC 919-636-4239 __

Re: [Tutor] optional parameter in list comprehension

2008-12-29 Thread Dj Gilcrease
def myfiles(directory,extension=None): for x in [os.path.join(x,i) for x,y,z in os.walk(directory)\ if extension: for i in z if i.endswith(extension)]:print x Dj Gilcrease OpenRPG Developer ~~http://www.openrpg.com ___ Tutor maillist -

[Tutor] optional parameter in list comprehension

2008-12-29 Thread prasad rao
hello!I am a novice looking up to the tutor as my Guide. I got a problem while using optional parameter. #! user/bin/env python import os def myfiles(directory,extension=None): for x in [os.path.join(x,i) for x,y,z in os.walk(directory)\ for i in z if i.endswith(extension)]:prin

Re: [Tutor] Printing the code of a function

2008-12-29 Thread Alan Gauld
"wormwood_3" wrote I am wondering if there is a way to print out the code of a defined function. Its not reliable but I think you can use func.func_code.filename func.func_code.firstlineno To find the first line of code in the original source file. Its up to you to figure out the last line

Re: [Tutor] Exception Handling

2008-12-29 Thread Alan Gauld
"bob gailer" wrote Also IMHO it is bad design to put a lot of code inside a try block. In this case the user might make a mistake on day and then is forced to reenter the year and month! Obviously there is no absolute rule here but I disagree. One of the biggest advantages of try/except err

Re: [Tutor] Exception Handling

2008-12-29 Thread Alan Gauld
"David" wrote Is this the correct way to handle a ValueError exception and should I get in the practice of catching them? Yes and Yes. Although I woulfd move the except clause up to just after the input section (which is where the errors will be raised). A couple of other comments below: