Re: suggestions for VIN parsing

2014-12-25 Thread Ben Finney
Vincent Davis writes: > Any comment on using pyparsing VS regex A full-blown parser (with ‘pyparsing’) is overkill for this. Even regular expressions isn't needed. The built-in text type (‘str’) in Python 3 should have everything you need; you only need to match prefixes. No need in this task

Re: If One Line

2014-12-25 Thread alex23
On 26/12/2014 1:37 PM, Steven D'Aprano wrote: One approach is to use a function in the condition to do the assignment: Let me fix that for you: /s/approach/bad idea/ I never said it was a _good_ approach ;) And you don't even save any lines! Instead of a one-liner, you have six lines! Wh

Re: Classes - "delegation" question.

2014-12-25 Thread Ben Finney
Steven D'Aprano writes: > However, be warned that there are two subtly different models for > delegation. Here's the one that people seem to forget: > > http://code.activestate.com/recipes/519639-true-lieberman-style-delegation-in-python/ Very interesting! The recipe at that URL works only on P

Re: Future of python on android

2014-12-25 Thread Steven D'Aprano
Fetchinson . wrote: > Guido is still working at google, right? No. Google is still using Python for lots of things, but Guido is now working for Dropbox. https://www.python.org/~guido/ -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: what is wrong with d.clear()?

2014-12-25 Thread Ian Kelly
On Wed, Dec 24, 2014 at 5:21 AM, Rustom Mody wrote: > On Tuesday, December 23, 2014 6:30:30 PM UTC+5:30, shawool wrote: >> Thank you for answering my query. >> >> Fonts and colors are reset to defaults now. Sorry for the inconvenience >> caused. >> >> Regards, >> Shawool > > Sorry for the peevish

Re: OFF TOPIC Snow Crash [was Re: Hello World]

2014-12-25 Thread Steven D'Aprano
alex23 wrote: > On 24/12/2014 2:20 AM, Grant Edwards wrote: >> And even _with_ all the technical jibber-jabber, none of it explained >> or justified the whole "writing a virus to infect the brain through >> the optic nerve" thing which might just have well been magick and >> witches. > > While I

Re: If One Line

2014-12-25 Thread Steven D'Aprano
alex23 wrote: > On 26/12/2014 1:18 AM, JC wrote: >> Is it possible in python: >> >> if ((x = a(b,c)) == 'TRUE'): >> print x > > One approach is to use a function in the condition to do the assignment: Let me fix that for you: /s/approach/bad idea/ All you have done is replace one anti-pattern

Re: If One Line

2014-12-25 Thread Steven D'Aprano
JC wrote: > Hello, > > Is it possible in python: > > if ((x = a(b,c)) == 'TRUE'): > print x Fortunately, no. Assignment as an expression is an anti-pattern and a bug magnet. The above is best written as: if a(b,c) == 'TRUE': print 'TRUE' If you need the result of calling the a() fun

Re: suggestions for VIN parsing

2014-12-25 Thread Skip Montanaro
You're extracting structured data from an html file. You might want to look at the lxml.etree module. (I think that's where ElementTree landed when it was adopted into the stdlib). Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: suggestions for VIN parsing

2014-12-25 Thread Tim Chase
On 2014-12-25 19:58, Vincent Davis wrote: > Any comment on using pyparsing VS regex If the VIN had any sort of regular grammar (especially if it involved nesting) then pyparsing would have value. I defaulted to regexp (1) because it's available out of the box, and (2) while it might be overkill,

Re: suggestions for VIN parsing

2014-12-25 Thread Vincent Davis
Tim and Ben, Thanks for your input, I am working on it now and will come back when I have questions. Any comment on using pyparsing VS regex Vincent Davis 720-301-3003 On Thu, Dec 25, 2014 at 7:18 PM, Ben Finney wrote: > Vincent Davis writes: > > > I don't want to parse the page, I what a func

Re: suggestions for VIN parsing

2014-12-25 Thread Ben Finney
Vincent Davis writes: > I don't want to parse the page, I what a function that given a VIN > (frame or engine number) returns the year the bike was made. So the page has a collection of tables which the reader can use to manually look up the VIN, or elements of the VIN, to determine the range of

