Re: Python Style Question

2014-11-12 Thread Anton
On Thursday, October 30, 2014 4:10:23 AM UTC-7, Steven D'Aprano wrote: > I don't particularly like either version. I prefer this: > > def load_int(obj): > if isinstance(obj, int): > # Case 1), an int, e.g. 7 > return obj > elif isinstance(obj, str): > # Case 2) and

Re: Python Style Question

2014-10-30 Thread Denis McMahon
On Fri, 31 Oct 2014 09:48:10 +1100, Steven D'Aprano wrote: > MRAB wrote: >> How about: >> >> int(str(obj).strip('"')) > > Absolutely not. > > obj = '""1\n\n\n\n' # not valid JSON load_int(obj) > => raises ValueError int(str(obj).strip('"')) > => wrongly returns 1 How about #!/us

Re: Python Style Question

2014-10-30 Thread Steven D'Aprano
Roy Smith wrote: > In article <54521c8f$0$12982$c3e8da3$54964...@news.astraweb.com>, > Steven D'Aprano wrote: > >> Anton wrote: >> >> > Let's say I have an incoming list of values *l*. Every element of *l* >> > can be one of the following options: >> > 1) an integer value >> > 2) a string in f

Re: Python Style Question

2014-10-30 Thread Roy Smith
In article <54521c8f$0$12982$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Anton wrote: > > > Let's say I have an incoming list of values *l*. Every element of *l* can > > be one of the following options: > > 1) an integer value > > 2) a string in form of '', e.g. '7' > > 3) a

Re: Python Style Question

2014-10-30 Thread Steven D'Aprano
MRAB wrote: > On 2014-10-30 11:10, Steven D'Aprano wrote: >> Anton wrote: >> >>> Let's say I have an incoming list of values *l*. Every element of *l* >>> can be one of the following options: >>> 1) an integer value >>> 2) a string in form of '', e.g. '7' >>> 3) a string with a json serialization

Re: Python Style Question

2014-10-30 Thread MRAB
On 2014-10-30 11:10, Steven D'Aprano wrote: Anton wrote: Let's say I have an incoming list of values *l*. Every element of *l* can be one of the following options: 1) an integer value 2) a string in form of '', e.g. '7' 3) a string with a json serialization of an integer value, e.g. '"7"' 4) so

Re: Python Style Question

2014-10-30 Thread Steven D'Aprano
Anton wrote: > Let's say I have an incoming list of values *l*. Every element of *l* can > be one of the following options: > 1) an integer value > 2) a string in form of '', e.g. '7' > 3) a string with a json serialization of an integer value, e.g. '"7"' > 4) something else that should be ignor

Re: Python Style Question

2014-10-29 Thread Anton
On Wednesday, October 29, 2014 4:59:25 AM UTC-7, Rafael Romero Carmona wrote: > 2014-10-29 12:25 GMT+01:00 Martin Kemp : > Actually it doesn't work because there is no add function and it > doesn't catch the TypeError function to ignore other exceptions than > ValueError. Doesn't it? I tested in Py

Re: Python Style Question

2014-10-29 Thread Anton
On Wednesday, October 29, 2014 4:43:33 AM UTC-7, Rafael Romero Carmona wrote: > Hi, first in Python 2.7.6 and Python 3.4.0 list haven't got any add > function but they have append. You are right, in my original code I use set instead of array, so it should be either values = set() or values.append

Re: Python Style Question

2014-10-29 Thread Martin Kemp
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 29/10/2014 12:01, Rafael Romero Carmona wrote: > 2014-10-29 12:25 GMT+01:00 Martin Kemp : On > 29/10/2014 10:45, Anton wrote: Let's say I have an incoming list of values *l*. Every element of *l* can be one of the following options: 1) an

Re: Python Style Question

2014-10-29 Thread Rafael Romero Carmona
2014-10-29 12:25 GMT+01:00 Martin Kemp : > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > On 29/10/2014 10:45, Anton wrote: >> Let's say I have an incoming list of values *l*. Every element of >> *l* can be one of the following options: 1) an integer value 2) a >> string in form of '', e.g. '7

Re: Python Style Question

2014-10-29 Thread Rafael Romero Carmona
Hi, first in Python 2.7.6 and Python 3.4.0 list haven't got any add function but they have append. I think you could do better with something like == import json l = [1, -1, 0, '1', '-1', '0', json.dumps(-1), json.dumps(1), json.dumps(0), 'x', 'sqjklsqjk__', (1, 2)] values = [] for c in

Re: Python Style Question

2014-10-29 Thread Martin Kemp
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 29/10/2014 10:45, Anton wrote: > Let's say I have an incoming list of values *l*. Every element of > *l* can be one of the following options: 1) an integer value 2) a > string in form of '', e.g. '7' 3) a string with a json > serialization of an int

Python Style Question

2014-10-29 Thread Anton
Let's say I have an incoming list of values *l*. Every element of *l* can be one of the following options: 1) an integer value 2) a string in form of '', e.g. '7' 3) a string with a json serialization of an integer value, e.g. '"7"' 4) something else that should be ignored I need to transform th

Re: Python Style Question

2009-01-22 Thread Terry Reedy
Steve Holden wrote: K-Dawg wrote: I am trying to become more pythonic as I learn python and get my mind around it instead of other languages I have used. I have an app that has a series of classes for objects it uses. From a style perspective, which should be done: Different py file for each

Re: Python Style Question

2009-01-22 Thread Steve Holden
K-Dawg wrote: > I am trying to become more pythonic as I learn python and get my mind > around it instead of other languages I have used. > > I have an app that has a series of classes for objects it uses. From a > style perspective, which should be done: > > Different py file for each class >

Python Style Question

2009-01-22 Thread K-Dawg
I am trying to become more pythonic as I learn python and get my mind around it instead of other languages I have used. I have an app that has a series of classes for objects it uses. From a style perspective, which should be done: Different py file for each class or One py file with all the c