Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread Chris Angelico
On Sat, May 12, 2012 at 2:11 PM, Devin Jeanpierre wrote: > I'm not talking about unexpected exceptions. I'm saying, if I expect > invalid input for int, where should I go to find out how to deal with > said invalid input properly? How do I know that int raises ValueError > on failure, and not, for

Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread Devin Jeanpierre
On Fri, May 11, 2012 at 11:21 PM, Chris Angelico wrote: > There are times when you want to catch all exceptions, though. > Top-level code will often want to replace exception tracebacks with > error messages appropriate to some external caller, or possibly log > the exception and return to some pr

Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread Chris Angelico
On Sat, May 12, 2012 at 5:34 AM, Devin Jeanpierre wrote: > On Fri, May 11, 2012 at 2:10 AM, Chris Angelico wrote: >> Unlike in Java, a function's list of things it can throw isn't part of >> its signature. Instead of trying to catch every possible exception, >> it's generally best to simply let e

Re: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Cameron Simpson
On 11May2012 15:40, Mark Lawrence wrote: | On 11/05/2012 15:32, Andreas Tawn wrote: | > It's also helpful to not have to display every attribute, of which there may be dozens. | | Do I detect a code smell here? Not necessarily. (Well, yeah, "dozens" may indicate time to partition stuff.) My "O"

Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread Devin Jeanpierre
On Fri, May 11, 2012 at 2:10 AM, Chris Angelico wrote: > Unlike in Java, a function's list of things it can throw isn't part of > its signature. Instead of trying to catch every possible exception, > it's generally best to simply let exceptions propagate unless you KNOW > you're expecting them. H

Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread John Terrak
Thank you all for your help. Greatly appreciated. John -- http://mail.python.org/mailman/listinfo/python-list

Re: __all__, public API, private stuff, and leading _

2012-05-11 Thread Ethan Furman
Emile van Sebille wrote: On 5/11/2012 9:41 AM Ethan Furman said... Style question: Since __all__ (if defined) is the public API, if I am using that should I also still use a leading underscore on my private data/functions/etc? I would, even if only to alert any future maintainer of the intern

Re: Retrieving result from embedded execution

2012-05-11 Thread Chris Angelico
On Sat, May 12, 2012 at 3:36 AM, Devin Jeanpierre wrote: > On Fri, May 11, 2012 at 12:45 AM, Stefan Behnel wrote: >> However, have you tried using a pipe for them instead of a real file? That >> would allow you to retrieve the output without needing to pass through a >> file in the file system. Y

Re: Retrieving result from embedded execution

2012-05-11 Thread Devin Jeanpierre
On Fri, May 11, 2012 at 12:45 AM, Stefan Behnel wrote: > However, have you tried using a pipe for them instead of a real file? That > would allow you to retrieve the output without needing to pass through a > file in the file system. You can also replace sys.stdout/err with arbitrary > objects in

Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread Chris Angelico
On Sat, May 12, 2012 at 3:12 AM, Ian Kelly wrote: > I believe that a MemoryError instance is pre-allocated for just this > scenario. Ah, wise move. It's one of those largely-imponderables, like figuring out how to alert the sysadmin to a router failure. ChrisA -- http://mail.python.org/mailman/

Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread Ian Kelly
On Fri, May 11, 2012 at 10:23 AM, Chris Angelico wrote: > Hmm. What happens if the interpreter can't construct a MemoryError exception? I believe that a MemoryError instance is pre-allocated for just this scenario. You can see it in the result of gc.get_objects(). >>> [x for x in gc.get_objects

Re: __all__, public API, private stuff, and leading _

2012-05-11 Thread Emile van Sebille
On 5/11/2012 9:41 AM Ethan Furman said... Style question: Since __all__ (if defined) is the public API, if I am using that should I also still use a leading underscore on my private data/functions/etc? I would, even if only to alert any future maintainer of the internal vs exposed nature of t

__all__, public API, private stuff, and leading _

2012-05-11 Thread Ethan Furman
Style question: Since __all__ (if defined) is the public API, if I am using that should I also still use a leading underscore on my private data/functions/etc? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread Chris Angelico
On Sat, May 12, 2012 at 2:15 AM, Christian Heimes wrote: > Am 11.05.2012 17:51, schrieb Terry Reedy: >> If the domain of a function is truly all Python objects, it cannot raise >> an error. I believe id(x) is such an example. > > Even id() can raise an exception, for example MemoryError when you a

Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread Christian Heimes
Am 11.05.2012 17:51, schrieb Terry Reedy: > If the domain of a function is truly all Python objects, it cannot raise > an error. I believe id(x) is such an example. Even id() can raise an exception, for example MemoryError when you are running out of memory. Christian -- http://mail.python.org/

Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread Terry Reedy
On 5/11/2012 1:55 AM, John Terrak wrote: I couldnt find anywhere in the documentation that int() can throw a ValueError. I checked the "The Python Language Reference", and the "The Python Standard Library " to no avail. Did I missed something? To add to Chris' answer: If the domain of a funct

RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
> >> It's also helpful to not have to display every attribute, of which > >> there may be dozens. > > > > Do I detect a code smell here? > > > I think so, Murphy's law dictates that the attribute you're interested in > will not be > displayed anyway. That's what __repr__'s for. -- http://mail.py

RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
> > It's also helpful to not have to display every attribute, of which there > > may be > dozens. > > Do I detect a code smell here? Possibly. I'll often try to subdivide into several simpler types, but sometimes that makes the code more complex than it needs to be. -- http://mail.python.org/m

Re: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Jean-Michel Pichavant
Mark Lawrence wrote: On 11/05/2012 15:32, Andreas Tawn wrote: It's also helpful to not have to display every attribute, of which there may be dozens. Do I detect a code smell here? I think so, Murphy's law dictates that the attribute you're interested in will not be displayed anyway. JM -

Re: Finding the line number of an 'else' statement via ast

2012-05-11 Thread Terry Reedy
On 5/11/2012 12:35 AM, Michael Rene Armida wrote: Given this source: def do_something(val): if val: return 'a' else: return 'b' How do I get the line number of the "else:" line, using the ast module? The grammar only includes the 'orelse' list: If(expr test, s

Re: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Mark Lawrence
On 11/05/2012 15:32, Andreas Tawn wrote: It's also helpful to not have to display every attribute, of which there may be dozens. Do I detect a code smell here? -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list

RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
> I have no idea why using __repr__ versus __str__ would make any difference in > the > order of the attributes. They're going to come out in the order you specify, > regardless of what you name your method. If you don't like the arbitrary > order you > get from the dictionary, then either sort

Re: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Dave Angel
On 05/11/2012 07:16 AM, Andreas Tawn wrote: >> >> This is a very interesting solution. >> >> I think it might be better suited (for my purpose) to __repr__ rather than >> __str__, mostly because I still lose control of the order the attributes >> appear. I have no idea why using __repr__ versus

Re: How can we covert string into Datetime object

2012-05-11 Thread MRAB
On 11/05/2012 12:13, Nikhil Verma wrote: Hi All I was going through this link http://docs.python.org/library/datetime.html#strftime-strptime-behavior. I practised strftime() and strptime() functions. Finally i stuck into a situation where i want to get the datetime object so that i can save it

RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
> This issue bit me once too often a few months ago, and now I have a class > called > "O" from which I often subclass instead of from "object". > Its main purpose is a friendly __str__ method, though it also has a friendly > __init__. > > Code: > > class O(object): > ''' A bare objec

How can we covert string into Datetime object

2012-05-11 Thread Nikhil Verma
Hi All I was going through this link http://docs.python.org/library/datetime.html#strftime-strptime-behavior. I practised strftime() and strptime() functions. Finally i stuck into a situation where i want to get the datetime object so that i can save it in my db. What i want is :- I have a stri

Re: Finding the line number of an 'else' statement via ast

2012-05-11 Thread Mark Lawrence
On 11/05/2012 05:35, Michael Rene Armida wrote: Given this source: def do_something(val): if val: return 'a' else: return 'b' How do I get the line number of the "else:" line, using the ast module? The grammar only includes the 'orelse' list: If(expr test, stm

Re: increment date present list of tuple by weeks python

2012-05-11 Thread Mark Lawrence
On 11/05/2012 10:55, Nikhil Verma wrote: Hi All I have a list like this :- [ ('7 May monday AM Neuropancreatic'), ('8 May tuesday PM Cardiovascular')] how can i increment date in the above list for the next months on weekly basis ? [ ('7 May monday AM Neuropancreatic'),('14May monday AM Neu

increment date present list of tuple by weeks python

2012-05-11 Thread Nikhil Verma
Hi All I have a list like this :- [ ('7 May monday AM Neuropancreatic'), ('8 May tuesday PM Cardiovascular')] how can i increment date in the above list for the next months on weekly basis ? [ ('7 May monday AM Neuropancreatic'),('14May monday AM Neuropancreatic')('21 May monday AM Neuropancr