Re: suggestions for VIN parsing

2014-12-25 Thread Tim Chase
On 2014-12-25 17:59, Vincent Davis wrote: > These are vintage motorcycles so the "VIN's" are not like modern > VIN's these are frame numbers and engine number. > I don't want to parse the page, I what a function that given a VIN > (frame or engine number) returns the year the bike was made. While

Re: suggestions for VIN parsing

2014-12-25 Thread Vincent Davis
These are vintage motorcycles so the "VIN's" are not like modern VIN's these are frame numbers and engine number. I don't want to parse the page, I what a function that given a VIN (frame or engine number) returns the year the bike was made. Vincent Davis 720-301-3003 On Thu, Dec 25, 2014 at 5:5

Re: suggestions for VIN parsing

2014-12-25 Thread Dan Stromberg
On Thu, Dec 25, 2014 at 4:02 PM, Vincent Davis wrote: > I would like to parse the VIN, frame and engine numbers found on this page > (below). I don't really know any regex, I have looked a little at pyparsing. > I have some other similar numbers to. I am looking for suggestions, which > "tool" sho

suggestions for VIN parsing

2014-12-25 Thread Vincent Davis
I would like to parse the VIN, frame and engine numbers found on this page (below). I don't really know any regex, I have looked a little at pyparsing. I have some other similar numbers to. I am looking for suggestions, which "tool" should I learn, how should I approach this. http://www.britishspar

Re: If One Line

2014-12-25 Thread alex23
On 26/12/2014 1:18 AM, JC wrote: Is it possible in python: if ((x = a(b,c)) == 'TRUE'): print x One approach is to use a function in the condition to do the assignment: x = None def assign_to_x(val): global x x = val return val def a(x, y):

Re: OFF TOPIC Snow Crash [was Re: Hello World]

