Re: learning to use iterators
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 anyway and returns garbage if you pass it an > iterator, so there's really no reason for it here. The version using slice > notation on the other hand will raise a TypeError if you pass it an > iterator or anything else that can't be sliced, which is preferable to > silently returning incorrect results. The natural remedy to that problem is of course itertools.tee(): >>> from itertools import islice, tee >>> def n_grams(items, n): ... z = (islice(it, start, None) for start, it in enumerate(tee(items, n))) ... return zip(*z) ... >>> for item in n_grams(iter("abcde"), 3): ... print("".join(item)) ... abc bcd cde >>> -- https://mail.python.org/mailman/listinfo/python-list
If One Line
Hello, Is it possible in python: if ((x = a(b,c)) == 'TRUE'): print x Thanks. -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
> 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://mail.python.org/mailman/listinfo/python-list
Re: If One Line
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
Future of python on android
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 and there doesn't seem to be any activity around it for the past couple of years. If sl4a is out, what's the preferred way of running python on android? Guido is still working at google, right? This makes me suspect that python is ought to be part of the android ecosystem but can't find anything else beyond sl4a. So what's the future proof way of writing/deploying/installing python programs on android? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
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 "Roger Wilco wants to welcome you...to the space janitor's closet..." - Original Message - From: "JC" Newsgroups: comp.lang.python To: Sent: Thursday, December 25, 2014 5:18 PM Subject: If One Line Hello, Is it possible in python: if ((x = a(b,c)) == 'TRUE'): print x Thanks. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
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 "Roger Wilco wants to welcome you...to the space janitor's closet..." - Original Message - From: "JC" Newsgroups: comp.lang.python To: Sent: Thursday, December 25, 2014 5:18 PM Subject: If One Line Hello, Is it possible in python: if ((x = a(b,c)) == 'TRUE'): print x Thanks. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
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
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. -- https://mail.python.org/mailman/listinfo/python-list
Re: question on string object handling in Python 2.7.8
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 for 2-byte string ‘hh’, which triggers the > malloc. However, when I put A/B into a big loop and try to measure the > performance using cProfile, B seems always faster than A. > Testing code: > for i in range(0, 1): > a = ‘h’ #or b = ‘hh’ > Testing cmd: python -m cProfile test.py > > So what is wrong here? B has one more malloc than A but is faster than > B? Your understanding. The first time through the loop, python creates a string object "h" or "hh" and creates a pointer (a or b) and assigns it to the string object. The next range(1, 1) times through the loop, python re-assigns the existing pointer to the existing string object. Maybe a 2 character string is faster to locate in the object table than a 1 character string, so that in the 2 character case, the lookup is faster. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Future of python on android
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, Fetchinson . wrote: > 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 and there doesn't seem to be any activity around > it for the past couple of years. > > If sl4a is out, what's the preferred way of running python on android? > Guido is still working at google, right? This makes me suspect that > python is ought to be part of the android ecosystem but can't find > anything else beyond sl4a. > > So what's the future proof way of writing/deploying/installing python > programs on android? > > Cheers, > Daniel > > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
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 that you're "seemingly" using a string to represent what should be a Boolean value. You may want to check out the contextlib, which allows you to create custom context managers utilizing the "with" statement. path = 'C:\d\e\f\g.txt with open(path) as f: do_something() -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
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..." - Original Message - From: Skip Montanaro To: Jacob Kruger Cc: Python Sent: Thursday, December 25, 2014 6:26 PM Subject: Re: If One Line 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
> 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 to tell the interactive interpreter that the block is ended. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
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 Kruger Cc: Python Sent: Thursday, December 25, 2014 7:45 PM Subject: Re: If One Line > 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 to tell the interactive interpreter that the block is ended. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
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 Kruger Cc: Python Sent: Thursday, December 25, 2014 7:45 PM Subject: Re: If One Line > 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 to tell the interactive interpreter that the block is ended. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: Future of python on android
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 around for a while and won't evaporate like sl4a :) Cheers, Daniel > 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, Fetchinson . > wrote: > >> 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 and there doesn't seem to be any activity around >> it for the past couple of years. >> >> If sl4a is out, what's the preferred way of running python on android? >> Guido is still working at google, right? This makes me suspect that >> python is ought to be part of the android ecosystem but can't find >> anything else beyond sl4a. >> >> So what's the future proof way of writing/deploying/installing python >> programs on android? >> >> Cheers, >> Daniel >> >> >> -- >> Psss, psss, put it down! - http://www.cafepress.com/putitdown >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- https://mail.python.org/mailman/listinfo/python-list
Re: converting PDF files is now an easy task
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 to Doc can provide more reliable Pdf to Doc results as under any circumstances, this is simply a rare Pdf to Doc. This way usually needs Pdf to Doc. Many punks may want to know how to get a Pdf to Doc. How is Python used in that conversion process ? -- Dave Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk http://www.pctipp.ch/downloads/dl/35905.asp -- https://mail.python.org/mailman/listinfo/python-list
Re: OFF TOPIC Snow Crash [was Re: Hello World]
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'd fundamentally flawed. The worst for me is that in a fictional universe with a VR system capable of displaying anything, the crux of the book revolves around a couple of characters having a long, long discussion about Sumerian history. A: "" B: "And then what?" A: "" B: etc It's been at least a decade since I read it, but wasn't that also the explanation for how the virus worked? -- https://mail.python.org/mailman/listinfo/python-list
Re: OFF TOPIC Snow Crash [was Re: Hello World]
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 probably have been rejected or seriously edited). My personal theory is that Stephenson polishes and polishes the first few chapters until the whole creative process really engages - the first chapter is especially overwritten - and then tears through the novel in an increasingly unrefined way, until it arrives at its anticlimactic conclusion. He was notorious for a while for not providing satisfying endings to his books. Hopefully it will finally settle down & amend my current impression. SNOW CRASH doesn't, I'm afraid, but Stephenson himself does as a writer. CRYPTONOMICON is a great geek read. ANATHEM is a fantastic piece of SF (possibly my favourite of his) THE SYSTEM OF THE WORLD is an amazing accomplishment and really shows that modern infotech didn't spring out of nothing like Venus from the foam. -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
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): return 'TRUE' b, c = 'foo', 'bar' if assign_to_x(a(b,c)) == 'TRUE': print(x) -- https://mail.python.org/mailman/listinfo/python-list
suggestions for VIN parsing
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.britishspares.com/41.php Thanks Vincent -- https://mail.python.org/mailman/listinfo/python-list
Re: suggestions for VIN parsing
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" should I learn, how should I approach this. > http://www.britishspares.com/41.php I don't see any VIN numbers there offhand (they perhaps don't belong on the public internet since they can sometimes be used to make a car key), but most people parse HTML using Python via lxml or BeautifulSoup. -- https://mail.python.org/mailman/listinfo/python-list
Re: suggestions for VIN parsing
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:56 PM, Dan Stromberg wrote: > 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" should I learn, how should I approach this. > > http://www.britishspares.com/41.php > > I don't see any VIN numbers there offhand (they perhaps don't belong > on the public internet since they can sometimes be used to make a car > key), but most people parse HTML using Python via lxml or > BeautifulSoup. > -- https://mail.python.org/mailman/listinfo/python-list
Re: suggestions for VIN parsing
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 I've done automobile VIN processing, I'm unfamiliar with motorcycle VIN processing. Traditional VINs consist of 17 alphanumeric (minus look-alike letters), and then certain offsets designate certain pieces of information (manufacturer, model, year, country of origin, etc). If you can describe what an actual VIN looks like and how you want to extract information from it, I'm sure folks here can come up with something. >From a rough reading of that URL you provided, it sounds like the format changed based on the year, so you would have to test against a a whole bunch of patterns to determine the year, and since some of the patterns overlap, you'd have to do subsequent checking. Something like import re def vin_to_year(vin): for pattern, min_val, max_val, year in [ (r'^(\d+)N$', 100, None, 1950), (r'^(\d+)NA$', 101, 15808, 1951), (r'^(\d+)$', 15809, 25000, 1951), (r'^(\d+)$', 25000, 32302, 1952), (r'^(\d+)$', 32303, 44134, 1953), (r'^(\d+)$', 44135, 56699, 1954), (r'^(\d+)$', 56700, 70929, 1955), # a whole bunch more like this ]: r = re.compile(pattern, re.I) m = r.match(vin) if m: if m.groups(): i = int(m.group(1)) if min_val is not None and i < min_val: continue if max_val is not None and i > max_val: continue return year # return DEFAULT_YEAR raise ValueError("Unable to determine year") Based on that link, it also looks like you might have to deal with partial-year ranges, so instead of just returning a year, you might need/want to return (start_year, start_month, end_year, end_month) instead of just the raw year. Thus, you'd have to update the table above to something like (r'^(\d+)$', 15809, 25000, 1951, 1, 1951, 12), (r'^KDA(\d+)$, None, None, 1980, 9, 1981, 4), (r'^K(\d+)$, None, None, 1974, 8, 1975, 7), # note that "K" has to follow "KDA" because of specificity and then iterate over for pattern, min_val, max_val, min_year, min_month, max_year, max_month in [ ... ]: # ... return (min_year, min_month, max_year, max_month) -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: suggestions for VIN parsing
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 dates of manufacture. Your problem is to come up with a suitable data structure to map VIN to date range. The core of this, in Python, is going to be a ‘dict’ instance. You need to represent “part of a VIN” as the key, and “range of dates” as the resulting value. For the value, a “date range” is expressed simply by a 2-item tuple of dates:: import datetime date_range = (datetime.date(1979, 8, 1), datetime.date(1980, 7, 31)) If you want something a little more expressive, make a namedtuple to name the items in the tuple:: import datetime import collections DateRange = collections.namedtuple('DateRange', ['begin', 'end']) date_range = DateRange( begin=datetime.date(1979, 8, 1), end=datetime.date(1980, 7, 31)) Given that a VIN is (despite the number) not a number, but instead a string of characters, I would recommend using “string prefix” as the key. To match a VIN, iterate through the keys and attempt a match against the prefix; if a match is found, the date range is obtained simply by getting the corresponding value from the dictionary. However, you have some entries in those tables with “prefix ranges”. You can extrapolate from what I wrote here to come up with a method for matching within a range of prefixes. I *strongly* recommend keeping the data set small until you come up with a working means to store and look up the information. While you do so, feel free to post (small!) code examples here to show your working. Good hunting. -- \ “The Vatican is not a state.… a state must have territory. This | `\ is a palace with gardens, about as big as an average golf | _o__) course.” —Geoffrey Robertson, 2010-09-18 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: suggestions for VIN parsing
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 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 dates of manufacture. > > Your problem is to come up with a suitable data structure to map VIN to > date range. > > The core of this, in Python, is going to be a ‘dict’ instance. You need > to represent “part of a VIN” as the key, and “range of dates” as the > resulting value. > > > For the value, a “date range” is expressed simply by a 2-item tuple of > dates:: > > import datetime > date_range = (datetime.date(1979, 8, 1), datetime.date(1980, 7, 31)) > > If you want something a little more expressive, make a namedtuple to > name the items in the tuple:: > > import datetime > import collections > > DateRange = collections.namedtuple('DateRange', ['begin', 'end']) > > date_range = DateRange( > begin=datetime.date(1979, 8, 1), > end=datetime.date(1980, 7, 31)) > > > Given that a VIN is (despite the number) not a number, but instead a > string of characters, I would recommend using “string prefix” as the > key. > > To match a VIN, iterate through the keys and attempt a match against the > prefix; if a match is found, the date range is obtained simply by > getting the corresponding value from the dictionary. > > However, you have some entries in those tables with “prefix ranges”. You > can extrapolate from what I wrote here to come up with a method for > matching within a range of prefixes. > > > I *strongly* recommend keeping the data set small until you come up with > a working means to store and look up the information. While you do so, > feel free to post (small!) code examples here to show your working. > > Good hunting. > > -- > \ “The Vatican is not a state.… a state must have territory. This | > `\ is a palace with gardens, about as big as an average golf | > _o__) course.” —Geoffrey Robertson, 2010-09-18 | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: suggestions for VIN parsing
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, it was a lazy way to capture the information needed. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: suggestions for VIN parsing
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: If One Line
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() function, possibly because you also have an else clause: x = a(b,c) if x == 'TRUE': print x else: print x, 'is not equal to a TRUE string.' Your subject line is misleading, since this has nothing to do with If. You *can* write an If one liner: if condition() == 'FLAG': print "condition equals flag" What you can't do is assignment as an expression: # None of these work if (x = func()) == 'RESULT': ... for item in (x = func()) or sequence: ... vars = [1, 2, 3, (x = func()), 4] -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
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 (assignment as an expression) with another (use of global variables). Your approach needs to have the name of the variable hard-coded, if you have three such variables you have to write three functions, you can't use local variables, and it has all the disadvantages of global state. And you don't even save any lines! Instead of a one-liner, you have six lines! > x = None > def assign_to_x(val): > global x > x = val > return val [...] > if assign_to_x(a(b,c)) == 'TRUE': > print(x) Just because a programming language allows something doesn't make it a good idea. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: OFF TOPIC Snow Crash [was Re: Hello World]
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 love SNOW CRASH, I do think it'd fundamentally flawed. The worst > for me is that in a fictional universe with a VR system capable of > displaying anything, the crux of the book revolves around a couple of > characters having a long, long discussion about Sumerian history. > > A: "" > B: "And then what?" > A: "" > B: etc Keep in mind the limitations of the media. The novel is written word, so there are only a limited number of ways of getting background information to the reader. In this case, having one character (an AI) tell another character (the protagonist) what he needs to know is arguably the least-worst way. The many pages of info-dumping is one of the lesser parts of the book. I wonder what Stephenson's motive for writing it as dialog was, because in other parts of the book he demonstrated great skill in imparting background information to the reader without dry info-dumps (e.g. the Rat Things). At least it is information that is *not* common knowledge in-universe. Old pulp SF used to be filled with cheesy dialog like this: Attractive but stupid female: "Professor, I know you've told me before, but how does the microwave oven work again?" Avuncular male authority figure: "Well my dear, as you know all foods contain water molecules. The oven uses radio-frequency subatomic radiation, know as 'microwaves', specially tuned to excite the oxygen-to-hydrogen molecular bonds in water molecules. As you know, heat is just the action of excited molecular bonds, so this has the effect of beaming heat energy deep into the food so that it cooks from the inside out without burning. and then the microwave oven is not used for anything more exciting than making a cup of tea for the rest of the book. In the case of Snow Crash, I think we need to keep in mind when it was written. In 1990, the idea that you might *carry on a conversation* with your computer still seemed (1) plausible to SF readers, who expected strong AI and robots with Asimov's Three Laws to be just around the corner, and (2) the widespread public Internet, or even use of computers, was still pretty rare. The idea that you could only get information out of a computer by typing, or pointing, would have struck readers in 1994 as terribly unrealistic. The other interface, the holographic interface so beloved of recent SF television and movies where you push screens around in space, hadn't been invented yet, and isn't terribly good for getting information to the reader since they can't actually see what is on the screen. > It's been at least a decade since I read it, but wasn't that also the > explanation for how the virus worked? Deep in the brain, well underneath the level of modern languages and consciousness, there is a deeper "machine language" of the brain. If you can write instructions in this machine language, you can control people's brains. Back in the distant past, the Sumerians learned how to do this via spoken language, but few people speak Sumerian any more, hence there are two versions of Snow Crash: one is a drug plus virus. The drug is to encourage people to inject themselves, which then allows the virus to get into their brain. The other is an animated bitmap, which contains "machine code" for the human brain, and is injected via the optic nerve (i.e. when a hacker sees it). -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: what is wrong with d.clear()?
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 peevishness > Are you using gmail? > If so when you compose a message > The compose window has little downward triangle > In there there is a 'plain text' option Ooh, thanks. I used to use plain text mode but at some point I lost track of the option, so for every reply I've been having to show the quoted portion, select all, and hit the remove formatting shortcut. This makes it a lot simpler. -- https://mail.python.org/mailman/listinfo/python-list
Re: Future of python on android
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: Classes - "delegation" question.
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 Python 2. Here is a version which works on both Python 2 and Python 3 https://gitorious.org/lieberman-style-delegation/lieberman-style-delegation/>. Licensed under the PSF license, which isn't really appropriate [0] but that's the license under which the original was received. [0] It's only appropriate for Python itself, and contributions to Python shouldn't even be licensed that way https://wiki.python.org/moin/PythonSoftwareFoundationLicenseFaq#What_if_I_want_to_contribute_my_code_to_the_PSF.3F>. Apache Software Foundation License 2.0 would be better. -- \ “When I get new information, I change my position. What, sir, | `\ do you do with new information?” —John Maynard Keynes | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
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! While I'm _definitely_ not going to advocate for this approach as a valid solution, I have to disagree with this being an issue. While it's more lines in the given example, if there were dozens of such assignment-within-conditional calls in the same code, the additional LOCs become negligible. Just because a programming language allows something doesn't make it a good idea. This is true. But conversely, just because I think something is a bad idea doesn't mean someone else can't have found a valid use for it. -- https://mail.python.org/mailman/listinfo/python-list
Re: suggestions for VIN parsing
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 to go beyond ‘str.startswith’, from what I can tell. -- \ “We are stuck with technology when what we really want is just | `\ stuff that works.” —Douglas Adams | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list