2014-12-25 Thread alex23
On 24/12/2014 9:50 PM, alister wrote: what feels like 3 or 4 chapters in & it is still trying to set the scene, an exercise in stylish writing with very little content so far. even early scifi written for magazines on a per word basis were not this excessive (because if they were they would proba

Re: OFF TOPIC Snow Crash [was Re: Hello World]

2014-12-25 Thread alex23
On 24/12/2014 2:20 AM, Grant Edwards wrote: And even _with_ all the technical jibber-jabber, none of it explained or justified the whole "writing a virus to infect the brain through the optic nerve" thing which might just have well been magick and witches. While I love SNOW CRASH, I do think it

Re: converting PDF files is now an easy task

2014-12-25 Thread David H. Lipman
From: "joshuaemsteves" There is a familiar chance Pdf to Doc wasn't going to take off as long as don't be an idiot and use this pdf to docx converter. I expect this was a bad hypothesis, but you really have to open your mind. While Pdf to Doc is used in those situations, it was shown that Pdf t

Re: Future of python on android

2014-12-25 Thread Fetchinson .
On 12/25/14, Billy Earney wrote: > try kivy, instead of sl4a http://kivy.org/ > > I believe in the past year or two, the python foundation gave a grant to > kivy to add further functionality.. Thanks, I didn't know about kivy but it looks quite nice, will give it a try! Hopefully it will be aroun

Re: If One Line

2014-12-25 Thread Jacob Kruger
Ok, makes sense - just slipped same one line if: action bit of code inside a function, and worked fine. Stay well Jacob Kruger Blind Biker Skype: BlindZA "Roger Wilco wants to welcome you...to the space janitor's closet..." - Original Message - From: Skip Montanaro To: Jacob Kru

Re: If One Line

2014-12-25 Thread Jacob Kruger
Ok, makes sense - just slipped same one line if: action bit of code inside a function, and worked fine. Stay well Jacob Kruger Blind Biker Skype: BlindZA "Roger Wilco wants to welcome you...to the space janitor's closet..." - Original Message - From: Skip Montanaro To: Jacob Kru

Re: If One Line

2014-12-25 Thread Skip Montanaro
> Actually more that in the interpreter, it's prompting me with ... as if I had left out a closing ) or something, but, suppose it could work fine in an actual imported bit of code? That's how it's supposed to work. Given that Python block structure is determined by indentation, you need some way

Re: If One Line

2014-12-25 Thread Jacob Kruger
Actually more that in the interpreter, it's prompting me with ... as if I had left out a closing ) or something, but, suppose it could work fine in an actual imported bit of code? Stay well Jacob Kruger Blind Biker Skype: BlindZA "Roger Wilco wants to welcome you...to the space janitor's closet

Re: If One Line

2014-12-25 Thread Rick Johnson
On Thursday, December 25, 2014 9:19:25 AM UTC-6, JC wrote: > Hello, > > Is it possible in python: > > if ((x = a(b,c)) == 'TRUE'): > print x > > Thanks. Could you not simply rephrase: result = foo() if result == 'TRUE': do_something() Of course, another oddity is fact th

Re: Future of python on android

2014-12-25 Thread Billy Earney
try kivy, instead of sl4a http://kivy.org/ I believe in the past year or two, the python foundation gave a grant to kivy to add further functionality.. According to wikipedia http://en.wikipedia.org/wiki/Guido_van_Rossum Guido works for dropbox. Billy On Thu, Dec 25, 2014 at 9:31 AM, Fetchinso

Re: question on string object handling in Python 2.7.8

2014-12-25 Thread Denis McMahon
On Tue, 23 Dec 2014 20:28:30 -0500, Dave Tian wrote: > Hi, > > There are 2 statements: > A: a = ‘h’ > B: b = ‘hh’ > > According to me understanding, A should be faster as characters would > shortcut this 1-byte string ‘h’ without malloc; B should be slower than > A as characters does not work fo

Re: If One Line

2014-12-25 Thread Rick Johnson
On Thursday, December 25, 2014 10:16:54 AM UTC-6, Jacob Kruger wrote: > One line assignment is ok, but, seems like you can't perform actions. > > #the following will work: > I = 1 if True else 2 > > #but the following will generate an error: > if I == 1: print("one") Only if "I" is undefined. --

Re: If One Line

2014-12-25 Thread Skip Montanaro
I don't get an error. >>> I = 1 if True else 2 >>> if I == 1: print("one") ... one >>> What error did you get? Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: If One Line

2014-12-25 Thread Jacob Kruger
One line assignment is ok, but, seems like you can't perform actions. #the following will work: I = 1 if True else 2 #but the following will generate an error: if I == 1: print("one") And, not sure if/how to work around that second one myself. Stay well Jacob Kruger Blind Biker Skype: BlindZA

Re: If One Line

2014-12-25 Thread Jacob Kruger
One line assignment is ok, but, seems like you can't perform actions. #the following will work: I = 1 if True else 2 #but the following will generate an error: if I == 1: print("one") And, not sure if/how to work around that second one myself. Stay well Jacob Kruger Blind Biker Skype: BlindZA

Future of python on android

2014-12-25 Thread Fetchinson .
Hi all, I was using sl4a for quite some time on android and it basically worked very well although some features are missing. It looks like sl4a is dead, although I could be wrong. Does anyone knowledgeable have any further info on the future of sl4a? For instance it doesn't work with android 5 an

Re: If One Line

2014-12-25 Thread Ian Kelly
On Thu, Dec 25, 2014 at 8:18 AM, JC wrote: > > Hello, > > Is it possible in python: > > if ((x = a(b,c)) == 'TRUE'): > print x No, assignments in Python are statements, not expressions. -- https://mail.python.org/mailman/listinfo/python-list

Re: If One Line

2014-12-25 Thread Fetchinson .
> Is it possible in python: > > if ((x = a(b,c)) == 'TRUE'): > print x Nope. Assignment is not allowed in a conditional. Cheers, Daniel > Thanks. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- https://m

If One Line

2014-12-25 Thread JC
Hello, Is it possible in python: if ((x = a(b,c)) == 'TRUE'): print x Thanks. -- https://mail.python.org/mailman/listinfo/python-list

Re: learning to use iterators

2014-12-25 Thread Peter Otten
Ian Kelly wrote: > On Wed, Dec 24, 2014 at 1:34 PM, Rustom Mody > wrote: >> +1 for the slice in succinct form > > Not only more succinct but also more correct. The purpose of islice is to > slice arbitrary iterables as opposed to just sequences. But this function > requires a reentrant iterable