From harrismh777 at gmail.com Thu May 1 00:16:17 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 30 Apr 2014 23:16:17 -0500 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> <7xeh0ekv7s.fsf@ruckus.brouhaha.com> Message-ID: <5361CA91.30401@gmail.com> On 4/30/14 10:56 PM, Paul Rubin wrote: > There is a nice Javascript simulation of the N4-ES here: > > http://www.antiquark.com/sliderule/sim/n4es/virtual-n4es.html > Thank you! The N4-ES and the N4-T (mine) are essentially the same rule. The N4-ES on the site is yellow (mine is white) and the site rule indicates Picket & Eckel Inc. (that's where the E comes from) Also the the ES states Chicage Ill USA where the T states Made in USA. The only technical difference is the T scale (which is folded-expanded on both). On the ES the T scale is listed only once in the margin. On the N4-T the T scale is listed 'twice'!-- once for each part of the fold. Well, that gives (2) scales instead of one --for T... increasing the number of scales on the rule from 34 to 35... if I'm counting right. Which makes the N4-T more valuable... supposedly. I don't plan are parting with it... till I croak, then my son (who is studying engineering this fall) will inherit it... heh he won't have a clue what to do with it ! The simulated rule on the site above is fabulous... especially if viewed from a large wide LED. ... simply fabulouso/ :) marcus From steve at pearwood.info Thu May 1 01:00:43 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 01 May 2014 05:00:43 GMT Subject: Unicode 7 References: Message-ID: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> On Tue, 29 Apr 2014 21:53:22 -0700, Rustom Mody wrote: > On Tuesday, April 29, 2014 11:29:23 PM UTC+5:30, Tim Chase wrote: >> While I dislike feeding the troll, what I see here is: > > > > Since its Unicode-troll time, here's my contribution > http://blog.languager.org/2014/04/unicode-and-unix-assumption.html I disagree with much of your characterisation of the Unix assumption, and I point out that out of the two most widespread flavours of OS today, Linux/Unix and Windows, it is *Windows* and not Unix which still regularly uses legacy encodings. Also your link to Joel On Software mistakenly links to me instead of Joel. There's a missing apostrophe in "Ive" [sic] in Acknowledgment #2. I didn't notice any other typos. -- Steven From wxjmfauth at gmail.com Thu May 1 02:00:37 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 30 Apr 2014 23:00:37 -0700 (PDT) Subject: Unicode 7 In-Reply-To: References: <4fc3221d-9b2e-4c95-9d36-c10a8fca7259@googlegroups.com> Message-ID: <58c7a006-3058-4137-8ae2-f5effbdc0e1e@googlegroups.com> Le mercredi 30 avril 2014 20:48:48 UTC+2, Tim Chase a ?crit?: > On 2014-04-30 00:06, wxjmfauth at gmail.com wrote: > > > @ Time Chase > > > > > > I'm perfectly aware about what I'm doing. > > > > Apparently, you're quite adept at appending superfluous characters to > > sensible strings...did you benchmark your email composition, too? ;-) > > > > -tkc (aka "Tim", not "Time") Mea culpa, ... From greg.ewing at canterbury.ac.nz Thu May 1 02:16:26 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 01 May 2014 18:16:26 +1200 Subject: Off-topic circumnavigating the earth in a mile or less [was Re: Significant digits in a float?] In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> Message-ID: Terry Reedy wrote: > For the most part, there are no bears within a mile of the North Pole > either. "they are rare north of 88?" (ie, 140 miles from pole). > https://en.wikipedia.org/wiki/Polar_bears > They mostly hunt in or near open water, near the coastlines. The way things are going, the coastline might be within a mile of the north pole quite soon. -- Greg From vlastimil.brom at gmail.com Thu May 1 03:49:43 2014 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 1 May 2014 09:49:43 +0200 Subject: Off-topic circumnavigating the earth in a mile or less [was Re: Significant digits in a float?] In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> Message-ID: 2014-05-01 3:57 GMT+02:00 Chris Angelico : > On Thu, May 1, 2014 at 9:46 AM, Ian Kelly wrote: >> It also works if your starting point is (precisely) the north pole. I >> believe that's the canonical answer to the riddle, since there are no >> bears in Antarctica. > > Yeah but that's way too obvious! Anyway, it's rather hard to navigate > due south from the north pole. Which way do you go? How do you know > you're still going due south? Will the rocket even light in that > climate? > > Important questions must be answered! > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list Well, after having been following the discussion, I couldn't resist but post the relevant sketch from the famous Czech play "The Conquest of the North Pole by the Czech Karel N?mec on 5th April 1909" by Jara Cimrman [as "dicovered" and presented by Z. Sverak and L. Smoljak] (translated by Craig Cravens) http://jaracimrman.files.wordpress.com/2010/04/north_pole.pdf (pp. 38-39) ============ Teacher: And now, friends, I?d like to draw your attention to a certain geographical peculiarity. If I stand next to the chief and step off in any direction, I always go south. Pharmacist: No! Teacher: Yes, yes! Watch! (stands next to the chief and steps off.) I?m going south. (He returns and sets off in another direction.) And now I?m going south again. And now ?once again south. Pharmacist: That?s unbelievable! Teacher: Hold on, you haven?t seen anything yet. Richard, stand here with your back to the chief. And now both of you, step forward. (Schwarzenegger and the chief, with their backs to each other, step forward.) Did you see that? They?re both going south! Pharmacist: That?s really something else! Teacher: And I?ve saved the best for last. Now, you?ll really see something. Vojt?ch, mark the Pole with an X and step aside. (Vojt?ch obeys. The teacher sets off toward the mark.) Watch this. I?m going north (he crosses the mark and continues walking) and now I?m going south! And now back: north ? and now south. Pharmacist: That?s impossible! Teacher: Try it yourself. Pharmacist: This I?ve got to see. (He walks towards the pole and the moment he crosses it his face lights up with joy.) Wow! Friends, this was worth it! On the verge of death from hypothermia, from hunger, and from exhaustion, but it was worth it! ============= regards, vbr From roy at panix.com Thu May 1 08:56:13 2014 From: roy at panix.com (Roy Smith) Date: Thu, 01 May 2014 08:56:13 -0400 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> Message-ID: In article , Mark H Harris wrote: > Absolutely, snort. I still have my K&E (Keuffel & Esser Co. N.Y.); > made of wood... (when ships were wood, and men were steel, and sheep ran > scared) ... to get to the S L T scales I have to pull the slide out > (turn it over) and reinsert it. You're right, the CF and DF scales are > missing, but the A B scales have the ?? symbol where it should be (more > or less). Mine is the 4058 C model, and you're right... has maths > equivalents and conversions printed on the back... For those who have no idea what we're talking about, take a look at http://www.ted.com/talks/clifford_stoll_on_everything. If you just want to see what you do with a slide rule, fast forward to 14:20, but you really owe it to yourself to invest the 18 minutes to watch the whole thing. From sam.murthy at gmail.com Thu May 1 11:34:57 2014 From: sam.murthy at gmail.com (s71murfy) Date: Thu, 1 May 2014 08:34:57 -0700 (PDT) Subject: Running scripts from shell / IDLE in windows Message-ID: <9fa954ea-e341-42ac-a91d-fb25598ccba7@googlegroups.com> Hi: I am trying to run the simple helloworld script from the IDLE shell. I want to pass it arguments. Please can you give me the syntax to do it? Thanks, Sam From harrismh777 at gmail.com Thu May 1 12:02:42 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 01 May 2014 11:02:42 -0500 Subject: Running scripts from shell / IDLE in windows References: <9fa954ea-e341-42ac-a91d-fb25598ccba7@googlegroups.com> Message-ID: <53627022.9020504@gmail.com> On 5/1/14 10:34 AM, s71murfy wrote: > > I am trying to run the simple helloworld script from the IDLE shell. I want to pass it arguments. Please can you give me the syntax to do it? > There are several ways to do this, depending on your preferences and goals. Is the helloworld script the tk version? In which case have the script put up input dialog boxes... The python docs pages are very clear about input parameter i/o and may give you some help, if you're building a script that you want to launch from a terminal, or startup... What I do with my IDLE scripts is embed to embed a Main function (or call it Hello(). So, I import hello, then call hello.Main(parms). or, hello.Hello(parms) example ====file hello.py=== def Hello(parms list): whatever whatever ==================== From IDLE: import hello hello.Hello([1, 2, 3, 4]) marcus From harrismh777 at gmail.com Thu May 1 12:18:28 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 01 May 2014 11:18:28 -0500 Subject: Running scripts from shell / IDLE in windows References: <9fa954ea-e341-42ac-a91d-fb25598ccba7@googlegroups.com> <53627022.9020504@gmail.com> Message-ID: On 5/1/14 11:02 AM, Mark H Harris wrote: > ====file hello.py=== > > def Hello(parms list): > whatever > whatever > > ==================== > > > From IDLE: > > import hello > > hello.Hello([1, 2, 3, 4]) Sorry, almost forgot, if you 'run' the module hello.py (with the IDLE run dropdown) then the 'hello' name will not be in the namespace... just enter: Hello(parms) Here is another example: ===hello.py=== def Hello(myname): out = "hello, " + str(myname) print(out) ============== import hello hello.Hello("mark") hello, mark From emile at fenx.com Thu May 1 12:34:35 2014 From: emile at fenx.com (emile) Date: Thu, 01 May 2014 09:34:35 -0700 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On 04/30/2014 11:21 AM, Grant Edwards wrote: > On 2014-04-29, emile wrote: >> On 04/29/2014 01:16 PM, Adam Funk wrote: >> >>> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >>> bear, & walks 1 km north, where he's back at his tent. What color is >>> the bear?" ;-) >> >> From how many locations on Earth can someone walk one mile south, one >> mile east, and one mile north and end up at their starting point? > > I'm pretty sure there are places in London like that. At least that's > what it seemed like to somebody from the midwestern US where the > streets are layed out on a grid. I was going to bring up London, but as I recall from my brief visit there, I wasn't sure you could go one mile straight in any direction. :) Emile From alister.nospam.ware at ntlworld.com Thu May 1 13:13:51 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 01 May 2014 17:13:51 GMT Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On Thu, 01 May 2014 09:34:35 -0700, emile wrote: > On 04/30/2014 11:21 AM, Grant Edwards wrote: >> On 2014-04-29, emile wrote: >>> On 04/29/2014 01:16 PM, Adam Funk wrote: >>> >>>> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >>>> bear, & walks 1 km north, where he's back at his tent. What color is >>>> the bear?" ;-) >>> >>> From how many locations on Earth can someone walk one mile south, >>> one >>> mile east, and one mile north and end up at their starting point? >> >> I'm pretty sure there are places in London like that. At least that's >> what it seemed like to somebody from the midwestern US where the >> streets are layed out on a grid. > > I was going to bring up London, but as I recall from my brief visit > there, I wasn't sure you could go one mile straight in any direction. > > :) > > Emile 100 yds is pushing it -- "They told me I was gullible ... and I believed them!" From random832 at fastmail.us Thu May 1 13:21:14 2014 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 01 May 2014 13:21:14 -0400 Subject: Unicode in Python In-Reply-To: References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> <03bb12d8-93be-4ef6-94ae-4a02789aea2d@googlegroups.com> Message-ID: <1398964874.23544.112634369.16888E6E@webmail.messagingengine.com> On Mon, Apr 28, 2014, at 4:57, wxjmfauth at gmail.com wrote: > Python 3: > - It missed the unicode shift. > - Covering the whole unicode range will not make > Python a unicode compliant product. Please cite exactly what portion of the unicode standard requires operations with all characters to be handled in the same amount of time and space, and forbids optimizations that make some characters handled faster or in less space than others. From rustompmody at gmail.com Thu May 1 14:04:41 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 1 May 2014 11:04:41 -0700 (PDT) Subject: Unicode 7 In-Reply-To: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> Message-ID: <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> On Thursday, May 1, 2014 10:30:43 AM UTC+5:30, Steven D'Aprano wrote: > On Tue, 29 Apr 2014 21:53:22 -0700, Rustom Mody wrote: > > On Tuesday, April 29, 2014 11:29:23 PM UTC+5:30, Tim Chase wrote: > >> While I dislike feeding the troll, what I see here is: > > Since its Unicode-troll time, here's my contribution > > http://blog.languager.org/2014/04/unicode-and-unix-assumption.html > Also your link to Joel On Software mistakenly links to me instead of Joel. > There's a missing apostrophe in "Ive" [sic] in Acknowledgment #2. Done, Done. > I didn't notice any other typos. Thank you sir! > I point out that out of the two most widespread flavours of OS today, > Linux/Unix and Windows, it is *Windows* and not Unix which still > regularly uses legacy encodings. Not sure what you are suggesting... That (I am suggesting that) 8859 is legacy and 1252 is not? > I disagree with much of your characterisation of the Unix assumption, I'd be interested to know the details -- Contents? Details? Tone? Tenor? Blaspheming the sacred scripture? (if you are so inclined of course) From pappgyozo at gmail.com Thu May 1 09:26:58 2014 From: pappgyozo at gmail.com (=?UTF-8?B?UGFwcCBHecWResWR?=) Date: Thu, 1 May 2014 15:26:58 +0200 Subject: Convert numpy array to single number In-Reply-To: References: <088cdf75-f196-404b-ba77-567559f431d8@googlegroups.com> Message-ID: Maybe something like this? >>> to_num = lambda array: np.sum(array * 2**np.arange(len(array)-1, -1, -1)) >>> to_num(np.array([1,0,1,0])) 10 2014-04-29 17:42 GMT+02:00 Tom P : > On 28.04.2014 15:04, mboyd02255 at gmail.com wrote: > >> I have a numpy array consisting of 1s and zeros for representing binary >> numbers: >> >> e.g. >> >> >>> binary >> array([ 1., 0., 1., 0.]) >> >> I wish the array to be in the form 1010, so it can be manipulated. >> >> I do not want to use built in binary converters as I am trying to build >> my own. >> >> > Do you mean that each element in the array represents a power of two? > So array([ 1., 0., 1., 0.]) represents 2^3 + 2 = 6 decimal? > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wrw at mac.com Thu May 1 11:53:51 2014 From: wrw at mac.com (William Ray Wing) Date: Thu, 01 May 2014 11:53:51 -0400 Subject: Significant digits in a float? In-Reply-To: <5361CA91.30401@gmail.com> References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> <7xeh0ekv7s.fsf@ruckus.brouhaha.com> <5361CA91.30401@gmail.com> Message-ID: <9AED7E7B-6DBD-4404-95E7-01BCD98FCB12@mac.com> On May 1, 2014, at 12:16 AM, Mark H Harris wrote: > On 4/30/14 10:56 PM, Paul Rubin wrote: > >> There is a nice Javascript simulation of the N4-ES here: >> >> http://www.antiquark.com/sliderule/sim/n4es/virtual-n4es.html >> > > Thank you! > > The N4-ES and the N4-T (mine) are essentially the same rule. The N4-ES on the site is yellow (mine is white) and the site rule indicates Picket & Eckel Inc. (that's where the E comes from) Also the the ES states Chicage Ill USA where the T states Made in USA. > I?ve resisted - but finally have to jump into this discussion... Picket used to talk a lot about their yellow background being optimized for the color the human eye was most sensitive to and therefore produced the sharpest focus and allowed the most precise reading of the scales. Nice theory, but at least on MY Picket rule the scales were printed not engraved and the result negated any possible advantage the color might have given. I?m surprised no one has jumped in to defend/tout the Dietzgen slide rules (which I always thought were the ultimate). Mine (their Vector Log Log) is one of their Microglide series that had teflon rails inserted in the body and is still totally stick-free after nearly 50 years. Taking it one step further, I _ALSO_ have a Curta Type II calculator http://en.wikipedia.org/wiki/Curta_calculator - which still operates as smoothly as it did the day I bought it. -Bill > The only technical difference is the T scale (which is folded-expanded on both). On the ES the T scale is listed only once in the margin. On the N4-T the T scale is listed 'twice'!-- once for each part of the fold. Well, that gives (2) scales instead of one --for T... increasing the number of scales on the rule from 34 to 35... if I'm counting right. Which makes the N4-T more valuable... supposedly. I don't plan are parting with it... till I croak, then my son (who is studying engineering this fall) will inherit it... heh he won't have a clue what to do with it ! > > The simulated rule on the site above is fabulous... especially if viewed from a large wide LED. ... simply fabulouso/ :) > > > > marcus > -- > https://mail.python.org/mailman/listinfo/python-list From square.steve at gmail.com Thu May 1 15:18:02 2014 From: square.steve at gmail.com (Steve Simmons) Date: Thu, 01 May 2014 20:18:02 +0100 Subject: Slightly OT - using PyUIC from Eclipse In-Reply-To: <5361a85a$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5360E0FC.70802@gmail.com> <5361a85a$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53629DEA.3060100@gmail.com> On 01/05/2014 02:50, Steven D'Aprano wrote: > On Thu, 01 May 2014 01:49:25 +0100, Steve Simmons wrote: > >> >> >> >> >> >>
>>
On 30/04/2014 23:49, Fabio Zadrozny >> wrote:
>>
>>
> cite="mid:CANXBEFrqndqCeT-9Hgqz7jRCZcmp8nz4VE+ebf-BKsYr54qQqQ >> @mail.gmail.com" >> type="cite"> > And that's about where I stopped reading. > > I'm sorry Steve, but you're writing to a programmer's forum here, and you > should be sending in plain text, not so-called "rich text" (actually HTML > code, as you can see). At the very least, if you absolutely must send > HTML code, you should instruct your mail program to also send plain text. > > People are reading this via Usenet and email and possibly using other > ways as well. Depending on how they are receiving your post, sending HTML > may be considered rude and a breach of etiquette (e.g. text-based news > groups typically ban binary attachments, including HTML), or their client > may not support HTML, or they may simply choose not to receive or read > such posts. (Pure HTML is one of the most reliable signs of spam email.) > > So I'm afraid that I have no idea what you were trying to say in your > post. Manually deciphering the message from the markup was too painful. > I'm not likely to be the only one. If you would care to try again using > plain text, you may get a better response rate. > > > Mea Culpa. Ironic really, the post was to thank Fabio for resolving my problem (posted correctly in plain text) and saying that I was too tired to make the required fix. Obviously too tired to hit 'plain text' instead of 'RTF' in my mail format drop-down too. Anyways, a plain text "Thank you" to Fabio for fixing my issue; a "Thank you" to Mark Harris for putting my encoded text through the transmogrifier and an apology to the rest of the list members. Steve From tgraves_cs at yahoo.com Thu May 1 15:49:21 2014 From: tgraves_cs at yahoo.com (Tom Graves) Date: Thu, 1 May 2014 12:49:21 -0700 (PDT) Subject: zipimport limited to 65536 files? Message-ID: <1398973761.73804.YahooMailNeo@web140106.mail.bf1.yahoo.com> Hello, I am trying to use python (2.6.6) to read a jar file that contains python files. ?I'm simply setting PYTHONPATH=?spark-assembly-1.0.0-SNAPSHOT-hadoop2.4.0.jar.???Unfortunately it fails to read the python files from the jar file and if run in verbose mode just shows: import zipimport # builtin # installed zipimport hook # zipimport: found 0 names in spark-assembly-1.0.0-SNAPSHOT-hadoop2.4.0.jar I was messing around and noticed that if I reduce the number of files and directories in the jar to below 65536 then it works: import zipimport # builtin # installed zipimport hook # zipimport: found 65452 names in pyspark.jar Is this a known limitation or is this perhaps fixed in newer version or is there a work around? Note, I'm not subscribed to the mailing list so please copy me in response if possible. Thanks, Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From orgnut at yahoo.com Thu May 1 15:51:17 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Thu, 01 May 2014 12:51:17 -0700 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> Message-ID: <77Sdnblwr9UrOP_OnZ2dnUVZ_uednZ2d@giganews.com> On 05/01/2014 05:56 AM, Roy Smith wrote: > In article , > Mark H Harris wrote: > >> Absolutely, snort. I still have my K&E (Keuffel & Esser Co. N.Y.); >> made of wood... (when ships were wood, and men were steel, and sheep ran >> scared) ... to get to the S L T scales I have to pull the slide out >> (turn it over) and reinsert it. You're right, the CF and DF scales are >> missing, but the A B scales have the ?? symbol where it should be (more >> or less). Mine is the 4058 C model, and you're right... has maths >> equivalents and conversions printed on the back... > > For those who have no idea what we're talking about, take a look at > http://www.ted.com/talks/clifford_stoll_on_everything. If you just want > to see what you do with a slide rule, fast forward to 14:20, but you > really owe it to yourself to invest the 18 minutes to watch the whole > thing. > Anyone (besides me) ever seen a cylindrical slide rule? I have one -- unfortunately misplaced at the moment. :-( The scales were helical around a cylinder giving (it was claimed) to be the equivalent of a five-foot rule. But that still only gave one additional significant digit. Only two scales, however, which limited its use to multiply/divide and logs. But interesting. I just did a quick google search and found a picture of one on e-bay, asking price of $175. This price rather surprised me because when I bought mine new (probably 45 or so years ago) I'm sure I didn't pay more than around $25-$30 for it. And mine is in far better condition than the one in the e-bay photo. I recently ran across mine, but promptly misplaced it again (long story -- don't ask...). I'll have to look for it again. (And no, mine is not for sale when/if I find it again.) -=- Larry -=- From a24061 at ducksburg.com Thu May 1 16:57:57 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 01 May 2014 21:57:57 +0100 Subject: Off-topic circumnavigating the earth in a mile or less References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> Message-ID: On 2014-05-01, Terry Reedy wrote: > On 4/30/2014 7:46 PM, Ian Kelly wrote: > >> It also works if your starting point is (precisely) the north pole. I >> believe that's the canonical answer to the riddle, since there are no >> bears in Antarctica. > > For the most part, there are no bears within a mile of the North Pole > either. "they are rare north of 88?" (ie, 140 miles from pole). > https://en.wikipedia.org/wiki/Polar_bears > They mostly hunt in or near open water, near the coastlines. > > I find it amusing that someone noticed and posted an alternate, > non-canonical solution. How might a bear be near the south pole? As > long as we are being creative, suppose some jokester mounts a near > life-size stuffed black bear, made of cold-tolerant artificial > materials, near but not at the South Pole. The intent is to give fright > to naive newcomers. Someone walking in a radius 1/2pi circle about the > pole might easily see it. OK, change bear to bird & the question to "What kind of bird is it?" -- There's no money in poetry, but there's no poetry in money either. --- Robert Graves From a24061 at ducksburg.com Thu May 1 16:55:20 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 01 May 2014 21:55:20 +0100 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> Message-ID: On 2014-05-01, Dennis Lee Bieber wrote: > On Tue, 29 Apr 2014 20:42:33 -0400, Roy Smith declaimed the > following: > >>In article , >> Dennis Lee Bieber wrote: >>> (one reason slide-rules were acceptable for so long -- and even my high >>> school trig course only required slide-rule significance even though half >>> the class had scientific calculators [costing >$100, when a Sterling >>> slide-rule could still be had for <$10]) >> >>Sterling? Snort. K&E was the way to go. > > Math teacher was selling them in my 10th grade... Actually I already > owned a Faber-Castell 57/22 "Business" ruler (which did NOT have the CF/DF > scales set for *PI) and a Pickett N-1010-ES Trig rule. What does a "business" slide-rule do? Depreciation? -- "Mrs CJ and I avoid clich?s like the plague." From a24061 at ducksburg.com Thu May 1 16:52:12 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 01 May 2014 21:52:12 +0100 Subject: Off-topic circumnavigating the earth in a mile or less References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> Message-ID: On 2014-04-30, Ethan Furman wrote: > Wow. It's amazing how writing something down, wrongly (I originally had north and south reversed), correcting it, > letting some time pass (enough to post the message so one can be properly embarrassed ;), and then rereading it later > can make something so much clearer! It's amazing how big a subthread appeared in response to a gag that I think I got from a Car Talk puzzler. -- A recent study conducted by Harvard University found that the average American walks about 900 miles a year. Another study by the AMA found that Americans drink, on average, 22 gallons of alcohol a year. This means, on average, Americans get about 41 miles to the gallon. http://www.cartalk.com/content/average-americans-mpg From a24061 at ducksburg.com Thu May 1 17:05:32 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 01 May 2014 22:05:32 +0100 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> <77Sdnblwr9UrOP_OnZ2dnUVZ_uednZ2d@giganews.com> Message-ID: On 2014-05-01, Larry Hudson wrote: > On 05/01/2014 05:56 AM, Roy Smith wrote: >> For those who have no idea what we're talking about, take a look at >> http://www.ted.com/talks/clifford_stoll_on_everything. If you just want >> to see what you do with a slide rule, fast forward to 14:20, but you >> really owe it to yourself to invest the 18 minutes to watch the whole >> thing. >> > > Anyone (besides me) ever seen a cylindrical slide rule? I have one -- unfortunately misplaced > at the moment. :-( > > The scales were helical around a cylinder giving (it was claimed) to be the equivalent of a > five-foot rule. But that still only gave one additional significant digit. Only two scales, > however, which limited its use to multiply/divide and logs. But interesting. I have a "circular" (really spiral) slide rule that I inherited from my grandfather. http://www.ducksburg.com/atlas_slide_rule/ One of my uncles told me that he took it (or a similar model) to university (ca. 1960, I guess) & got an F on a calculus test because his answers were too accurate & precise to be honest. He went to the professor's office, showed him the circular slide rule, & got an A. -- To live without killing is a thought which could electrify the world, if men were only capable of staying awake long enough to let the idea soak in. --- Henry Miller From breamoreboy at yahoo.co.uk Thu May 1 17:49:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 01 May 2014 22:49:20 +0100 Subject: Off-topic circumnavigating the earth in a mile or less In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> Message-ID: On 01/05/2014 21:57, Adam Funk wrote: > On 2014-05-01, Terry Reedy wrote: > >> On 4/30/2014 7:46 PM, Ian Kelly wrote: >> >>> It also works if your starting point is (precisely) the north pole. I >>> believe that's the canonical answer to the riddle, since there are no >>> bears in Antarctica. >> >> For the most part, there are no bears within a mile of the North Pole >> either. "they are rare north of 88?" (ie, 140 miles from pole). >> https://en.wikipedia.org/wiki/Polar_bears >> They mostly hunt in or near open water, near the coastlines. >> >> I find it amusing that someone noticed and posted an alternate, >> non-canonical solution. How might a bear be near the south pole? As >> long as we are being creative, suppose some jokester mounts a near >> life-size stuffed black bear, made of cold-tolerant artificial >> materials, near but not at the South Pole. The intent is to give fright >> to naive newcomers. Someone walking in a radius 1/2pi circle about the >> pole might easily see it. > > OK, change bear to bird & the question to "What kind of bird is it?" > A buffalo with an aqualung possibly? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From tjreedy at udel.edu Thu May 1 18:38:35 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 May 2014 18:38:35 -0400 Subject: Unicode 7 In-Reply-To: <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> Message-ID: On 5/1/2014 2:04 PM, Rustom Mody wrote: >>> Since its Unicode-troll time, here's my contribution >>> http://blog.languager.org/2014/04/unicode-and-unix-assumption.html I will not comment on the Unix-assumption part, but I think you go wrong with this: "Unicode is a Headache". The major headache is that unicode and its very few encodings are not universally used. The headache is all the non-unicode legacy encodings still being used. So you better title this section 'Non-Unicode is a Headache'. The first sentence is this misleading tautology: "With ASCII, data is ASCII whether its file, core, terminal, or network; ie "ABC" is 65,66,67." Let me translate: "If all text is ASCII encoded, then text data is ASCII, whether ..." But it was never the case that all text was ASCII encoded. IBM used 6-bit BCDIC and then 8-bit EBCDIC and I believe still uses the latter. Other mainframe makers used other encodings of A-Z + 0-9 + symbols + control codes. The all-ASCII paradise was never universal. You could have just as well said "With EBCDIC, data is EBCDIC, whether ..." https://en.wikipedia.org/wiki/Ascii https://en.wikipedia.org/wiki/EBCDIC A crucial step in the spread of Ascii was its use for microcomputers, including the IBM PC. The latter was considered a toy by the mainframe guys. If they had known that PCs would partly take over the computing world, they might have suggested or insisted that the it use EBCDIC. "With unicode there are: encodings" where 'encodings' is linked to https://en.wikipedia.org/wiki/Character_encodings_in_HTML If html 'always' used utf-8 (like xml), as has become common but not universal, all of the problems with *non-unicode* character sets and encodings would disappear. The pre-unicode declarations could then disappear. More truthful: "without unicode there are 100s of encodings and with unicode only 3 that we should worry about. "in-memory formats" These are not the concern of the using programmer as long as they do not introduce bugs or limitations (as do all the languages stuck on UCS-2 and many using UTF-16, including old Python narrow builds). Using what should generally be the universal transmission format, UFT-8, as the internal format means either losing indexing and slicing, having those operations slow from O(1) to O(len(string)), or adding an index table that is not part of the unicode standard. Using UTF-32 avoids the above but usually wasted space -- up to 75%. "strange beasties like python's FSR" Have you really let yourself be poisoned by JMF's bizarre rants? The FSR is an *internal optimization* that benefits most unicode operations that people actually perform. It uses UTF-32 by default but adapts to the strings users create by compressing the internal format. The compression is trivial -- simple dropping leading null bytes common to all characters -- so each character is still readable as is. The string headers records how many bytes are left. Is the idea of algorithms that adapt to inputs really strange to you? Like good adaptive algorthms, the FSR is invisible to the user except for reducing space or time or maybe both. Unicode operations are otherwise the same as with previous wide builds. People who used to use narrow-builds also benefit from bug elimination. The only 'headaches' involved might have been those of the developers who optimized previous wide builds. CPython has many other functions with special-case optimizations and 'fast paths' for common, simple cases. For instance, (some? all?) number operations are optimized for pairs of integers. Do you call these 'strange beasties'? PyPy is faster than CPython, when it is, because it is even more adaptable to particular computations by creating new fast paths. The mechanism to create these 'strange beasties' might have been a headache for the writers, but when it works, which it now seems to, it is not for the users. -- Terry Jan Reedy From tjreedy at udel.edu Thu May 1 19:03:24 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 May 2014 19:03:24 -0400 Subject: zipimport limited to 65536 files? In-Reply-To: <1398973761.73804.YahooMailNeo@web140106.mail.bf1.yahoo.com> References: <1398973761.73804.YahooMailNeo@web140106.mail.bf1.yahoo.com> Message-ID: <5362D2BC.6090103@udel.edu> On 5/1/2014 3:49 PM, Tom Graves wrote: > Hello, > > I am trying to use python (2.6.6) to read a jar file that contains > python files. I'm simply setting > PYTHONPATH=spark-assembly-1.0.0-SNAPSHOT-hadoop2.4.0.jar. > Unfortunately it fails to read the python files from the jar file and > if run in verbose mode just shows: > > import zipimport # builtin > # installed zipimport hook > # zipimport: found 0 names in spark-assembly-1.0.0-SNAPSHOT-hadoop2.4.0.jar > > I was messing around and noticed that if I reduce the number of files > and directories in the jar to below 65536 then it works: > > import zipimport # builtin > # installed zipimport hook > # zipimport: found 65452 names in pyspark.jar > > Is this a known limitation It is definitely not documented, which it should be if intentional. > or is this perhaps fixed in newer version or Install 3.4 and try. Or go to http://bugs.python.org, click search, enter 'zipimport' in the title box, change 'open' in the status box to 'dont care', and look at 44 titles returned (I did not see anything that looked relevant). All I know is that in the discussion about a ziplib issue, someone mentioned using zips with 100000s of files. But zipimport could have an additional limitation. > is there a work around? Multiple archives? > Note, I'm not subscribed to the mailing list so please copy me in > response if possible. -- Terry Jan Reedy From python at mrabarnett.plus.com Thu May 1 19:33:21 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 02 May 2014 00:33:21 +0100 Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> Message-ID: <5362D9C1.9000108@mrabarnett.plus.com> On 2014-05-01 23:38, Terry Reedy wrote: > On 5/1/2014 2:04 PM, Rustom Mody wrote: > >>>> Since its Unicode-troll time, here's my contribution >>>> http://blog.languager.org/2014/04/unicode-and-unix-assumption.html > > I will not comment on the Unix-assumption part, but I think you go wrong > with this: "Unicode is a Headache". The major headache is that unicode > and its very few encodings are not universally used. The headache is all > the non-unicode legacy encodings still being used. So you better title > this section 'Non-Unicode is a Headache'. > [snip] I think he's right when he says "Unicode is a headache", but only because it's being used to handle languages which are, themselves, a "headache": left-to-right versus right-to-left, sometimes on the same line; diacritics, possibly several on a glyph; etc. From msustik at gmail.com Thu May 1 21:00:17 2014 From: msustik at gmail.com (Matyas) Date: Thu, 1 May 2014 18:00:17 -0700 (PDT) Subject: optimized compile with egg files Message-ID: Our project is using setuptools to compile. I noticed that by default python setup.py build will create .pyc files which I assume are archived into the egg file. I do not know yet how to verify what is in the egg file. I tried using python setup.py build_py -O1 python setup.py install --user -O1 in my attempt to compile to .pyo files. Indeed the output indicates that .pyo files are created (I can see them in build/lib.macos-10.9-x86_64-2.7/...) However I still see the some files being bytecompiled to .pyc files as well. I am not sure where these end up, I cannot find them. Well I guess I hope for some direction on how to compile optimized using setuptools. Then how to run the optimized version of the modules? Often we use nosetests to run and nosetests does not take a -O parm like python. Also ipython does not like -O either. Thanks! From rustompmody at gmail.com Thu May 1 22:02:48 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 1 May 2014 19:02:48 -0700 (PDT) Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> Message-ID: On Friday, May 2, 2014 5:03:21 AM UTC+5:30, MRAB wrote: > On 2014-05-01 23:38, Terry Reedy wrote: > > On 5/1/2014 2:04 PM, Rustom Mody wrote: > >>>> Since its Unicode-troll time, here's my contribution > >>>> http://blog.languager.org/2014/04/unicode-and-unix-assumption.html > > I will not comment on the Unix-assumption part, but I think you go wrong > > with this: "Unicode is a Headache". The major headache is that unicode > > and its very few encodings are not universally used. The headache is all > > the non-unicode legacy encodings still being used. So you better title > > this section 'Non-Unicode is a Headache'. > [snip] > I think he's right when he says "Unicode is a headache", but only > because it's being used to handle languages which are, themselves, a > "headache": left-to-right versus right-to-left, sometimes on the same > line; diacritics, possibly several on a glyph; etc. Yes, the headaches go a little further back than Unicode. There is a certain large old book... In which is described the building of a 'tower that reached up to heaven'... At which point 'it was decided'? to do something to prevent that. And our headaches started. I dont know how one causally connects the 'headaches' but Ive seen - mojibake - unicode 'number-boxes' (what are these called?) - Worst of all what we *dont* see -- how many others dont see what we see? I never knew of any of this in the good ol days of ASCII ? Passive voice is often the best choice in the interests of political correctness It would be a pleasant surprise if everyone sees a pilcrow at start of line above From rustompmody at gmail.com Thu May 1 22:29:55 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 1 May 2014 19:29:55 -0700 (PDT) Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> Message-ID: <8c30f6fc-8493-419b-a4c8-dfe4a9d30de0@googlegroups.com> On Friday, May 2, 2014 4:08:35 AM UTC+5:30, Terry Reedy wrote: > On 5/1/2014 2:04 PM, Rustom Mody wrote: > >>> Since its Unicode-troll time, here's my contribution > >>> http://blog.languager.org/2014/04/unicode-and-unix-assumption.html > I will not comment on the Unix-assumption part, but I think you go wrong > with this: "Unicode is a Headache". The major headache is that unicode > and its very few encodings are not universally used. The headache is all > the non-unicode legacy encodings still being used. So you better title > this section 'Non-Unicode is a Headache'. > The first sentence is this misleading tautology: "With ASCII, data is > ASCII whether its file, core, terminal, or network; ie "ABC" is > 65,66,67." Let me translate: "If all text is ASCII encoded, then text > data is ASCII, whether ..." But it was never the case that all text was > ASCII encoded. IBM used 6-bit BCDIC and then 8-bit EBCDIC and I believe > still uses the latter. Other mainframe makers used other encodings of > A-Z + 0-9 + symbols + control codes. The all-ASCII paradise was never > universal. You could have just as well said "With EBCDIC, data is > EBCDIC, whether ..." > https://en.wikipedia.org/wiki/Ascii > https://en.wikipedia.org/wiki/EBCDIC > A crucial step in the spread of Ascii was its use for microcomputers, > including the IBM PC. The latter was considered a toy by the mainframe > guys. If they had known that PCs would partly take over the computing > world, they might have suggested or insisted that the it use EBCDIC. > "With unicode there are: > encodings" > where 'encodings' is linked to > https://en.wikipedia.org/wiki/Character_encodings_in_HTML > If html 'always' used utf-8 (like xml), as has become common but not > universal, all of the problems with *non-unicode* character sets and > encodings would disappear. The pre-unicode declarations could then > disappear. More truthful: "without unicode there are 100s of encodings > and with unicode only 3 that we should worry about. > "in-memory formats" > These are not the concern of the using programmer as long as they do not > introduce bugs or limitations (as do all the languages stuck on UCS-2 > and many using UTF-16, including old Python narrow builds). Using what > should generally be the universal transmission format, UFT-8, as the > internal format means either losing indexing and slicing, having those > operations slow from O(1) to O(len(string)), or adding an index table > that is not part of the unicode standard. Using UTF-32 avoids the above > but usually wasted space -- up to 75%. > "strange beasties like python's FSR" > Have you really let yourself be poisoned by JMF's bizarre rants? The FSR > is an *internal optimization* that benefits most unicode operations that > people actually perform. It uses UTF-32 by default but adapts to the > strings users create by compressing the internal format. The compression > is trivial -- simple dropping leading null bytes common to all > characters -- so each character is still readable as is. The string > headers records how many bytes are left. Is the idea of algorithms that > adapt to inputs really strange to you? > Like good adaptive algorthms, the FSR is invisible to the user except > for reducing space or time or maybe both. Unicode operations are > otherwise the same as with previous wide builds. People who used to use > narrow-builds also benefit from bug elimination. The only 'headaches' > involved might have been those of the developers who optimized previous > wide builds. > CPython has many other functions with special-case optimizations and > 'fast paths' for common, simple cases. For instance, (some? all?) number > operations are optimized for pairs of integers. Do you call these > 'strange beasties'? Here is an instance of someone who would like a certain optimization to be dis-able-able https://mail.python.org/pipermail/python-list/2014-February/667169.html To the best of my knowledge its nothing to do with unicode or with jmf. Why if optimizations are always desirable do C compilers have: -O0 O1 O2 O3 and zillions of more specific flags? JFTR I have no issue with FSR. What we have to hand to jmf - willingly or otherwise - is that many more people have heard of FSR thanks to him. [I am one of them] I dont even know whether jmf has a real technical (as he calls it 'mathematical') issue or its entirely political: "Why should I pay more for a EURO sign than a $ sign?" Well perhaps that is more related to the exchange rate than to python! From ben at benfinney.id.au Thu May 1 22:39:44 2014 From: ben at benfinney.id.au (Ben Finney) Date: Fri, 02 May 2014 12:39:44 +1000 Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> Message-ID: <85iopohpjj.fsf@benfinney.id.au> Rustom Mody writes: > Yes, the headaches go a little further back than Unicode. Okay, so can you change your article to reflect the fact that the headaches both pre-date Unicode, and are made much easier by Unicode? > There is a certain large old book... Ah yes, the neo-Sumerian story ?Enmerkar_and_the_Lord_of_Aratta? . Probably inspired by stories older than that, of course. > In which is described the building of a 'tower that reached up to heaven'... > At which point 'it was decided'? to do something to prevent that. > And our headaches started. And other myths with fantastic reasons for the diversity of language . > I never knew of any of this in the good ol days of ASCII Yes, by ignoring all other writing systems except one's own ? and thereby excluding most of the world's people ? the system can be made simpler. Hopefully the proportion of programmers who still feel they can make such a parochial choice is rapidly shrinking. -- \ ?Why doesn't Python warn that it's not 100% perfect? Are people | `\ just supposed to ?know? this, magically?? ?Mitya Sirenef, | _o__) comp.lang.python, 2012-12-27 | Ben Finney From rustompmody at gmail.com Thu May 1 22:39:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 1 May 2014 19:39:27 -0700 (PDT) Subject: Unicode 7 In-Reply-To: <8c30f6fc-8493-419b-a4c8-dfe4a9d30de0@googlegroups.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <8c30f6fc-8493-419b-a4c8-dfe4a9d30de0@googlegroups.com> Message-ID: <51602756-7019-4f79-b168-d12b2b801a8e@googlegroups.com> On Friday, May 2, 2014 7:59:55 AM UTC+5:30, Rustom Mody wrote: > "Why should I pay more for a EURO sign than a $ sign?" A unicode 'headache' there: I typed the Euro sign (trying again ? ) not EURO Somebody -- I guess its GG in overhelpful mode -- converted it And made my post: Content-Type: text/plain; charset=ISO-8859-1 Will some devanagarari vowels help it stop being helpful? ? ? ? ? ? ? ? ? From rustompmody at gmail.com Thu May 1 22:59:43 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 1 May 2014 19:59:43 -0700 (PDT) Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> Message-ID: <92004436-36a8-49ce-b4ec-dc0237b04bac@googlegroups.com> On Friday, May 2, 2014 8:09:44 AM UTC+5:30, Ben Finney wrote: > Rustom Mody writes: > > Yes, the headaches go a little further back than Unicode. > Okay, so can you change your article to reflect the fact that the > headaches both pre-date Unicode, and are made much easier by Unicode? Predate: Yes Made easier: No > > There is a certain large old book... > Ah yes, the neo-Sumerian story "Enmerkar_and_the_Lord_of_Aratta" > . > Probably inspired by stories older than that, of course. Thanks for that link > > In which is described the building of a 'tower that reached up to heaven'... > > At which point 'it was decided'? to do something to prevent that. > > And our headaches started. > And other myths with fantastic reasons for the diversity of language > . This one takes the cake - see 1st para http://hilgart.org/enformy/BronsonRekindling.pdf > > I never knew of any of this in the good ol days of ASCII > Yes, by ignoring all other writing systems except one's own - and > thereby excluding most of the world's people - the system can be made > simpler. > Hopefully the proportion of programmers who still feel they can make > such a parochial choice is rapidly shrinking. See link above: Ethnic differences and chauvinism are invariably linked From rosuav at gmail.com Thu May 1 23:01:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 May 2014 13:01:56 +1000 Subject: Unicode 7 In-Reply-To: <8c30f6fc-8493-419b-a4c8-dfe4a9d30de0@googlegroups.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <8c30f6fc-8493-419b-a4c8-dfe4a9d30de0@googlegroups.com> Message-ID: On Fri, May 2, 2014 at 12:29 PM, Rustom Mody wrote: > Here is an instance of someone who would like a certain optimization to be > dis-able-able > > https://mail.python.org/pipermail/python-list/2014-February/667169.html > > To the best of my knowledge its nothing to do with unicode or with jmf. It doesn't, and it has only to do with testing. I've had similar issues at times; for instance, trying to benchmark one language or language construct against another often means fighting against an optimizer. (How, for instance, do you figure out what loop overhead is, when an empty loop is completely optimized out?) This is nothing whatsoever to do with Unicode, nor to do with the optimization that Python and Pike (and maybe other languages) do with the storage of Unicode strings. ChrisA From steve+comp.lang.python at pearwood.info Thu May 1 23:15:24 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2014 03:15:24 GMT Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> Message-ID: <53630dcc$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 01 May 2014 18:38:35 -0400, Terry Reedy wrote: > "strange beasties like python's FSR" > > Have you really let yourself be poisoned by JMF's bizarre rants? The FSR > is an *internal optimization* that benefits most unicode operations that > people actually perform. It uses UTF-32 by default but adapts to the > strings users create by compressing the internal format. The compression > is trivial -- simple dropping leading null bytes common to all > characters -- so each character is still readable as is. For anyone who, like me, wasn't convinced that Unicode worked that way, you can see for yourself that it does. You don't need Python 3.3, any version of 3.x will work. In Python 2.7, it should work if you just change the calls from "chr()" to "unichr()": py> for i in range(256): ... c = chr(i) ... u = c.encode('utf-32-be') ... assert u[:3] == b'\0\0\0' ... assert u[3:] == c.encode('latin-1') ... py> for i in range(256, 0xFFFF+1): ... c = chr(i) ... u = c.encode('utf-32-be') ... assert u[:2] == b'\0\0' ... assert u[2:] == c.encode('utf-16-be') ... py> So Terry is correct: dropping leading zeroes, and treating the remainder as either Latin-1 or UTF-16, works fine, and potentially saves a lot of memory. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Thu May 1 23:16:57 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 1 May 2014 20:16:57 -0700 (PDT) Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <8c30f6fc-8493-419b-a4c8-dfe4a9d30de0@googlegroups.com> Message-ID: <17d23e0b-7876-49b3-a785-4601f58414c6@googlegroups.com> On Friday, May 2, 2014 8:31:56 AM UTC+5:30, Chris Angelico wrote: > On Fri, May 2, 2014 at 12:29 PM, Rustom Mody wrote: > > Here is an instance of someone who would like a certain optimization to be > > dis-able-able > > https://mail.python.org/pipermail/python-list/2014-February/667169.html > > To the best of my knowledge its nothing to do with unicode or with jmf. > It doesn't, and it has only to do with testing. I've had similar > issues at times; for instance, trying to benchmark one language or > language construct against another often means fighting against an > optimizer. (How, for instance, do you figure out what loop overhead > is, when an empty loop is completely optimized out?) This is nothing > whatsoever to do with Unicode, nor to do with the optimization that > Python and Pike (and maybe other languages) do with the storage of > Unicode strings. This was said in response to Terry's > CPython has many other functions with special-case optimizations and > 'fast paths' for common, simple cases. For instance, (some? all?) number > operations are optimized for pairs of integers. Do you call these > 'strange beasties'? which evidently vanished -- optimized out :D -- in multiple levels of quoting From torriem at gmail.com Thu May 1 23:50:40 2014 From: torriem at gmail.com (Michael Torrie) Date: Thu, 01 May 2014 21:50:40 -0600 Subject: Unicode in Python In-Reply-To: References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> <03bb12d8-93be-4ef6-94ae-4a02789aea2d@googlegroups.com> Message-ID: <53631610.80802@gmail.com> Can't help but feed the troll... forgive me. On 04/28/2014 02:57 AM, wxjmfauth at gmail.com wrote: > Python 2.7 + cp1252: > - Solid and coherent system (nothing to do with the Euro). Except that cp1252 is not unicode. Perhaps some subset of unicode can be encoded into bytes using cp1252. But if it works for you keep using it, and stop spreading nonsense about FSR. > Python 3: > - Flexible String Representation (a problem per se), > a mathematical absurditiy which does the opposite of > the coding schemes endorsed by Unicord.org (sheet of > paper and pencil!) > - Very deeply buggy (quadrature of the circle problem). Maybe it's the language barrier, but whatever it is you are talking about, I certainly can't make out. You've been ranting about FSR for years without being able to clearly say what's wrong with it. Please quote unicode specifications that you feel Python does not implement. What unicode characters cannot be represented? Does Python choke on certain unicode strings or expose entities it should not (like Javascript does)? Why would you think that the unicode consortium's list of byte encodings are the only possible valid ways of encoding unicode to a byte stream? If you're going to continue to write this sort of stuff, please have the decency to answer these questions at least. > Positive side: > - A very nice tool to teach the coding of characters > and unicode. Indeed. From tjreedy at udel.edu Fri May 2 00:16:36 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 May 2014 00:16:36 -0400 Subject: Unicode 7 In-Reply-To: <5362D9C1.9000108@mrabarnett.plus.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <5362D9C1.9000108@mrabarnett.plus.com> Message-ID: On 5/1/2014 7:33 PM, MRAB wrote: > On 2014-05-01 23:38, Terry Reedy wrote: >> On 5/1/2014 2:04 PM, Rustom Mody wrote: >> >>>>> Since its Unicode-troll time, here's my contribution >>>>> http://blog.languager.org/2014/04/unicode-and-unix-assumption.html >> >> I will not comment on the Unix-assumption part, but I think you go wrong >> with this: "Unicode is a Headache". The major headache is that unicode >> and its very few encodings are not universally used. The headache is all >> the non-unicode legacy encodings still being used. So you better title >> this section 'Non-Unicode is a Headache'. >> > [snip] > I think he's right when he says "Unicode is a headache", but only > because it's being used to handle languages which are, themselves, a > "headache": left-to-right versus right-to-left, sometimes on the same > line; Handling that without unicode is even worse. > diacritics, possibly several on a glyph; etc. Ditto. -- Terry Jan Reedy From rustompmody at gmail.com Fri May 2 00:42:21 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 1 May 2014 21:42:21 -0700 (PDT) Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <5362D9C1.9000108@mrabarnett.plus.com> Message-ID: <1c08837e-496b-4fb2-8ff9-f8a495b67d67@googlegroups.com> On Friday, May 2, 2014 9:46:36 AM UTC+5:30, Terry Reedy wrote: > On 5/1/2014 7:33 PM, MRAB wrote: > > On 2014-05-01 23:38, Terry Reedy wrote: > >> On 5/1/2014 2:04 PM, Rustom Mody wrote: > >>>>> Since its Unicode-troll time, here's my contribution > >>>>> http://blog.languager.org/2014/04/unicode-and-unix-assumption.html > >> I will not comment on the Unix-assumption part, but I think you go wrong > >> with this: "Unicode is a Headache". The major headache is that unicode > >> and its very few encodings are not universally used. The headache is all > >> the non-unicode legacy encodings still being used. So you better title > >> this section 'Non-Unicode is a Headache'. > > [snip] > > I think he's right when he says "Unicode is a headache", but only > > because it's being used to handle languages which are, themselves, a > > "headache": left-to-right versus right-to-left, sometimes on the same > > line; > Handling that without unicode is even worse. > > diacritics, possibly several on a glyph; etc. > Ditto. Whats the best cure for headache? Cut off the head Whats the best cure for Unicode? Ascii Saying however that there is no headache in unicode does not make the headache go away: http://lucumr.pocoo.org/2014/1/5/unicode-in-2-and-3/ No I am not saying that the contents/style/tone are right. However people are evidently suffering the transition. Denying it is not a help. And unicode consortium's ways are not exactly helpful to its own cause: Imagine the C standard committee deciding that adding mandatory garbage collection to C is a neat idea Unicode consortium's going from old BMP to current (6.0) SMPs to who-knows-what in the future is similar. From rosuav at gmail.com Fri May 2 00:54:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 May 2014 14:54:19 +1000 Subject: Unicode 7 In-Reply-To: <1c08837e-496b-4fb2-8ff9-f8a495b67d67@googlegroups.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <5362D9C1.9000108@mrabarnett.plus.com> <1c08837e-496b-4fb2-8ff9-f8a495b67d67@googlegroups.com> Message-ID: On Fri, May 2, 2014 at 2:42 PM, Rustom Mody wrote: > Unicode consortium's going from old BMP to current (6.0) SMPs to who-knows-what > in the future is similar. Unicode 1.0: "Let's make a single universal character set that can represent all the world's scripts. We'll define 65536 codepoints to do that with." Unicode 2.0: "Oh. That's not enough. Okay, let's define some more." It's not a fundamental change, nor is it unhelpful to Unicode's cause. It's simply an acknowledgement that 64K codepoints aren't enough. Yes, that gave us the mess of UTF-16 being called "Unicode" (if it hadn't been for Unicode 1.0, I doubt we'd now have so many languages using and exposing UTF-16 - it'd be a simple judgment call, pick UTF-8/UTF-16/UTF-32 based on what you expect your users to want to use), but it doesn't change Unicode's goal, and it also doesn't indicate that there's likely to be any more such changes in the future. (Just look at how little of the Unicode space is allocated so far.) ChrisA From tjreedy at udel.edu Fri May 2 01:05:48 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 May 2014 01:05:48 -0400 Subject: Unicode 7 In-Reply-To: <8c30f6fc-8493-419b-a4c8-dfe4a9d30de0@googlegroups.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <8c30f6fc-8493-419b-a4c8-dfe4a9d30de0@googlegroups.com> Message-ID: On 5/1/2014 10:29 PM, Rustom Mody wrote: > Here is an instance of someone who would like a certain optimization to be > dis-able-able > > https://mail.python.org/pipermail/python-list/2014-February/667169.html > > To the best of my knowledge its nothing to do with unicode or with jmf. Right. Ned has an actual technical reason to complain, even though the developers do not consider it strong enough to act. > Why if optimizations are always desirable do C compilers have: > -O0 O1 O2 O3 and zillions of more specific flags? One reason is that many optimizations sometimes introduce bugs, or to put it another way, they are based on assumptions that are not true for all code. For instance, some people have suggested that CPython should have an optional optimization based on the assumption that builtin names are never rebound. That is true for perhaps many code files, but definitely not all. Guido does not seem to like such conditional optimizations. I can think of three reasons for not adding to the numerous options CPython already has. 1. We do not have the developers resources to handle the added complications of multiple optimization options. 2. Zillions of options and flags confuse users. As it is, most options are seldom used. 3. Optimization options are easily misused, possibly leading to silently buggy results, or mysterious failures. For instance, people sometimes rebind builtins without realizing what they have done, such as using 'id' as a parameter name. Being in the habit of routinely using the 'assume no rebinding option' would lead to problems. I am rather sure that the string (unicode) test suite was reviewed and the performance of 3.2 wide builds recorded before the new implementation was committed. The tracker currently has 37 behavior (bug) issues marked for the unicode component. In a quick review, I do not see that any have anything to do with using standard UTF-32 versus adaptive UTF-32. Indeed, I believe a majority of the 37 were filed before 3.3 or are 2.7 specific. Problems with FSR itself have been fixed as discovered. > JFTR I have no issue with FSR. What we have to hand to jmf - willingly > or otherwise - is that many more people have heard of FSR thanks to him. [I am one of them] Somewhat ironically, I suppose your are right. > I dont even know whether jmf has a real > technical (as he calls it 'mathematical') issue or its entirely political: I would call his view personal or philosophical. I only object to endless repetition and the deception of claiming that personal views are mathematical facts. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Fri May 2 04:08:57 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2014 08:08:57 GMT Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <5362D9C1.9000108@mrabarnett.plus.com> <1c08837e-496b-4fb2-8ff9-f8a495b67d67@googlegroups.com> Message-ID: <53635299$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 01 May 2014 21:42:21 -0700, Rustom Mody wrote: > Whats the best cure for headache? > > Cut off the head o_O I don't think so. > Whats the best cure for Unicode? > > Ascii Unicode is not a problem to be solved. The inability to write standard human text in ASCII is a problem, e.g. one cannot write ?ASCII For Dummies? ? 2014 by Z?e Smith, now on sale 99? so even *Americans* cannot represent all their common characters in ASCII, let alone specialised characters from mathematics, science, the printing industry, and law. And even Americans sometimes need to write text in Foreign. Where is your ASCII now? The solution is to have at least one encoding which contains the additional characters needed. The plethora of such additional encodings is a problem. The solution is a single encoding that covers all needed characters, like Unicode, so that there is no need to handle multiple encodings. The inability for plain text files to record metadata of what encoding they use is a problem. The solution is to standardize on a single, world- wide encoding, like Unicode. > Saying however that there is no headache in unicode does not make the > headache go away: > > http://lucumr.pocoo.org/2014/1/5/unicode-in-2-and-3/ > > No I am not saying that the contents/style/tone are right. However > people are evidently suffering the transition. Denying it is not a help. Transitions are always more painful than after the transition has settled down. As I have said repeatedly, I look forward for the day when nobody but document archivists and academics need care about legacy encodings. But we're not there yet. > And unicode consortium's ways are not exactly helpful to its own cause: > Imagine the C standard committee deciding that adding mandatory garbage > collection to C is a neat idea > > Unicode consortium's going from old BMP to current (6.0) SMPs to > who-knows-what in the future is similar. I don't see the connection. -- Steven D'Aprano http://import-that.dreamwidth.org/ From alister.nospam.ware at ntlworld.com Fri May 2 04:19:44 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 02 May 2014 08:19:44 GMT Subject: Cookie not retrieving as it should in some cases References: Message-ID: On Fri, 02 May 2014 01:11:05 -0700, Ferrous Cranus wrote: > # retrieve cookie from client's browser otherwise set it try: > cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE', '') ) > cookieID = cookie['ID'].value > except: > cookieID = str( time.time() ) > cookieID = cookieID[-3:] > > cookie['ID'] = cookieID > > > Many times i noticed that the script instead of retrieving the cookie ID > value so to identify each visitor uniquely it insteads set its again. > The same think also happens when someone comes to superhost.gr via a > link from anothwe webpage > > can somebody tell me why this is happening? > is there some flaw in my code? Perhaps it can be written more > efficiently? I had a similar issue when using Beaker middleware for WSGI which was caused by me not specifying a location for the storage of the cookie database. -- There is a multi-legged creature crawling on your shoulder. -- Spock, "A Taste of Armageddon", stardate 3193.9 From steve+comp.lang.python at pearwood.info Fri May 2 04:45:41 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2014 08:45:41 GMT Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> Message-ID: <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 01 May 2014 19:02:48 -0700, Rustom Mody wrote: > I dont know how one causally connects the 'headaches' but Ive seen - > mojibake Mojibake is certainly more common with multiple encodings, but the solution to that is Unicode, not ASCII. In fact, in your blog post you even link to a post of mine where I explain that ASCII has gone through multiple backwards incompatible changes over the decades, which means you can have a limited form of mojibake even in pure ASCII. Between changes over various versions of ASCII, and ambiguous characters allowed by the standard, you needed some sort of out-of-band metadata to tell you whether they intended an @ or a `, a | or a ?, a ? or a #, to mention only a few. It's only since the 1980s that ASCII, actual 7-bit US ASCII, has become an unambiguous standard. But that's okay, because that merely allowed people to create dozens of 7-bit and 8-bit variations on ASCII, all incompatible with each other, and *call them ASCII* regardless of the actual standard name. Between ambiguities in actual ASCII, and common practice to label non- ASCII as ASCII, I can categorically say that mojibake has always been possible in so-called "plain text". If you haven't noticed it, it was because you were only exchanging documents with people who happened to use the same set of characters as you. > - unicode 'number-boxes' (what are these called?) They are missing character glyphs, and they have nothing to do with Unicode. They are due to deficiencies in the text font you are using. Admittedly with Unicode's 0x10FFFF possible characters (actually more, since a single code point can have multiple glyphs) it isn't surprising that most font designers have neither the time, skill or desire to create a glyph for every single code point. But then the same applies even for more restrictive 8-bit encodings -- sometimes font designers don't even bother providing glyphs for *ASCII* characters. (E.g. they may only provide glyphs for uppercase A...Z, not lowercase.) > - Worst of all what we > *dont* see -- how many others dont see what we see? Again, this a deficiency of the font. There are very few code points in Unicode which are intended to be invisible, e.g. space, newline, zero- width joiner, control characters, etc., but they ought to be equally invisible to everyone. No printable character should ever be invisible in any decent font. > I never knew of any of this in the good ol days of ASCII You must have been happy with a very impoverished set of symbols, then. > ? Passive voice is often the best choice in the interests of political > correctness > > It would be a pleasant surprise if everyone sees a pilcrow at start of > line above I do. -- Steven D'Aprano http://import-that.dreamwidth.org/ From alister.nospam.ware at ntlworld.com Fri May 2 04:49:07 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 02 May 2014 08:49:07 GMT Subject: Off-topic circumnavigating the earth in a mile or less References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> Message-ID: <7_I8v.213288$Ey6.51141@fx24.am4> On Thu, 01 May 2014 21:57:57 +0100, Adam Funk wrote: > On 2014-05-01, Terry Reedy wrote: > >> On 4/30/2014 7:46 PM, Ian Kelly wrote: >> >>> It also works if your starting point is (precisely) the north pole. I >>> believe that's the canonical answer to the riddle, since there are no >>> bears in Antarctica. >> >> For the most part, there are no bears within a mile of the North Pole >> either. "they are rare north of 88?" (ie, 140 miles from pole). >> https://en.wikipedia.org/wiki/Polar_bears They mostly hunt in or near >> open water, near the coastlines. >> >> I find it amusing that someone noticed and posted an alternate, >> non-canonical solution. How might a bear be near the south pole? As >> long as we are being creative, suppose some jokester mounts a near >> life-size stuffed black bear, made of cold-tolerant artificial >> materials, near but not at the South Pole. The intent is to give fright >> to naive newcomers. Someone walking in a radius 1/2pi circle about the >> pole might easily see it. > > OK, change bear to bird & the question to "What kind of bird is it?" Arctic Turn is a valid answer for all locations :-) -- Pardon me, but do you know what it means to be TRULY ONE with your BOOTH! From rosuav at gmail.com Fri May 2 05:01:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 May 2014 19:01:44 +1000 Subject: Unicode 7 In-Reply-To: <53635299$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <5362D9C1.9000108@mrabarnett.plus.com> <1c08837e-496b-4fb2-8ff9-f8a495b67d67@googlegroups.com> <53635299$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 2, 2014 at 6:08 PM, Steven D'Aprano wrote: > ... even *Americans* cannot represent all their common characters in > ASCII, let alone specialised characters from mathematics, science, the > printing industry, and law. Aside: What additional characters does law use that aren't in ASCII? Section ? and paragraph ? are used frequently, but you already mentioned the printing industry. Are there other symbols? ChrisA From rosuav at gmail.com Fri May 2 05:08:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 May 2014 19:08:24 +1000 Subject: Unicode 7 In-Reply-To: <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 2, 2014 at 6:45 PM, Steven D'Aprano wrote: >> - unicode 'number-boxes' (what are these called?) > > They are missing character glyphs, and they have nothing to do with > Unicode. They are due to deficiencies in the text font you are using. > > Admittedly with Unicode's 0x10FFFF possible characters (actually more, > since a single code point can have multiple glyphs) it isn't surprising > that most font designers have neither the time, skill or desire to create > a glyph for every single code point. But then the same applies even for > more restrictive 8-bit encodings -- sometimes font designers don't even > bother providing glyphs for *ASCII* characters. > > (E.g. they may only provide glyphs for uppercase A...Z, not lowercase.) This is another area where Unicode has given us "a great improvement over the old method of giving satisfaction". Back in the 1990s on OS/2, DOS, and Windows, a missing glyph might be (a) blank, (b) a simple square with no information, or (c) copied from some other font (common with dingbats fonts). With Unicode, the standard is to show a little box *with the hex digits in it*. Granted, those boxes are a LOT more readable for BMP characters than SMP (unless your text is huge, six digits in the space of one character will make them pretty tiny), and a "Unicode" font will generally include all (or at least most) of the BMP, but it's still better than having no information at all. ChrisA From ben at benfinney.id.au Fri May 2 05:16:29 2014 From: ben at benfinney.id.au (Ben Finney) Date: Fri, 02 May 2014 19:16:29 +1000 Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <5362D9C1.9000108@mrabarnett.plus.com> <1c08837e-496b-4fb2-8ff9-f8a495b67d67@googlegroups.com> <53635299$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85a9b0h76a.fsf@benfinney.id.au> Chris Angelico writes: > On Fri, May 2, 2014 at 6:08 PM, Steven D'Aprano > wrote: > > ... even *Americans* cannot represent all their common characters in > > ASCII, let alone specialised characters from mathematics, science, > > the printing industry, and law. > > Aside: What additional characters does law use that aren't in ASCII? > Section ? and paragraph ? are used frequently, but you already > mentioned the printing industry. Are there other symbols? ASCII does not contain ??? (U+00A9 COPYRIGHT SIGN) nor ??? (U+00AE REGISTERED SIGN), for instance. -- \ ?I got some new underwear the other day. Well, new to me.? ?Emo | `\ Philips | _o__) | Ben Finney From rosuav at gmail.com Fri May 2 05:24:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 May 2014 19:24:32 +1000 Subject: Unicode 7 In-Reply-To: <85a9b0h76a.fsf@benfinney.id.au> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <5362D9C1.9000108@mrabarnett.plus.com> <1c08837e-496b-4fb2-8ff9-f8a495b67d67@googlegroups.com> <53635299$0$29965$c3e8da3$5496439d@news.astraweb.com> <85a9b0h76a.fsf@benfinney.id.au> Message-ID: On Fri, May 2, 2014 at 7:16 PM, Ben Finney wrote: > Chris Angelico writes: > >> On Fri, May 2, 2014 at 6:08 PM, Steven D'Aprano >> wrote: >> > ... even *Americans* cannot represent all their common characters in >> > ASCII, let alone specialised characters from mathematics, science, >> > the printing industry, and law. >> >> Aside: What additional characters does law use that aren't in ASCII? >> Section ? and paragraph ? are used frequently, but you already >> mentioned the printing industry. Are there other symbols? > > ASCII does not contain ??? (U+00A9 COPYRIGHT SIGN) nor ??? (U+00AE > REGISTERED SIGN), for instance. Heh! I forgot about those. U+00A9 in particular has gone so mainstream that it's easy to think of it not as "I'm going to switch to my 'British English + Legal' dictionary now" and just as "This is a critical part of the basic dictionary". ChrisA From varun7rs at gmail.com Fri May 2 05:33:14 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Fri, 2 May 2014 02:33:14 -0700 (PDT) Subject: Designing a network in Python In-Reply-To: References: <8ab783e8-a36e-49e5-a329-2c4d98df8537@googlegroups.com> , > <6b386a23-ee11-46df-ade7-6cb235df4a18@googlegroups.com> Message-ID: On Wednesday, 30 April 2014 20:38:07 UTC+2, Joseph L. Casale wrote: > > I don't know how to do that stuff in python. Basically, I'm trying to pull certain data from the > > xml file like the node-name, source, destination and the capacity. Since, I am done with that > > part, I now want to have a link between source and destination and assign capacity to it. > > I dont mind writing you an SQLite schema and accessor class, can you define your data in a tabular > format and mail it to me offline, we add relationships etc as we go. > > Hopefully it inspires you to adopt this approach in the future as it often proves powerful. > > jlc Thanks a lot for your help. But, how do I mail you? I can't find your mail id here From jpiitula at ling.helsinki.fi Fri May 2 06:04:23 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 02 May 2014 13:04:23 +0300 Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico writes: > (common with dingbats fonts). With Unicode, the standard is to show > a little box *with the hex digits in it*. Granted, those boxes are a > LOT more readable for BMP characters than SMP (unless your text is > huge, six digits in the space of one character will make them pretty > tiny), and a "Unicode" font will generally include all (or at least > most) of the BMP, but it's still better than having no information I needed to see such tiny numbers just today, just the four of them in the tiny box. So I pressed C-+ a few times to _make_ the text huge, obtained my information, and returned to my normal text size with C--. Perfect. Usually all I need to know is that I have a character for which I don't have a glyph, but this time I wanted to record the number because I was testing things rather than reading the text. From marko at pacujo.net Fri May 2 06:05:06 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 02 May 2014 13:05:06 +0300 Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <5362D9C1.9000108@mrabarnett.plus.com> <1c08837e-496b-4fb2-8ff9-f8a495b67d67@googlegroups.com> <53635299$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87iopojy25.fsf@elektro.pacujo.net> Ben Finney : >> Aside: What additional characters does law use that aren't in ASCII? >> Section ? and paragraph ? are used frequently, but you already >> mentioned the printing industry. Are there other symbols? > > ASCII does not contain ??? (U+00A9 COPYRIGHT SIGN) nor ??? (U+00AE > REGISTERED SIGN), for instance. The em-dash is mapped on my keyboard ? I use it quite often. Marko From rustompmody at gmail.com Fri May 2 06:39:34 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 2 May 2014 03:39:34 -0700 (PDT) Subject: Unicode 7 In-Reply-To: <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> On Friday, May 2, 2014 2:15:41 PM UTC+5:30, Steven D'Aprano wrote: > On Thu, 01 May 2014 19:02:48 -0700, Rustom Mody wrote: > > - Worst of all what we > > *dont* see -- how many others dont see what we see? > Again, this a deficiency of the font. There are very few code points in > Unicode which are intended to be invisible, e.g. space, newline, zero- > width joiner, control characters, etc., but they ought to be equally > invisible to everyone. No printable character should ever be invisible in > any decent font. Thats not what I meant. I wrote http://blog.languager.org/2014/04/unicoded-python.html ? mostly on a debian box. Later on seeing it on a less heavily setup ubuntu box, I see ? ? ? ? ? ? ? ? have become 'missing-glyph' boxes. It leads me ask, how much else of what I am writing, some random reader has simply not seen? Quite simply we can never know ? because most are going to go away saying "mojibaked/garbled rubbish" Speaking of what you understood of what I said: Yes invisible chars is another problem I was recently bitten by. I pasted something from google into emacs' org mode. Following that link again I kept getting a broken link. Until I found that the link had an invisible char The problem was that emacs was faithfully rendering that char according to standard, ie invisibly! From steve+comp.lang.python at pearwood.info Fri May 2 07:52:21 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2014 11:52:21 GMT Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <5362D9C1.9000108@mrabarnett.plus.com> <1c08837e-496b-4fb2-8ff9-f8a495b67d67@googlegroups.com> <53635299$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536386f5$0$29965$c3e8da3$5496439d@news.astraweb.com> On Fri, 02 May 2014 19:01:44 +1000, Chris Angelico wrote: > On Fri, May 2, 2014 at 6:08 PM, Steven D'Aprano > wrote: >> ... even *Americans* cannot represent all their common characters in >> ASCII, let alone specialised characters from mathematics, science, the >> printing industry, and law. > > Aside: What additional characters does law use that aren't in ASCII? > Section ? and paragraph ? are used frequently, but you already mentioned > the printing industry. Are there other symbols? I was thinking of copyright, trademark, registered mark, and similar. I think these are all of relevant characters: py> for c in '????': ... unicodedata.name(c) ... 'COPYRIGHT SIGN' 'REGISTERED SIGN' 'SOUND RECORDING COPYRIGHT' 'TRADE MARK SIGN' -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri May 2 07:55:37 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2014 11:55:37 GMT Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> Message-ID: <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> On Fri, 02 May 2014 03:39:34 -0700, Rustom Mody wrote: > On Friday, May 2, 2014 2:15:41 PM UTC+5:30, Steven D'Aprano wrote: >> On Thu, 01 May 2014 19:02:48 -0700, Rustom Mody wrote: >> > - Worst of all what we >> > *dont* see -- how many others dont see what we see? > >> Again, this a deficiency of the font. There are very few code points in >> Unicode which are intended to be invisible, e.g. space, newline, zero- >> width joiner, control characters, etc., but they ought to be equally >> invisible to everyone. No printable character should ever be invisible >> in any decent font. > > Thats not what I meant. > > I wrote http://blog.languager.org/2014/04/unicoded-python.html > ? mostly on a debian box. > Later on seeing it on a less heavily setup ubuntu box, I see > ? ? ? ? ? ? ? ? > have become 'missing-glyph' boxes. > > It leads me ask, how much else of what I am writing, some random reader > has simply not seen? > Quite simply we can never know ? because most are going to go away > saying "mojibaked/garbled rubbish" > > Speaking of what you understood of what I said: Yes invisible chars is > another problem I was recently bitten by. I pasted something from google > into emacs' org mode. Following that link again I kept getting a broken > link. > > Until I found that the link had an invisible char > > The problem was that emacs was faithfully rendering that char according > to standard, ie invisibly! And you've never been bitten by an invisible control character in ASCII text? You've lived a sheltered life! Nothing you are describing is unique to Unicode. -- Steven D'Aprano http://import-that.dreamwidth.org/ From marko at pacujo.net Fri May 2 08:19:29 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 02 May 2014 15:19:29 +0300 Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878uqkjru6.fsf@elektro.pacujo.net> Steven D'Aprano : > And you've never been bitten by an invisible control character in > ASCII text? You've lived a sheltered life! That reminds me: "?" (nonbreakable space) is often used between numbers and units, for example. Marko From python.list at tim.thechases.com Fri May 2 08:58:00 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 2 May 2014 07:58:00 -0500 Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140502075800.30508552@bigbox.christie.dr> On 2014-05-02 19:08, Chris Angelico wrote: > This is another area where Unicode has given us "a great improvement > over the old method of giving satisfaction". Back in the 1990s on > OS/2, DOS, and Windows, a missing glyph might be (a) blank, (b) a > simple square with no information, or (c) copied from some other > font (common with dingbats fonts). With Unicode, the standard is to > show a little box *with the hex digits in it*. Granted, those boxes > are a LOT more readable for BMP characters than SMP (unless your > text is huge, six digits in the space of one character will make > them pretty tiny), and a "Unicode" font will generally include all > (or at least most) of the BMP, but it's still better than having no > information at all. I'm pleased when applications & fonts work properly, using both the placeholder fonts for "this character is legitimate but I can't display it with a font, so here, have a box with the codepoint numbers in it until I'm directed to use a more appropriate font at which point you'll see it correctly" and the "somebody crammed garbage in here, so I'll display it with "?" (U+FFFD) which is designated for exactly this purpose". -tkc From rustompmody at gmail.com Fri May 2 12:03:13 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 2 May 2014 09:03:13 -0700 (PDT) Subject: Unicode 7 In-Reply-To: <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e348f0a-9c31-447e-8438-9282942a08b2@googlegroups.com> On Friday, May 2, 2014 5:25:37 PM UTC+5:30, Steven D'Aprano wrote: > On Fri, 02 May 2014 03:39:34 -0700, Rustom Mody wrote: > > On Friday, May 2, 2014 2:15:41 PM UTC+5:30, Steven D'Aprano wrote: > >> On Thu, 01 May 2014 19:02:48 -0700, Rustom Mody wrote: > >> > - Worst of all what we > >> > *dont* see -- how many others dont see what we see? > >> Again, this a deficiency of the font. There are very few code points in > >> Unicode which are intended to be invisible, e.g. space, newline, zero- > >> width joiner, control characters, etc., but they ought to be equally > >> invisible to everyone. No printable character should ever be invisible > >> in any decent font. > > Thats not what I meant. > > I wrote http://blog.languager.org/2014/04/unicoded-python.html > > ? mostly on a debian box. > > Later on seeing it on a less heavily setup ubuntu box, I see > > ? ? ? ? ? ? ? ? > > have become 'missing-glyph' boxes. > > It leads me ask, how much else of what I am writing, some random reader > > has simply not seen? > > Quite simply we can never know ? because most are going to go away > > saying "mojibaked/garbled rubbish" > > Speaking of what you understood of what I said: Yes invisible chars is > > another problem I was recently bitten by. I pasted something from google > > into emacs' org mode. Following that link again I kept getting a broken > > link. > > Until I found that the link had an invisible char > > The problem was that emacs was faithfully rendering that char according > > to standard, ie invisibly! > And you've never been bitten by an invisible control character in ASCII > text? You've lived a sheltered life! For control characters Ive seen: - garbage (the ASCII equiv of mojibake) - Straight ^A^B^C - Maybe their names NUL,SOH,STX,ETX,EOT,ENQ,ACK? - Or maybe just a little dot . - More pathological behavior: a control sequence putting the terminal into some other mode But I dont ever remember seeing a control character become invisible (except [ \t\n\f]) From python at mrabarnett.plus.com Fri May 2 12:52:55 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 02 May 2014 17:52:55 +0100 Subject: Unicode 7 In-Reply-To: <85iopohpjj.fsf@benfinney.id.au> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <85iopohpjj.fsf@benfinney.id.au> Message-ID: <5363CD67.3050404@mrabarnett.plus.com> On 2014-05-02 03:39, Ben Finney wrote: > Rustom Mody writes: > >> Yes, the headaches go a little further back than Unicode. > > Okay, so can you change your article to reflect the fact that the > headaches both pre-date Unicode, and are made much easier by Unicode? > >> There is a certain large old book... > > Ah yes, the neo-Sumerian story ?Enmerkar_and_the_Lord_of_Aratta? > . > Probably inspired by stories older than that, of course. > >> In which is described the building of a 'tower that reached up to heaven'... >> At which point 'it was decided'? to do something to prevent that. >> And our headaches started. > > And other myths with fantastic reasons for the diversity of language > . > >> I never knew of any of this in the good ol days of ASCII > > Yes, by ignoring all other writing systems except one's own ? and > thereby excluding most of the world's people ? the system can be made > simpler. > ASCII lacked even ?. I can remember assembly listings in magazines containing lines such as: LDA ?0 I even (vaguely) remember an advert with a character that looked like ?, presumably because they didn't have ?. In a UK magazine? Very strange! > Hopefully the proportion of programmers who still feel they can make > such a parochial choice is rapidly shrinking. > From rustompmody at gmail.com Fri May 2 12:50:51 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 2 May 2014 09:50:51 -0700 (PDT) Subject: Unicode 7 In-Reply-To: <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> On Friday, May 2, 2014 5:25:37 PM UTC+5:30, Steven D'Aprano wrote: > On Fri, 02 May 2014 03:39:34 -0700, Rustom Mody wrote: > > On Friday, May 2, 2014 2:15:41 PM UTC+5:30, Steven D'Aprano wrote: > >> On Thu, 01 May 2014 19:02:48 -0700, Rustom Mody wrote: > >> > - Worst of all what we > >> > *dont* see -- how many others dont see what we see? > >> Again, this a deficiency of the font. There are very few code points in > >> Unicode which are intended to be invisible, e.g. space, newline, zero- > >> width joiner, control characters, etc., but they ought to be equally > >> invisible to everyone. No printable character should ever be invisible > >> in any decent font. > > Thats not what I meant. > > I wrote http://blog.languager.org/2014/04/unicoded-python.html > > ? mostly on a debian box. > > Later on seeing it on a less heavily setup ubuntu box, I see > > ? ? ? ? ? ? ? ? > > have become 'missing-glyph' boxes. > > It leads me ask, how much else of what I am writing, some random reader > > has simply not seen? > > Quite simply we can never know ? because most are going to go away > > saying "mojibaked/garbled rubbish" > > Speaking of what you understood of what I said: Yes invisible chars is > > another problem I was recently bitten by. I pasted something from google > > into emacs' org mode. Following that link again I kept getting a broken > > link. > > Until I found that the link had an invisible char > > The problem was that emacs was faithfully rendering that char according > > to standard, ie invisibly! > And you've never been bitten by an invisible control character in ASCII > text? You've lived a sheltered life! > Nothing you are describing is unique to Unicode. Just noticed a small thing in which python does a bit better than haskell: $ ghci let (?ne, fine) = (1,2) Prelude> (?ne, fine) (1,2) Prelude> In case its not apparent, the fi in the first fine is a ligature. Python just barfs: >>> ?ne = 1 File "", line 1 ?ne = 1 ^ SyntaxError: invalid syntax >>> The point of that example is to show that unicode gives all kind of "Aaah! Gotcha!!" opportunities that just dont exist in the old world. Python may have got this one right but there are surely dozens of others. On the other hand I see more eagerness for unicode source-text there eg. https://github.com/i-tu/Hasklig http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#unicode-syntax http://www.haskell.org/haskellwiki/Unicode-symbols http://hackage.haskell.org/package/base-unicode-symbols Some music ? ? ? ? to appease the utf-8 gods From python at mrabarnett.plus.com Fri May 2 13:07:07 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 02 May 2014 18:07:07 +0100 Subject: Unicode 7 In-Reply-To: <53635299$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <5362D9C1.9000108@mrabarnett.plus.com> <1c08837e-496b-4fb2-8ff9-f8a495b67d67@googlegroups.com> <53635299$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5363D0BB.7070808@mrabarnett.plus.com> On 2014-05-02 09:08, Steven D'Aprano wrote: > On Thu, 01 May 2014 21:42:21 -0700, Rustom Mody wrote: > > >> Whats the best cure for headache? >> >> Cut off the head > > o_O > > I don't think so. > > >> Whats the best cure for Unicode? >> >> Ascii > > Unicode is not a problem to be solved. > > The inability to write standard human text in ASCII is a problem, e.g. > one cannot write > > ?ASCII For Dummies? ? 2014 by Z?e Smith, now on sale 99? > [snip] Shouldn't that be "Zo?"? From torriem at gmail.com Fri May 2 13:39:42 2014 From: torriem at gmail.com (Michael Torrie) Date: Fri, 02 May 2014 11:39:42 -0600 Subject: Unicode 7 In-Reply-To: <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> Message-ID: <5363D85E.9070908@gmail.com> On 05/02/2014 10:50 AM, Rustom Mody wrote: > Python just barfs: > >>>> ?ne = 1 > File "", line 1 > ?ne = 1 > ^ > SyntaxError: invalid syntax >>>> > > The point of that example is to show that unicode gives all kind of > "Aaah! Gotcha!!" opportunities that just dont exist in the old world. > Python may have got this one right but there are surely dozens of others. Except that it doesn't. This has nothing to do with unicode handling. It has everything to do with what defines an identifier in Python. This is no different than someone wondering why they can't start an identifier in Python 1.x with a number or punctuation mark. From ned at nedbatchelder.com Fri May 2 13:46:08 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 02 May 2014 13:46:08 -0400 Subject: Unicode 7 In-Reply-To: <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> Message-ID: On 5/2/14 12:50 PM, Rustom Mody wrote: > Just noticed a small thing in which python does a bit better than haskell: > $ ghci > let (?ne, fine) = (1,2) > Prelude> (?ne, fine) > (1,2) > Prelude> > > In case its not apparent, the fi in the first fine is a ligature. > > Python just barfs: > >>>> >>>?ne = 1 > File "", line 1 > ?ne = 1 > ^ > SyntaxError: invalid syntax >>>> >>> Surely by now we could at least be explicit about which version of Python we are talking about? $ python2.7 Python 2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> ?ne = 1 File "", line 1 ?ne = 1 ^ SyntaxError: invalid syntax >>> ^D $ python3.4 Python 3.4.0b1 (default, Dec 16 2013, 21:05:22) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> ?ne = 1 >>> ?ne 1 In Python 2 identifiers must be ASCII. Python 3 allows many Unicode characters in identifiers (see PEP 3131 for details: http://legacy.python.org/dev/peps/pep-3131/) -- Ned Batchelder, http://nedbatchelder.com From __peter__ at web.de Fri May 2 14:07:02 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 02 May 2014 20:07:02 +0200 Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> Message-ID: Rustom Mody wrote: > Just noticed a small thing in which python does a bit better than haskell: > $ ghci > let (?ne, fine) = (1,2) > Prelude> (?ne, fine) > (1,2) > Prelude> > > In case its not apparent, the fi in the first fine is a ligature. > > Python just barfs: Not Python 3: Python 3.3.2+ (default, Feb 28 2014, 00:52:16) [GCC 4.8.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> (?ne, fine) = (1,2) >>> (?ne, fine) (2, 2) No copy-and-paste errors involved: >>> eval("\ufb01ne") 2 >>> eval(b"fine".decode("ascii")) 2 From bhawani90 at gmail.com Fri May 2 15:55:18 2014 From: bhawani90 at gmail.com (Bhawani Singh) Date: Fri, 2 May 2014 12:55:18 -0700 (PDT) Subject: Hi. I want to create a script to read a file placed in a remote linux server using python..need help..? Message-ID: I have created the script till here .. import os os.chdir("/var/log") fd = open("t1.txt", "r") for line in fd: if re.match("(.*)(file1)(.*)", line): print line, Output : file1 -------------------- this script i ran on the linux server, but now i want to run this script from another linux server and get the output displayed there..how can i do that... i tried to use : pexpect but getting no help.. From ben at benfinney.id.au Fri May 2 17:07:28 2014 From: ben at benfinney.id.au (Ben Finney) Date: Sat, 03 May 2014 07:07:28 +1000 Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <878uqkjru6.fsf@elektro.pacujo.net> Message-ID: <8561lnhotr.fsf@benfinney.id.au> Marko Rauhamaa writes: > That reminds me: "?" [U+00A0 NON-BREAKING SPACE] is often used between > numbers and units, for example. The non-breaking space (??? U+00A0) is frequently used in text to keep conceptually inseparable text such as ?100?km? from automatic word breaks . Because of established, conflicting conventions for separating groups of digits (?1,234.00? in many countries; ?1.234,00? in many others) , the ??? U+2009 THIN SPACE is recommended for separating digit groups (e.g. ?1?234?567?m?) . -- \ ?We spend the first twelve months of our children's lives | `\ teaching them to walk and talk and the next twelve years | _o__) telling them to sit down and shut up.? ?Phyllis Diller | Ben Finney From roy at panix.com Fri May 2 17:13:55 2014 From: roy at panix.com (Roy Smith) Date: Fri, 02 May 2014 17:13:55 -0400 Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <878uqkjru6.fsf@elektro.pacujo.net> Message-ID: In article , Ben Finney wrote: > The non-breaking space (???????? U+00A0) is frequently used in text to keep > conceptually inseparable text such as ???100??km??? from automatic word > breaks . Which, by the way, argparse doesn't honor... http://bugs.python.org/issue16623 From denismfmcmahon at gmail.com Fri May 2 18:32:19 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 2 May 2014 22:32:19 +0000 (UTC) Subject: Hi. I want to create a script to read a file placed in a remote linux server using python..need help..? References: Message-ID: On Fri, 02 May 2014 12:55:18 -0700, Bhawani Singh wrote: > I have created the script till here .. > > import os > > os.chdir("/var/log") > fd = open("t1.txt", "r") > for line in fd: > if re.match("(.*)(file1)(.*)", line): > print line, > > Output : > > file1 > > -------------------- > this script i ran on the linux server, but now i want to run this script > from another linux server and get the output displayed there..how can i > do that... > > i tried to use : pexpect but getting no help.. Method a: Go and sit in front of the keyboard on the other linux server, run the script and read the screen. Method b: Use telnet to login to your account on the other server, run the script. To run your script on someone elses machine usually needs you to be able to access their machine somehow. Either you are permitted to do it, in which case you should already know how to do it, or you're not permitted to do it, in which case we're not going to teach you how to do it here. -- Denis McMahon, denismfmcmahon at gmail.com From roy at panix.com Fri May 2 18:51:29 2014 From: roy at panix.com (Roy Smith) Date: Fri, 02 May 2014 18:51:29 -0400 Subject: Hi. I want to create a script to read a file placed in a remote linux server using python..need help..? References: Message-ID: In article , Denis McMahon wrote: > Method b: > > Use telnet to login to your account on the other server, run the script. Ugh. I hope nobody is using telnet anymore. Passwords send in plain text over the network. Bad. All uses of telnet should have long since been replaced with ssh. One of the cool thinks about ssh is that not only does it give you remote shell connectivity, but it can be used to execute commands remotely, over the same secure channel. There is an awesome python package called fabric (http://www.fabfile.org/) which makes it trivial to do this inside of a python program. You can use it as a command-line tool, or as a library embedded in another python script. From rustompmody at gmail.com Fri May 2 20:58:51 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 2 May 2014 17:58:51 -0700 (PDT) Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> Message-ID: <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> On Friday, May 2, 2014 11:37:02 PM UTC+5:30, Peter Otten wrote: > Rustom Mody wrote: > > Just noticed a small thing in which python does a bit better than haskell: > > $ ghci > > let (?ne, fine) = (1,2) > > Prelude> (?ne, fine) > > (1,2) > > In case its not apparent, the fi in the first fine is a ligature. > > Python just barfs: > Not Python 3: > Python 3.3.2+ (default, Feb 28 2014, 00:52:16) > [GCC 4.8.1] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> (?ne, fine) = (1,2) > >>> (?ne, fine) > (2, 2) > No copy-and-paste errors involved: > >>> eval("\ufb01ne") > 2 > >>> eval(b"fine".decode("ascii")) > 2 Aah! Thanks Peter (and Ned and Michael) ? 2-3 confusion ? my bad. I am confused about the tone however: You think this >>> (?ne, fine) = (1,2) # and no issue about it is fine? From rosuav at gmail.com Fri May 2 21:15:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 May 2014 11:15:49 +1000 Subject: Unicode 7 In-Reply-To: <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> Message-ID: On Sat, May 3, 2014 at 10:58 AM, Rustom Mody wrote: > You think this > >>>> (?ne, fine) = (1,2) # and no issue about it > > is fine? Not sure which part you're objecting to. Are you saying that this should be an error: >>> a, a = 1, 2 # simple ASCII identifier used twice or that Python should take the exact sequence of codepoints, rather than normalizing? Python 3.5.0a0 (default:6a0def54c63d, Mar 26 2014, 01:11:09) [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ?ne = 1 >>> vars() {'__package__': None, '__spec__': None, '__doc__': None, 'fine': 1, '__loader__': , '__builtins__': , '__name__': '__main__'} As regards normalization, I would be happy with either "keep it exactly as you provided" or "normalize according to ", as long as it's consistent. It's like what happens with SQL identifiers: according to the standard, an unquoted name should be uppercased, but some databases instead lowercase them. It doesn't break code (modulo quoted names, not applicable here), as long as it's consistent. (My reading of PEP 3131 is that NFKC is used; is that what's implemented, or was that a temporary measure and/or something for Py2 to consider?) ChrisA From ned at nedbatchelder.com Fri May 2 21:18:21 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 02 May 2014 21:18:21 -0400 Subject: Unicode 7 In-Reply-To: <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> Message-ID: On 5/2/14 8:58 PM, Rustom Mody wrote: > On Friday, May 2, 2014 11:37:02 PM UTC+5:30, Peter Otten wrote: >> Rustom Mody wrote: > >>> Just noticed a small thing in which python does a bit better than haskell: >>> $ ghci >>> let (?ne, fine) = (1,2) >>> Prelude> (?ne, fine) >>> (1,2) >>> In case its not apparent, the fi in the first fine is a ligature. >>> Python just barfs: > >> Not Python 3: > >> Python 3.3.2+ (default, Feb 28 2014, 00:52:16) >> [GCC 4.8.1] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> (?ne, fine) = (1,2) >>>>> (?ne, fine) >> (2, 2) > >> No copy-and-paste errors involved: > >>>>> eval("\ufb01ne") >> 2 >>>>> eval(b"fine".decode("ascii")) >> 2 > > Aah! Thanks Peter (and Ned and Michael) ? 2-3 confusion ? my bad. > > I am confused about the tone however: > You think this > >>>> (?ne, fine) = (1,2) # and no issue about it > > is fine? > > Can you be more explicit? It seems like you think it isn't fine. Why not? What bothers you about it? Should there be an issue? -- Ned Batchelder, http://nedbatchelder.com From rustompmody at gmail.com Fri May 2 21:42:26 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 2 May 2014 18:42:26 -0700 (PDT) Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> Message-ID: On Saturday, May 3, 2014 6:48:21 AM UTC+5:30, Ned Batchelder wrote: > On 5/2/14 8:58 PM, Rustom Mody wrote: > > On Friday, May 2, 2014 11:37:02 PM UTC+5:30, Peter Otten wrote: > >> Rustom Mody wrote: > >>> Just noticed a small thing in which python does a bit better than haskell: > >>> $ ghci > >>> let (?ne, fine) = (1,2) > >>> Prelude> (?ne, fine) > >>> (1,2) > >>> In case its not apparent, the fi in the first fine is a ligature. > >>> Python just barfs: > >> Not Python 3: > >> Python 3.3.2+ (default, Feb 28 2014, 00:52:16) > >> [GCC 4.8.1] on linux > >> Type "help", "copyright", "credits" or "license" for more information. > >>>>> (?ne, fine) = (1,2) > >>>>> (?ne, fine) > >> (2, 2) > >> No copy-and-paste errors involved: > >>>>> eval("\ufb01ne") > >> 2 > >>>>> eval(b"fine".decode("ascii")) > >> 2 > > Aah! Thanks Peter (and Ned and Michael) ? 2-3 confusion ? my bad. > > I am confused about the tone however: > > You think this > >>>> (?ne, fine) = (1,2) # and no issue about it > > is fine? > Can you be more explicit? It seems like you think it isn't fine. Why > not? What bothers you about it? Should there be an issue? Two identifiers that to some programmers - can look the same - and not to others - and that the language treats as different is not fine (or ?ne) to me. Putting them together as I did is summarizing the problem. Think of them textually widely separated. And the code (un)serendipitously 'working' (ie not giving NameErrors) From rosuav at gmail.com Fri May 2 21:54:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 May 2014 11:54:08 +1000 Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> Message-ID: On Sat, May 3, 2014 at 11:42 AM, Rustom Mody wrote: > Two identifiers that to some programmers > - can look the same > - and not to others > - and that the language treats as different > > is not fine (or ?ne) to me. The language treats them as the same, though. ChrisA From rustompmody at gmail.com Fri May 2 22:02:04 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 2 May 2014 19:02:04 -0700 (PDT) Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> Message-ID: <4c2e056d-eeda-4e2c-9eaa-c411212628d0@googlegroups.com> On Saturday, May 3, 2014 7:24:08 AM UTC+5:30, Chris Angelico wrote: > On Sat, May 3, 2014 at 11:42 AM, Rustom Mody wrote: > > Two identifiers that to some programmers > > - can look the same > > - and not to others > > - and that the language treats as different > > is not fine (or ?ne) to me. > The language treats them as the same, though. Whoops! I seem to be goofing a lot today Saw Peter's >>> (?ne, fine) = (1,2) Didn't notice his next line >>> (?ne, fine) (2, 2) So then I am back to my original point: Python is giving better behavior than Haskell in this regard! [Earlier reached this conclusion via a wrong path] From steve+comp.lang.python at pearwood.info Fri May 2 22:02:32 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 May 2014 02:02:32 GMT Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> Message-ID: <53644e38$0$29965$c3e8da3$5496439d@news.astraweb.com> On Fri, 02 May 2014 17:58:51 -0700, Rustom Mody wrote: > I am confused about the tone however: You think this > >>>> (?ne, fine) = (1,2) # and no issue about it > > is fine? It's no worse than any other obfuscated variable name: MOOSE, MO0SE, M0OSE = 1, 2, 3 xl, x1 = 1, 2 If you know your victim is reading source code in Ariel font, "rn" and "m" are virtually indistinguishable except at very large sizes. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri May 2 22:04:47 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 May 2014 02:04:47 GMT Subject: Unicode 7 References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> <53644e38$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53644ebf$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sat, 03 May 2014 02:02:32 +0000, Steven D'Aprano wrote: > On Fri, 02 May 2014 17:58:51 -0700, Rustom Mody wrote: > >> I am confused about the tone however: You think this >> >>>>> (?ne, fine) = (1,2) # and no issue about it >> >> is fine? > > > It's no worse than any other obfuscated variable name: > > MOOSE, MO0SE, M0OSE = 1, 2, 3 > xl, x1 = 1, 2 > > If you know your victim is reading source code in Ariel font, "rn" and > "m" are virtually indistinguishable except at very large sizes. Ooops! I too missed that Python normalises the name ?ne to fine, so in fact this is not a case of obfuscation. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri May 2 22:17:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 May 2014 12:17:05 +1000 Subject: Unicode 7 In-Reply-To: <53644e38$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> <53644e38$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 3, 2014 at 12:02 PM, Steven D'Aprano wrote: > If you know your victim is reading source code in Ariel font, "rn" and > "m" are virtually indistinguishable except at very large sizes. I kinda like the idea of naming it after a bratty teenager who rebels against her father and runs away from home, but normally the font's called Arial. :) ChrisA From tjreedy at udel.edu Fri May 2 22:19:55 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 May 2014 22:19:55 -0400 Subject: Unicode 7 In-Reply-To: References: <5361d4f9$0$11109$c3e8da3@news.astraweb.com> <82067b83-a6f5-4b16-b012-385535ea5607@googlegroups.com> <53635b34$0$29965$c3e8da3$5496439d@news.astraweb.com> <0bdd2577-2893-4564-9857-fcfc6021dced@googlegroups.com> <536387b8$0$29965$c3e8da3$5496439d@news.astraweb.com> <5e91529c-c03f-44ee-a610-5697fea167b2@googlegroups.com> <432508d1-984d-4c07-890b-31a7058429c6@googlegroups.com> Message-ID: On 5/2/2014 9:15 PM, Chris Angelico wrote: > (My reading of PEP 3131 is that NFKC is used; is that what's > implemented, or was that a temporary measure and/or something for Py2 > to consider?) The 3.4 docs say "The syntax of identifiers in Python is based on the Unicode standard annex UAX-31, with elaboration and changes as defined below; see also PEP 3131 for further details." ... "All identifiers are converted into the normal form NFKC while parsing; comparison of identifiers is based on NFKC." Without reading UAX-31, I don't know how much was changed, but I suspect not much. In any case, the current rules are intended and very unlikely to change as that would break code going either forward or back for little purpose. -- Terry Jan Reedy From wxjmfauth at gmail.com Sat May 3 03:46:28 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 3 May 2014 00:46:28 -0700 (PDT) Subject: Unicode in Python In-Reply-To: References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> <03bb12d8-93be-4ef6-94ae-4a02789aea2d@googlegroups.com> Message-ID: Le vendredi 2 mai 2014 05:50:40 UTC+2, Michael Torrie a ?crit?: > Can't help but feed the troll... forgive me. > > > > On 04/28/2014 02:57 AM, wxjmfauth at gmail.com wrote: > > > Python 2.7 + cp1252: > > > - Solid and coherent system (nothing to do with the Euro). > > > > Except that cp1252 is not unicode. Perhaps some subset of unicode can > > be encoded into bytes using cp1252. But if it works for you keep using > > it, and stop spreading nonsense about FSR. > > > > > Python 3: > > > - Flexible String Representation (a problem per se), > > > a mathematical absurditiy which does the opposite of > > > the coding schemes endorsed by Unicord.org (sheet of > > > paper and pencil!) > > > - Very deeply buggy (quadrature of the circle problem). > > > > Maybe it's the language barrier, but whatever it is you are talking > > about, I certainly can't make out. > > > > You've been ranting about FSR for years without being able to clearly > > say what's wrong with it. Please quote unicode specifications that you > > feel Python does not implement. What unicode characters cannot be > > represented? Does Python choke on certain unicode strings or expose > > entities it should not (like Javascript does)? > > > > Why would you think that the unicode consortium's list of byte encodings > > are the only possible valid ways of encoding unicode to a byte stream? > > > > If you're going to continue to write this sort of stuff, please have the > > decency to answer these questions at least. > > > > > Positive side: > > > - A very nice tool to teach the coding of characters > > > and unicode. > > > > Indeed. ======== - From jurko.gospodnetic at pke.hr Sat May 3 06:37:24 2014 From: jurko.gospodnetic at pke.hr (=?windows-1250?Q?Jurko_Gospodneti=E6?=) Date: Sat, 03 May 2014 12:37:24 +0200 Subject: Why has __new__ been implemented as a static method? Message-ID: Hi all. I was wandering why Python implements its __new__ method as a static and not a class method? __new__ always accepts a cls parameter, which lead me to believe it was a class method. Also, implementing __new__ as a class method seems natural when thinking about __new__ as 'a method you call on a class to create a new instance of that class'. The difference between the two implementations is admittedly not that significant. In most cases __new__ would still need to have its cls parameter explicitly specified since it is most often called on a class and not on an instance. Having it implemented as a class method would allow this: class X: def __new__(cls, x): return super().__new__(x) instead of having to do this, as we do now: class X: def __new__(cls, x): return super().__new__(cls, x) Thinking about this some more - I guess having it as a static method allows you to use super() and still create a new 'subclass' when asked to instantiate a base class. Perhaps some sort of a factory pattern implementation like so: class Base: def __new__(cls, x): actual_class = get_class_for(x) return super().__new__(actual_class, x) If __new__ were a class method, the same logic could not be so easily implemented as you would need to call __new__ on actual_class, and so each actual_class would need to implement its own __new__ skipping its direct parent's __new__ - yuck... what a mess... Could that be the actual use case causing Guido to model __new__ as a static method? Or was it something else? I'm not suggesting this be changed, of course. I'm just curious as to whether I'm not fully understanding something in this part of Python. I generally find Python highly intuitive and it's not often something about it takes me by surprise like this. :-) Thanks in advance. Best regards, Jurko Gospodneti? P.S. Normally, I'd chalk this issue up under 'bike-shedding', but it came up while teaching others about Python and so does not feel right leaving it as 'because that's the way it is'. :-) From petertbrady at gmail.com Sat May 3 09:15:59 2014 From: petertbrady at gmail.com (ptb) Date: Sat, 3 May 2014 06:15:59 -0700 (PDT) Subject: Number of objects grows unbouned...Memory leak Message-ID: Hello all, I'm using Python 3.4 and am seeing the memory usage of my program grow unbounded. Here's a snippet of the loop driving the main computation opt_dict = {'interior':cons_dict['int_eq'],'lboundary':cons_dict['lboundary'], 'rboundary':cons_dict['rboundary'], 'material_props':{'conv':0.9,'diff':0.01}, 'file_ident':ident,'numeric':True,'file_set':files} # this produces roughly 25,000 elements args = product(zip(repeat(nx[-1]),ib_frac),nx,subs) for i,arg in enumerate(args): my_func(a=arg[0],b=arg[1],c=arg[2],**opt_dict) gc.collect() print(i,len(gc.get_objects())) A few lines of output: progress.... 0 84883 1 95842 2 106655 3 117576 4 128444 5 139309 6 150172 7 161015 8 171886 9 182739 10 193593 11 204455 12 215284 13 226102 14 236922 15 247804 16 258567 17 269386 18 280213 19 291032 20 301892 21 312701 22 323536 23 334391 24 345239 25 356076 26 366923 27 377701 28 388532 29 399321 30 410127 31 420917 32 431732 33 442489 34 453320 35 464147 36 475071 37 485593 38 496068 39 506568 40 517040 41 527531 42 538099 43 548658 44 559205 45 569732 46 580214 47 590655 48 601165 49 611656 50 622179 51 632645 52 643186 53 653654 54 664146 ... As you can see the number of objects keep growing and my memory usage grows proportionately. Also, my_func doesn't return any values but simply writes data to a file. I was under the impression that this sort of thing couldn't happen in Python. Can someone explain (1) how this is possible? and (2) how do I fix it? Hopefully that's enough information. Thanks for your help, Peter From icesti2014editor at gmail.com Sat May 3 09:51:02 2014 From: icesti2014editor at gmail.com (icesti2014editor at gmail.com) Date: Sat, 3 May 2014 06:51:02 -0700 (PDT) Subject: [Call for Paper - SCOPUS/ISI THOMSON] ICESTI 2014, September 10-13, 2014, Kuta Bali - Indonesia Message-ID: <184a15eb-e2ba-4f22-91ea-c833c640c724@googlegroups.com> International Conference on Engineering, Science and Technology Innovation (ICESTI 2014) 10-13 September 2014, Bali, Indonesia http://www.icesti.org/ Contact Email: icesti2014 at icesti.org Online Submission: http://www.icesti.org/online-submission ICESTI 2014 will provide a forum for accessing to the most up-to-date and authoritative knowledge from both industrial and academic worlds, sharing best practice in the field of Engineering, Science, and Technology towards sustainable development. The conference will provide an opportunity to highlight recent developments and to identify emerging and future areas of growth in these exciting fields. The first event of this conference series (ICESTI 2014) will be held in Bali, Indonesia, on 10-13 September 2014. ICESTI organizing committee are inviting submissions from scientists, academicians and industry practitioners worldwide. _____ CONTACT US Should you have any questions, please feel free to contact us: icesti2014 at icesti.org _____ IMPORTANT DATES Full paper submission : May 30, 2014 Notification of acceptance : June 21, 2014 Final paper submission and registration : June 21, 2014 - July 14, 2014 (latest date for early bird registration) Conference Event: September 10-13, 2014 _____ AREAS OF INTEREST Special sessions on specific service topics are also welcome. The topics of interest include, but are not limited to: Technology Innovation in Information Technology Computer Engineering Information Technology Multimedia Cloud Computing Artificial Intelligence Computer Vision and Machine Learning Technology Innovation in Energy Renewable Energy Energy Planning and Policy Energy Science and Technology Efficient Resources Utilization Climate Change Mitigation Technology Innovation in Electrical and Electronics Mechatronics and Robotics Power System and Smart Grid Distributed Generation Electrical Machines, Power Electronics and Drives Control and Automation Embedded System, Sensors, Actuators Technology Innovation in Mechanics and Materials Biotechnology and Nanotechnology Ceramics Science Physics and Optics Chemical Science and engineering Civil Engineering Mechanical Engineering Technology Innovation and Creative Economy Technopreneurship Creative Economy in Engineering Creative Art in Technology Technology Innovation in Industrial Management Supply Network, Operations & Engineering Management Operation Research Enterprise Resource Planning General Industry Studies _____ PUBLICATION After a careful refereeing process, all accepted papers will be published in one of the following international journals : Australian Journal of Basic and Applied Sciences (ISSN: 1991-8178, http://www.ajbasweb.com/). AJBAS is indexed by ISI-Thomson Reuters. Advances in Natural and Applied Sciences (ISSN: 1995-0772, http://www.aensiweb.com/anas.html). ANAS is indexed by Elsevier (SCOPUS). Applied Mechanics and Materials (AMM) (ISSN: 1660-9336), http://www.ttp.net/1660-9336.html. AMM is indexed by Elsevier (SCOPUS). ARPN-Journal of Engineering and Applied Sciences (ISSN: 1819-6608, http://www.arpnjournals.com/jeas/). JEAS is indexed by Elsevier (SCOPUS). From petertbrady at gmail.com Sat May 3 10:40:14 2014 From: petertbrady at gmail.com (ptb) Date: Sat, 3 May 2014 07:40:14 -0700 (PDT) Subject: Number of objects grows unbouned...Memory leak In-Reply-To: References: Message-ID: Turns out one of the libraries I am using has a cache system. If I shut if off then my problem goes away... On Saturday, May 3, 2014 7:15:59 AM UTC-6, ptb wrote: > Hello all, > > > > I'm using Python 3.4 and am seeing the memory usage of my program grow unbounded. Here's a snippet of the loop driving the main computation > > > > opt_dict = {'interior':cons_dict['int_eq'],'lboundary':cons_dict['lboundary'], > > 'rboundary':cons_dict['rboundary'], > > 'material_props':{'conv':0.9,'diff':0.01}, > > 'file_ident':ident,'numeric':True,'file_set':files} > > > > # this produces roughly 25,000 elements > > args = product(zip(repeat(nx[-1]),ib_frac),nx,subs) > > > > for i,arg in enumerate(args): > > my_func(a=arg[0],b=arg[1],c=arg[2],**opt_dict) > > gc.collect() > > print(i,len(gc.get_objects())) > > > > A few lines of output: > > > > progress.... > > 0 84883 > > 1 95842 > > 2 106655 > > 3 117576 > > 4 128444 > > 5 139309 > > 6 150172 > > 7 161015 > > 8 171886 > > 9 182739 > > 10 193593 > > 11 204455 > > 12 215284 > > 13 226102 > > 14 236922 > > 15 247804 > > 16 258567 > > 17 269386 > > 18 280213 > > 19 291032 > > 20 301892 > > 21 312701 > > 22 323536 > > 23 334391 > > 24 345239 > > 25 356076 > > 26 366923 > > 27 377701 > > 28 388532 > > 29 399321 > > 30 410127 > > 31 420917 > > 32 431732 > > 33 442489 > > 34 453320 > > 35 464147 > > 36 475071 > > 37 485593 > > 38 496068 > > 39 506568 > > 40 517040 > > 41 527531 > > 42 538099 > > 43 548658 > > 44 559205 > > 45 569732 > > 46 580214 > > 47 590655 > > 48 601165 > > 49 611656 > > 50 622179 > > 51 632645 > > 52 643186 > > 53 653654 > > 54 664146 > > ... > > > > As you can see the number of objects keep growing and my memory usage grows proportionately. Also, my_func doesn't return any values but simply writes data to a file. > > > > I was under the impression that this sort of thing couldn't happen in Python. Can someone explain (1) how this is possible? and (2) how do I fix it? > > > > Hopefully that's enough information. > > > > Thanks for your help, > > Peter From steve+comp.lang.python at pearwood.info Sat May 3 11:12:17 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 May 2014 15:12:17 GMT Subject: Why has __new__ been implemented as a static method? References: Message-ID: <53650751$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sat, 03 May 2014 12:37:24 +0200, Jurko Gospodneti? wrote: > Hi all. > > I was wandering why Python implements its __new__ method as a static > and not a class method? Have you read Guido's tutorial on it? https://www.python.org/download/releases/2.2.3/descrintro [quote] Factoid: __new__ is a static method, not a class method. I initially thought it would have to be a class method, and that's why I added the classmethod primitive. Unfortunately, with class methods, upcalls don't work right in this case, so I had to make it a static method with an explicit class as its first argument. [end quote] I'm not entirely sure what he means by "upcalls", but I believe it means to call the method further up (that is, closer to the base) of the inheritance tree. -- Steven D'Aprano http://import-that.dreamwidth.org/ From denismfmcmahon at gmail.com Sat May 3 11:50:40 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 3 May 2014 15:50:40 +0000 (UTC) Subject: [Call for Paper - SCOPUS/ISI THOMSON] ICESTI 2014, September 10-13, 2014, Kuta Bali - Indonesia References: <184a15eb-e2ba-4f22-91ea-c833c640c724@googlegroups.com> Message-ID: On Sat, 03 May 2014 06:51:02 -0700, icesti2014editor wrote: > sharing best practice in the field of Engineering, Science, and > Technology towards sustainable development. > The first event of this conference series (ICESTI 2014) will be held in > Bali, Indonesia Let's all fly to Bali in the name of sustainability and preserving the planet, and damn the CO2 created by doing so. -- Denis McMahon, denismfmcmahon at gmail.com From steve+comp.lang.python at pearwood.info Sat May 3 13:23:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 May 2014 17:23:01 GMT Subject: [Call for Paper - SCOPUS/ISI THOMSON] ICESTI 2014, September 10-13, 2014, Kuta Bali - Indonesia References: <184a15eb-e2ba-4f22-91ea-c833c640c724@googlegroups.com> Message-ID: <536525f5$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sat, 03 May 2014 15:50:40 +0000, Denis McMahon wrote: > On Sat, 03 May 2014 06:51:02 -0700, icesti2014editor wrote: > >> sharing best practice in the field of Engineering, Science, and >> Technology towards sustainable development. > >> The first event of this conference series (ICESTI 2014) will be held in >> Bali, Indonesia > > Let's all fly to Bali in the name of sustainability and preserving the > planet, and damn the CO2 created by doing so. Pennywise and pound-foolish perhaps? If spending a few thousand tonnes of CO2 enables the saving of a few million tonnes, I think that would be well worth it. Of course, Bali happens to be one of the premier holiday destinations in the world. Presumably that's completely a coincidence... -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sat May 3 13:59:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 4 May 2014 03:59:53 +1000 Subject: [Call for Paper - SCOPUS/ISI THOMSON] ICESTI 2014, September 10-13, 2014, Kuta Bali - Indonesia In-Reply-To: <536525f5$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <184a15eb-e2ba-4f22-91ea-c833c640c724@googlegroups.com> <536525f5$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 4, 2014 at 3:23 AM, Steven D'Aprano wrote: > On Sat, 03 May 2014 15:50:40 +0000, Denis McMahon wrote: > >> On Sat, 03 May 2014 06:51:02 -0700, icesti2014editor wrote: >> >>> sharing best practice in the field of Engineering, Science, and >>> Technology towards sustainable development. >> >>> The first event of this conference series (ICESTI 2014) will be held in >>> Bali, Indonesia >> >> Let's all fly to Bali in the name of sustainability and preserving the >> planet, and damn the CO2 created by doing so. > > Pennywise and pound-foolish perhaps? If spending a few thousand tonnes of > CO2 enables the saving of a few million tonnes, I think that would be > well worth it. And if setting up a Mailman list to discuss the exact same content would be as effective as a conference, then it would be anything but. We can't know. What we *do* know is that putting the word "sustainable" into a proposal makes it a lot easier for people to get funding. Even more so, further down, "Climate Change Mitigation". For better or for worse, that's how a lot of the world allocates money. By the way, thank you both for saying "CO2" and not "carbon". If I had a black balloon for every time someone talked about how much carbon was created in such-and-such, I could make my own global warming advert... ChrisA From tjreedy at udel.edu Sat May 3 16:32:37 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 03 May 2014 16:32:37 -0400 Subject: Why has __new__ been implemented as a static method? In-Reply-To: References: Message-ID: On 5/3/2014 6:37 AM, Jurko Gospodneti? wrote: > Hi all. > > I was wandering why Python implements its __new__ method as a static > and not a class method? For a technical internal reason that Guido and maybe others have explained on pydev (more than once). I forget the details partly because I do not care beyond knowing that there is a reason. You might be able to find something by searching the pydev archives at gmane.org for '__new__ static method'. In other words, Guido knows that it 'should' be a class method, if it could be. > Normally, I'd chalk this issue up under 'bike-shedding', but it came > up while teaching others about Python and so does not feel right leaving > it as 'because that's the way it is'. :-) 'Because that is how it has to be for technical internal reasons beyond the scope of my teaching.' -- Terry Jan Reedy From tjreedy at udel.edu Sat May 3 16:47:00 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 03 May 2014 16:47:00 -0400 Subject: [Call for Paper - SCOPUS/ISI THOMSON] ICESTI 2014, September 10-13, 2014, Kuta Bali - Indonesia In-Reply-To: <536525f5$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <184a15eb-e2ba-4f22-91ea-c833c640c724@googlegroups.com> <536525f5$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/3/2014 1:23 PM, Steven D'Aprano wrote: > On Sat, 03 May 2014 15:50:40 +0000, Denis McMahon wrote: > >> On Sat, 03 May 2014 06:51:02 -0700, icesti2014editor wrote: >> >>> sharing best practice in the field of Engineering, Science, and >>> Technology towards sustainable development. >> >>> The first event of this conference series (ICESTI 2014) will be held in >>> Bali, Indonesia >> >> Let's all fly to Bali in the name of sustainability and preserving the >> planet, and damn the CO2 created by doing so. > > Pennywise and pound-foolish perhaps? If spending a few thousand tonnes of > CO2 enables the saving of a few million tonnes, I think that would be > well worth it. > > Of course, Bali happens to be one of the premier holiday destinations in > the world. Presumably that's completely a coincidence... If this had been held for moderation and I were the one responding to it, I would have discarded it as commercial spam. Many such conferences detached from professional societies are profit-seeking enterprises. I consider both the cross-posting and location as evidence that this might be true of this conference. -- Terry Jan Reedy From mikejohnryan08 at gmail.com Sat May 3 17:47:42 2014 From: mikejohnryan08 at gmail.com (mikejohnryan08 at gmail.com) Date: Sat, 3 May 2014 14:47:42 -0700 (PDT) Subject: Python Image Registration and Cropping? Message-ID: Hello, Is there a Python tool or function that can register two images together (line them up visually), and then crop them to the common overlap area? I'm assuming this can probably be done with Python Imaging Library but I'm not very familiar with it yet. Any help or advice is appreciated! Thanks! From breamoreboy at yahoo.co.uk Sat May 3 18:04:14 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 03 May 2014 23:04:14 +0100 Subject: Python Image Registration and Cropping? In-Reply-To: References: Message-ID: On 03/05/2014 22:47, mikejohnryan08 at gmail.com wrote: > Hello, > > Is there a Python tool or function that can register two images together (line them up visually), and then crop them to the common overlap area? I'm assuming this can probably be done with Python Imaging Library but I'm not very familiar with it yet. > > Any help or advice is appreciated! > > Thanks! > Sorry I can't help directly but I do know that PIL has been forked into Pillow see https://pypi.python.org/pypi/Pillow/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From missive at hotmail.com Sat May 3 18:28:34 2014 From: missive at hotmail.com (Lee Harr) Date: Sun, 4 May 2014 02:58:34 +0430 Subject: [ANNC] pybotwar-0.9 : now using pybox2d-2.3b0 Message-ID: pybotwar is a fun and educational game where players write computer programs to control simulated robots. http://pybotwar.googlecode.com/ The focus of this release is updating to use the latest available pybox2d version: 2.3b0 pybotwar uses pybox2d for the physical simulation. It can be run in text-only mode -- useful for longer tournaments -- or use pyqt or pygame for a graphical interface and visualization of the action. pybotwar is released under GPLv3. Downloads: ??? https://drive.google.com/folderview?id=0B63eegq9QFJmcXdSMEtvc0JFZTQ ??? (requires javascript to download...) Changes in pybotwar-0.9: ??? - pybox2d-2.3b0 is now the required version From greg.ewing at canterbury.ac.nz Sat May 3 19:21:53 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 04 May 2014 11:21:53 +1200 Subject: Why has __new__ been implemented as a static method? In-Reply-To: <53650751$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <53650751$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I'm not entirely sure what he means by "upcalls", but I believe it means > to call the method further up (that is, closer to the base) of the > inheritance tree. I think it means this: def __new__(cls): MyBaseClass.__new__(cls) which wouldn't work with a class method, because MyBaseClass.__new__ would give a *bound* method rather than an unbound one. Python 3's version of super() seems to work with class methods, but Python 2's doesn't (or at least I couldn't get it to work in a brief test). Also, I don't think super() existed at all when __new__ was invented. -- Greg From steve+comp.lang.python at pearwood.info Sat May 3 23:37:21 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 May 2014 03:37:21 GMT Subject: Why has __new__ been implemented as a static method? References: <53650751$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5365b5f1$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 04 May 2014 11:21:53 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> I'm not entirely sure what he means by "upcalls", but I believe it >> means to call the method further up (that is, closer to the base) of >> the inheritance tree. > > I think it means this: > > def __new__(cls): > MyBaseClass.__new__(cls) > > which wouldn't work with a class method, because MyBaseClass.__new__ > would give a *bound* method rather than an unbound one. If it were a class method, you would call it by MyBaseClass.__new__() rather than explicitly providing the cls argument. > Python 3's version of super() seems to work with class methods, but > Python 2's doesn't (or at least I couldn't get it to work in a brief > test). Works for me. Perhaps you got your super() call wrong? py> class MyDict(dict): ... @classmethod ... def fromkeys(cls, *args, **kwargs): ... print "Calling overridden method." ... return super(MyDict, cls).fromkeys(*args, **kwargs) ... py> MyDict.fromkeys('abc') Calling overridden method. {'a': None, 'c': None, 'b': None} py> MyDict().fromkeys('abc') Calling overridden method. {'a': None, 'c': None, 'b': None} > Also, I don't think super() existed at all when __new__ was > invented. Well, I don't know about that, but super was introduced in the same version as new-style classes with __new__. -- Steven D'Aprano http://import-that.dreamwidth.org/ From greg.ewing at canterbury.ac.nz Sun May 4 04:03:35 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 04 May 2014 20:03:35 +1200 Subject: Why has __new__ been implemented as a static method? In-Reply-To: <5365b5f1$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <53650751$0$29965$c3e8da3$5496439d@news.astraweb.com> <5365b5f1$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > If it were a class method, you would call it by MyBaseClass.__new__() > rather than explicitly providing the cls argument. But that wouldn't be any good, because the base __new__ needs to receive the actual class being instantiated, not the class that the __new__ method belongs to. -- Greg From mdickinson at enthought.com Sun May 4 06:53:06 2014 From: mdickinson at enthought.com (Mark Dickinson) Date: Sun, 4 May 2014 10:53:06 +0000 (UTC) Subject: Bug in Decimal?? References: <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com> Message-ID: On Tue, 29 Apr 2014 19:37:17 -0700, pleasedontspam wrote: > Hello, I believe I found a bug in the Decimal library. The natural logarithm > results seem to be off in a certain range, as compared with Wolfram Alpha. I had a quick look: this isn't a bug - it's just the result of propagation of the error in "partial" to "final". In more detail: we've got a working precision of 2016 significant figures. For any small x, we have (1 + x) / (1 - x) = 1 + 2x + 2x^2 + 2x^3 + .... For your value of x, `Decimal('1e-1007'), we've got enough precision to store 1 + 2x + 2x^2 exactly, but that's all. So partial has an absolute error of around 2x^3, or 2e-3021. And since the derivative of the natural log function is almost exactly 1 at the point we're interested in, we expect the absolute error in the output to be close to 2e-3021, too. And that's *precisely* what you're seeing: the Decimal module is giving you a result that's exactly `Decimal('2e-1007') - Decimal('1.3e-3021')`, while the result you were expecting is `Decimal('2e-1007') + Decimal('0.7e-3021')`. A difference of exactly `Decimal('2e-3021')`, as expected. -- Mark From draganov93 at gmail.com Sun May 4 07:53:12 2014 From: draganov93 at gmail.com (draganov93 at gmail.com) Date: Sun, 4 May 2014 04:53:12 -0700 (PDT) Subject: tkinter: invisible PanedWindow "sashes" on OS X In-Reply-To: References: Message-ID: <4c525a66-dd14-48a7-92f0-605309da1523@googlegroups.com> Hi to all, I have a similar problem. I have a PanedWindow with a lot of checkboxes in it and i want to make the checkboxes non-resizable.How can i achieve this? From davea at davea.name Sun May 4 09:24:55 2014 From: davea at davea.name (Dave Angel) Date: Sun, 4 May 2014 09:24:55 -0400 (EDT) Subject: Python Image Registration and Cropping? References: Message-ID: mikejohnryan08 at gmail.com Wrote in message: > Hello, > > Is there a Python tool or function that can register two images together (line them up visually), and then crop them to the common overlap area? I'm assuming this can probably be done with Python Imaging Library but I'm not very familiar with it yet. > > Any help or advice is appreciated! > > Thanks! > Without some context I'd call the problem intractable. I've done such things using Photoshop to insert elements of one image into another. But even describing an algorithm is difficult, never mind trying to code it. If I had such a challenge, I'd probably use Pillow, but not till I knew what subset I was solving. 1) you had an image, saved in lossless tiff, and it was copied twice, each was edited and cropped, and the original lost. Analyze the two remaining tiff, and try to reconstruct the largest common subset. 2) You have two faxes from filled in versions of the same original form, and you're trying to extract just the handwriting portions of each. Very tricky, because not only exposure differences, but registration will vary over the surface, because of moisture and irregular feed from multiple rollers. 3) You have two jpegs, created from same master, but one has been scaled, rotated, cropped, and color corrected. Even without color correction, one was saved at a different quality setting, or prepared with a different raw converter. 4) You have two images taken with the same camera, on a tripod, within a minute of each other, with no visible difference of cloud cover, with camera set on full manual, without auto focus. The were converted with the same raw converter, ... etc. -- DaveA From steve+comp.lang.python at pearwood.info Sun May 4 10:16:00 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 May 2014 14:16:00 GMT Subject: Why has __new__ been implemented as a static method? References: <53650751$0$29965$c3e8da3$5496439d@news.astraweb.com> <5365b5f1$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53664b9f$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 04 May 2014 20:03:35 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> If it were a class method, you would call it by MyBaseClass.__new__() >> rather than explicitly providing the cls argument. > > But that wouldn't be any good, because the base __new__ needs to receive > the actual class being instantiated, not the class that the __new__ > method belongs to. Which is exactly what method descriptors -- whether instance methods or class descriptors -- can do. Here's an example, using Python 2.7: class MyDict(dict): @classmethod def fromkeys(cls, *args, **kwargs): print "Called from", cls return super(MyDict, cls).fromkeys(*args, **kwargs) class AnotherDict(MyDict): pass And in use: py> MyDict.fromkeys('abc') Called from {'a': None, 'c': None, 'b': None} py> AnotherDict().fromkeys('xyz') Called from {'y': None, 'x': None, 'z': None} In both cases, MyDict's __new__ method receives the class doing the calling, not the class where the method is defined. Whatever the difficulty is with __new__, it isn't something obvious. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ian.g.kelly at gmail.com Sun May 4 11:51:00 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 4 May 2014 09:51:00 -0600 Subject: Python Image Registration and Cropping? In-Reply-To: References: Message-ID: On Sun, May 4, 2014 at 7:24 AM, Dave Angel wrote: > mikejohnryan08 at gmail.com Wrote in message: >> Hello, >> >> Is there a Python tool or function that can register two images together (line them up visually), and then crop them to the common overlap area? I'm assuming this can probably be done with Python Imaging Library but I'm not very familiar with it yet. >> >> Any help or advice is appreciated! >> >> Thanks! >> > > Without some context I'd call the problem intractable. I've done > such things using Photoshop to insert elements of one image into > another. But even describing an algorithm is difficult, never > mind trying to code it. Well, fortunately there are known algorithms already: http://en.wikipedia.org/wiki/Image_registration > If I had such a challenge, I'd probably use Pillow, but not till > I knew what subset I was solving. I don't think Pillow has any support for registration. I'd probably start by looking for Python bindings of a library that does handle it, like ITK. Searching for "itk python" turns up a number of results. From sg552 at hotmail.co.uk Sun May 4 12:24:11 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Sun, 04 May 2014 17:24:11 +0100 Subject: Why has __new__ been implemented as a static method? In-Reply-To: <53664b9f$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <53650751$0$29965$c3e8da3$5496439d@news.astraweb.com> <5365b5f1$0$29965$c3e8da3$5496439d@news.astraweb.com> <53664b9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/05/2014 15:16, Steven D'Aprano wrote: > On Sun, 04 May 2014 20:03:35 +1200, Gregory Ewing wrote: > >> Steven D'Aprano wrote: >>> If it were a class method, you would call it by MyBaseClass.__new__() >>> rather than explicitly providing the cls argument. >> >> But that wouldn't be any good, because the base __new__ needs to receive >> the actual class being instantiated, not the class that the __new__ >> method belongs to. > > > Which is exactly what method descriptors -- whether instance methods or > class descriptors -- can do. Here's an example, using Python 2.7: > > class MyDict(dict): > @classmethod > def fromkeys(cls, *args, **kwargs): > print "Called from", cls > return super(MyDict, cls).fromkeys(*args, **kwargs) > > class AnotherDict(MyDict): > pass > > > And in use: > > py> MyDict.fromkeys('abc') > Called from > {'a': None, 'c': None, 'b': None} > py> AnotherDict().fromkeys('xyz') > Called from > {'y': None, 'x': None, 'z': None} > > > In both cases, MyDict's __new__ method receives the class doing the > calling, not the class where the method is defined. Yes, when a classmethod bound to a subclass or an instance is called. But this is irrelevant to Gregory's point: On 04/05/2014 04:37, Steven D'Aprano wrote: > On Sun, 04 May 2014 11:21:53 +1200, Gregory Ewing wrote: >> Steven D'Aprano wrote: >>> I'm not entirely sure what he means by "upcalls", but I believe it >>> means to call the method further up (that is, closer to the base) of >>> the inheritance tree. >> >> I think it means this: >> >> def __new__(cls): >> MyBaseClass.__new__(cls) >> >> which wouldn't work with a class method, because MyBaseClass.__new__ >> would give a *bound* method rather than an unbound one. > > If it were a class method, you would call it by MyBaseClass.__new__() > rather than explicitly providing the cls argument. The relevant behaviour is this: >>> class C: @classmethod def m(cls): print("Called from", cls) >>> class D(C): @classmethod def m(cls): C.m() >>> C.m() Called from >>> D.m() Called from If __new__ were a classmethod, then a call to MyBaseClass.__new__() within the body of MySubClass.__new__ would pass MyBaseClass to the underlying function, not the MySubClass. This means that class MySubClass(MyBaseClass): def __new__(cls): return MyBaseClass.__new__() would fail, since it would return an instance of MyBaseClass rather than MySubClass. From ian.g.kelly at gmail.com Sun May 4 13:05:33 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 4 May 2014 11:05:33 -0600 Subject: Why has __new__ been implemented as a static method? In-Reply-To: <53664b9f$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <53650751$0$29965$c3e8da3$5496439d@news.astraweb.com> <5365b5f1$0$29965$c3e8da3$5496439d@news.astraweb.com> <53664b9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 4, 2014 at 8:16 AM, Steven D'Aprano wrote: > On Sun, 04 May 2014 20:03:35 +1200, Gregory Ewing wrote: > >> Steven D'Aprano wrote: >>> If it were a class method, you would call it by MyBaseClass.__new__() >>> rather than explicitly providing the cls argument. >> >> But that wouldn't be any good, because the base __new__ needs to receive >> the actual class being instantiated, not the class that the __new__ >> method belongs to. > > > Which is exactly what method descriptors -- whether instance methods or > class descriptors -- can do. Here's an example, using Python 2.7: > > class MyDict(dict): > @classmethod > def fromkeys(cls, *args, **kwargs): > print "Called from", cls > return super(MyDict, cls).fromkeys(*args, **kwargs) > > class AnotherDict(MyDict): > pass > > > And in use: > > py> MyDict.fromkeys('abc') > Called from > {'a': None, 'c': None, 'b': None} > py> AnotherDict().fromkeys('xyz') > Called from > {'y': None, 'x': None, 'z': None} > > > In both cases, MyDict's __new__ method receives the class doing the > calling, not the class where the method is defined. > > Whatever the difficulty is with __new__, it isn't something obvious. You cheated on two counts here. First, you're using super; I think Guido's comment about "upcalls" in the link you posted earlier was in reference to calls that explicitly name the name parent class, i.e. "dict.fromkeys()", not "super(MyDict, cls).fromkeys()". Second, you didn't override the method in AnotherDict, so "MyDict.fromkeys" and "AnotherDict.fromkeys" refer to the same method, the only difference being in which class is passed to the descriptor when it is accessed. Compare to this: class MyDict(dict): @classmethod def fromkeys(cls, *args, **kwargs): print "MyDict Called from", cls return dict.fromkeys(*args, **kwargs) class AnotherDict(MyDict): @classmethod def fromkeys(cls, *args, **kwargs): print "AnotherDict Called from", cls return MyDict.fromkeys(*args, **kwargs) >>> MyDict.fromkeys('abc') MyDict Called from {'a': None, 'c': None, 'b': None} >>> AnotherDict.fromkeys('abc') AnotherDict Called from MyDict Called from {'a': None, 'c': None, 'b': None} From mbg1708 at planetmail.com Sun May 4 15:51:01 2014 From: mbg1708 at planetmail.com (mbg1708 at planetmail.com) Date: Sun, 4 May 2014 12:51:01 -0700 (PDT) Subject: Glade on Windows using Python In-Reply-To: <62715f8a-8e45-4150-a3c9-ca1183fc6abb@googlegroups.com> References: <62715f8a-8e45-4150-a3c9-ca1183fc6abb@googlegroups.com> Message-ID: On Tuesday, April 22, 2014 7:08:29 PM UTC-4, mbg... at planetmail.com wrote: > Using Windows 8.1 Update. > > I've loaded ActiveState python (version 2.7) --- installed OK. > > I don't need Glade, but I do want to use some Glade XML and run the python application. > > To run a Glade application this needs: > > > > from gi.repository import Gtk > > > > gi.repository is not available to import. > > > > Where can I find gi.repository?....all searches to date have come up empty! > > > > Mary So...it turns out that Glade support for Python 2.7 is pretty difficult. I ended up rewriting the whole thing using Tkinter and ttk.Treeview. It would have been good to reuse the Glade XML...less code, better looking, etc. etc. Ah well. Mary From torriem at gmail.com Sun May 4 19:27:05 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 04 May 2014 17:27:05 -0600 Subject: Glade on Windows using Python In-Reply-To: References: <62715f8a-8e45-4150-a3c9-ca1183fc6abb@googlegroups.com> Message-ID: <5366CCC9.503@gmail.com> On 05/04/2014 01:51 PM, mbg1708 at planetmail.com wrote: > So...it turns out that Glade support for Python 2.7 is pretty difficult. > I ended up rewriting the whole thing using Tkinter and ttk.Treeview. > It would have been good to reuse the Glade XML...less code, better looking, etc. etc. Both Gtk2 and Gtk3 are available for Windows. Glade XML is typically used on Gtk2 by the GtkBuilder class (http://www.pygtk.org/pygtk2reference/class-gtkbuilder.html). Gtk3 uses http://python-gtk-3-tutorial.readthedocs.org/en/latest/builder.html. The code you had in your OP was for Gtk3. There are up-to-date packages of Gtk3 bindings for Python on Windows here: http://sourceforge.net/projects/pygobjectwin32/files/ I didn't see your original post a couple of weeks ago, which is too bad. I'm not sure Gtk is better-looking on Windows. It's always been the ugly step-child there compared to Linux. Tkinter has a Windows native look and feel, so there's no reason to not use Tkinter if it suits your project: https://docs.python.org/3/library/tkinter.ttk.html From mikejohnryan08 at gmail.com Sun May 4 20:56:11 2014 From: mikejohnryan08 at gmail.com (mikejohnryan08 at gmail.com) Date: Sun, 4 May 2014 17:56:11 -0700 (PDT) Subject: Python Image Registration and Cropping? In-Reply-To: References: Message-ID: <9886ebf9-ba2c-48dc-aed0-81437c68faf2@googlegroups.com> On Sunday, May 4, 2014 11:51:00 AM UTC-4, Ian wrote: > On Sun, May 4, 2014 at 7:24 AM, Dave Angel wrote: > > > mikejohnryan08 at gmail.com Wrote in message: > > >> Hello, > > >> > > >> Is there a Python tool or function that can register two images together (line them up visually), and then crop them to the common overlap area? I'm assuming this can probably be done with Python Imaging Library but I'm not very familiar with it yet. > > >> > > >> Any help or advice is appreciated! > > >> > > >> Thanks! > > >> > > > > > > Without some context I'd call the problem intractable. I've done > > > such things using Photoshop to insert elements of one image into > > > another. But even describing an algorithm is difficult, never > > > mind trying to code it. > > > > Well, fortunately there are known algorithms already: > > http://en.wikipedia.org/wiki/Image_registration > > > > > If I had such a challenge, I'd probably use Pillow, but not till > > > I knew what subset I was solving. > > > > I don't think Pillow has any support for registration. I'd probably > > start by looking for Python bindings of a library that does handle it, > > like ITK. Searching for "itk python" turns up a number of results. Thanks for the responses. More specifically, my scenario is that I have many aerial image stereo-pairs, and need to register each pair together and crop them to their overlapping area. The output should produce two images with the same field-of-view; and the only difference will be the perspective. Still searching for a suitable module that can easily do this sort of thing. From larry at hastings.org Mon May 5 07:08:41 2014 From: larry at hastings.org (Larry Hastings) Date: Mon, 05 May 2014 04:08:41 -0700 Subject: [RELEASED] Python 3.4.1rc1 Message-ID: <53677139.6010008@hastings.org> On behalf of the Python development community and the Python 3.4 release team, I'm pleased to announce the availability of Python 3.4.1rc1. Python 3.4.1rc1 has over three hundred bugfixes and other improvements over 3.4.0. One notable change: the version of OpenSSL bundled with the Windows installer no longer has the "HeartBleed" vulnerability. You can download it here: https://www.python.org/download/releases/3.4.1 One note: the "topics" data file for the pydoc is broken in this release. This means the pydoc command and the built-in "help" will fail on some topics. //arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From acewebacademy at gmail.com Mon May 5 08:53:29 2014 From: acewebacademy at gmail.com (AWA Hyd) Date: Mon, 5 May 2014 05:53:29 -0700 (PDT) Subject: Job Oriented Web Designing Course in Hyderabad Message-ID: <012f64ad-ecfe-4254-adcc-b26e8b9c1c79@googlegroups.com> The concept of education has changed a lot in today's world where everything has been approached with a practical sense. The concept of education for the sake of knowledge has become a thing of past. Now the first and foremost aim of education is to grab good opportunities and thus to make a safe and secured future. When you look from this point of view, The Web Designing Course offered by Ace Web Academy in Hyderabad considered one of the best courses. There is a huge demand for web designers and it will certainly increase in the near future. India has become one of the favorite destinations for outsourcing web designing works by the individuals and companies in the developed countries. Being one of the most important IT hubs in India, Hyderabad houses many web designing companies and hence has a prominent place in the IT map. Now you will know why more and more youngsters prefer to pursue web designing course in Hyderabad. Ace Web Academy is an associate of Ace Dezines, one of the global leaders in Web designing and programming. Industry professionals with vast working experience are taking classes. Latest technology and the sophisticated equipments will certainly update you with the changes in technology. Professional approach and career orientation programs will certainly help you in your future endeavors. Job opportunities for bright students with Ace Web Designs. Many other opportunities with associated companies. Highly valued course completion certificate respected by many service providers. These are a few reasons why Ace Web Academy has become one of the most favorite Institutes offering Web Designing Course in Hyderabad. There are many other reasons which you will understand by experiencing. Contact us at the earliest as the new batches are starting soon. New batches are about to start and contact us immediately: Contact Person: Sravanthi Ph: 040-64586626 / 7660-966-660 Email us @ hello at acewebacademy.com Visit: http://www.acewebacademy.com/ From christcadet99 at yahoo.com Mon May 5 11:18:49 2014 From: christcadet99 at yahoo.com (Joshua Knights) Date: Mon, 5 May 2014 11:18:49 -0400 Subject: Joining centos 6.5 member Domain Controller to an existing Windows Domain Message-ID: Here is my Issue and I think it may be a python path bug? This is my Error: /root/samba-master/bin/samba-tool domain join AAF.ECPI DC -Uadministrator --realm=AAF.ECPI I get the following Error: Traceback (most recent call last): File "/root/samba-master/bin/samba-tool", line 33, in from samba.netcmd.main import cmd_sambatool ImportError: No module named samba.netcmd.main In my research somebody said: to export the PYTHONPATH and to change it to the correct path of the netcmd command. Someone said this fixed the problem for them, but it did not fix the problem for me!! Below is my Sinereo: I am running a CentosOS Release 6.5 (Final) Kernel Linux 2.632-431.11.2.el6.x86_64 GNOME 2.28.2 Both my Domain and Relm are AAF.ECPI; My Directory Path for Samba Version is /root/samba-master/ I did a Yum Update before starting anything Then I did a: yum install glibc glibc-devel gcc python* libacl-devel krb5-workstation krb5-libs pam_krb5 and then I removed the older samba packages before starting via the command: yum remove samba-winbind-client samba-common samba-client Then I installed git core using the command: yum install git-core Then I downloaded Samba with the following command: git clone git://git.samba.org/samba.git samba-master Then I installed the additional openldap-devel Library then I did the ./configure --enable-debug --enable-selftest then initiated the make command Then I successfully did a: kinit administrator and it prompted me for the Administrator Password of the Windows Domain Administrator. Then I ran klist and it successfully showed me I had a security token from the Windows Primary Domain Controller. Where I am currently Stuck is when I run the: /root/samba-master/bin/samba-tool domain join AAF.ECPI DC -Uadministrator --realm=AAF.ECPI I get the following Error: Traceback (most recent call last): File "/root/samba-master/bin/samba-tool", line 33, in from samba.netcmd.main import cmd_sambatool ImportError: No module named samba.netcmd.main When I do a find / - name samba.netcmd.main It pulls up: NOTHING!! If I pull up : find / -name netcmd I get: /root/samba-master/python/samba/netcmd /root/samba-master/bin/python/samba/netcmd /root/samba-master/bin/default/python/samba/netcmd In my research somebody said: to export the PYTHONPATH and to change it to the correct path of the netcmd command. if I wanted to fix it permanently then to update my bash.rc file. In other words Tell my samba tool where to look, and this look is only temporary till I close my terminal. Placing the command in the bash.rc file will run this script every time I open my terminal. Well, I tried all 3 and none of them worked. --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at freeranger.com Mon May 5 11:33:38 2014 From: chris at freeranger.com (chris at freeranger.com) Date: Mon, 5 May 2014 08:33:38 -0700 (PDT) Subject: socket client and server in one application? Message-ID: <2db82378-5bb3-4a5c-b9e0-7ccb29760a06@googlegroups.com> I have a python script that uses a serial port to read data from an xbee radio and it delivers the data to a socket server. Now I need to retrieve the data from a socket client so I can send data out on the common serial port. I think I need a combination of threads, queues, socket client and sever. Anyone have ideas about how I might frame this out? Thanks in advance, Chris. From marko at pacujo.net Mon May 5 11:38:32 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 05 May 2014 18:38:32 +0300 Subject: socket client and server in one application? References: <2db82378-5bb3-4a5c-b9e0-7ccb29760a06@googlegroups.com> Message-ID: <877g60z153.fsf@elektro.pacujo.net> chris at freeranger.com: > I think I need a combination of threads, queues, socket client and > se[r]ver. Yes, although I'd stay away from threads if I could. > Anyone have ideas about how I might frame this out? Take a look at asyncio. It might have everything you could wish for. Marko From dihedral88888 at gmail.com Mon May 5 14:26:19 2014 From: dihedral88888 at gmail.com (CHIN Dihedral) Date: Mon, 5 May 2014 11:26:19 -0700 (PDT) Subject: socket client and server in one application? In-Reply-To: <2db82378-5bb3-4a5c-b9e0-7ccb29760a06@googlegroups.com> References: <2db82378-5bb3-4a5c-b9e0-7ccb29760a06@googlegroups.com> Message-ID: On Monday, May 5, 2014 11:33:38 PM UTC+8, ch... at freeranger.com wrote: > I have a python script that uses a serial port to read data from an xbee radio and it delivers the data to a socket server. > > > > Now I need to retrieve the data from a socket client so I can send data out on the common serial port. > > > > I think I need a combination of threads, queues, socket client and sever. > > > > Anyone have ideas about how I might frame this out? > > > > Thanks in advance, > > Chris. I did this kind of projects in 1999-2002 for taxie call out services in object pascal from Borland in paid jobs. In python, check the urlib. From invalid at invalid.invalid Mon May 5 15:47:04 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 5 May 2014 19:47:04 +0000 (UTC) Subject: socket client and server in one application? References: <2db82378-5bb3-4a5c-b9e0-7ccb29760a06@googlegroups.com> Message-ID: On 2014-05-05, chris at freeranger.com wrote: > I have a python script that uses a serial port to read data from an > xbee radio and it delivers the data to a socket server. Now I need to > retrieve the data from a socket client so I can send data out on the > common serial port. > > I think I need a combination of threads, queues, socket client and > sever. You could use either threads or select/poll. They would all work fine. -- Grant Edwards grant.b.edwards Yow! Now I'm concentrating at on a specific tank battle gmail.com toward the end of World War II! From invalid at invalid.invalid Mon May 5 15:51:15 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 5 May 2014 19:51:15 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? Message-ID: I'm working on a Python app that receives an e-mail message via SMTP, does some trivial processing on it, and forwards it to another SMTP server. I'd like to do the polite thing and add a "Received:" header, but I can't figure out how to get Python's email module to add it in the correct place. It always ends up at the "bottom" of the headers below From: To: etc. It's supposed to go at the above all the Received: headers that where there when I received it. -- Grant Edwards grant.b.edwards Yow! With YOU, I can be at MYSELF ... We don't NEED gmail.com Dan Rather ... From ethan at stoneleaf.us Mon May 5 16:01:29 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 05 May 2014 13:01:29 -0700 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: Message-ID: <5367EE19.7080606@stoneleaf.us> On 05/05/2014 12:51 PM, Grant Edwards wrote: > > I'm working on a Python app that receives an e-mail message via SMTP, > does some trivial processing on it, and forwards it to another SMTP > server. > > I'd like to do the polite thing and add a "Received:" header, but I > can't figure out how to get Python's email module to add it in the > correct place. It always ends up at the "bottom" of the headers below > From: To: etc. It's supposed to go at the above all the Received: > headers that where there when I received it. I don't know that it matters, but which Python version? -- ~Ethan~ From invalid at invalid.invalid Mon May 5 16:58:25 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 5 May 2014 20:58:25 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? References: Message-ID: On 2014-05-05, Ethan Furman wrote: > On 05/05/2014 12:51 PM, Grant Edwards wrote: [...] >> I'd like to do the polite thing and add a "Received:" header, but I >> can't figure out how to get Python's email module to add it in the >> correct place. It always ends up at the "bottom" of the headers below >> From: To: etc. It's supposed to go at the above all the Received: >> headers that where there when I received it. > > I don't know that it matters, but which Python version? Sorry, should have mentioned it: 2.7.5 -- Grant Edwards grant.b.edwards Yow! over in west at Philadelphia a puppy is gmail.com vomiting ... From python.list at tim.thechases.com Mon May 5 17:09:30 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 5 May 2014 16:09:30 -0500 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: Message-ID: <20140505160930.13ea9ed1@bigbox.christie.dr> On 2014-05-05 20:58, Grant Edwards wrote: > On 2014-05-05, Ethan Furman wrote: > > On 05/05/2014 12:51 PM, Grant Edwards wrote: > >> I'd like to do the polite thing and add a "Received:" header, > >> but I can't figure out how to get Python's email module to add > >> it in the correct place. It always ends up at the "bottom" of > >> the headers below From: To: etc. It's supposed to go at the > >> above all the Received: headers that where there when I received > >> it. > > > > I don't know that it matters, but which Python version? > > Sorry, should have mentioned it: 2.7.5 Looking at the stdlib source, it doesn't look like there's an easy way to specify where it gets inserted. However, the source to email.message.Message.add_header() is all of 9 lines of code, so it wouldn't be too hard to subclass Message and twiddle self._headers as you would any other list (i.e., using .insert() to specify an index). It might look something like class MyMessage(email.message.Message): def insert_header(self, index, _name, _value, **_params): parts = [] for k, v in _params.items(): if v is None: parts.append(k.replace('_', '-')) else: parts.append(_formatparam(k.replace('_', '-'), v)) if _value is not None: parts.insert(0, _value) self._headers.insert(index, (_name, SEMISPACE.join(parts))) You might still need to search for *where* you want to insert it, but I'll leave that as an exercise to the reader. :-) -tkc -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From chris at freeranger.com Mon May 5 18:37:55 2014 From: chris at freeranger.com (chris at freeranger.com) Date: Mon, 5 May 2014 15:37:55 -0700 (PDT) Subject: socket client and server in one application? In-Reply-To: <2db82378-5bb3-4a5c-b9e0-7ccb29760a06@googlegroups.com> References: <2db82378-5bb3-4a5c-b9e0-7ccb29760a06@googlegroups.com> Message-ID: <69f1b8e6-0b03-4d26-9b89-0d7b3dc43b16@googlegroups.com> Thanks to Marko, Chin, Grant. There's a lot to study, asincio, urllib, threads, select/poll. I'm using a dispatch method to receive and occasionally send data through a serial port on a Raspberry Pi. I think the dispatch method is essentially a threaded approach, right? Now to receive serial data and send via socket, then occasionally receive some socket based input and send out on the same serial port. It's combining the client and server socket code into a single app (so I can have a single connection to the serial port) that has me confused. I don't see any discussion of that anywhere. Thanks so much, Chris. From rosuav at gmail.com Mon May 5 19:05:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 May 2014 09:05:22 +1000 Subject: socket client and server in one application? In-Reply-To: <69f1b8e6-0b03-4d26-9b89-0d7b3dc43b16@googlegroups.com> References: <2db82378-5bb3-4a5c-b9e0-7ccb29760a06@googlegroups.com> <69f1b8e6-0b03-4d26-9b89-0d7b3dc43b16@googlegroups.com> Message-ID: On Tue, May 6, 2014 at 8:37 AM, wrote: > I'm using a dispatch method to receive and occasionally send data through a serial port on a Raspberry Pi. I think the dispatch method is essentially a threaded approach, right? > > Now to receive serial data and send via socket, then occasionally receive some socket based input and send out on the same serial port. It's combining the client and server socket code into a single app (so I can have a single connection to the serial port) that has me confused. I don't see any discussion of that anywhere. > Threads would be easy. As I understand it, you have two bidirectional connections, and you're simply linking them? Sounds like a very simple proxy/tunnel. You don't need to multiplex, so all you need is two threads: one reading from the socket and writing to the serial port, and one reading from the serial port and writing to the socket. The code would look something like this: serial_port = open(...) tcp_socket = socket.create_connection(...) # initialize them both, do whatever setup is needed def socket_to_serial(): while True: data = tcp_socket.recv(4096) serial_port.write(data) Thread.Thread(target=socket_to_serial).start() while True: data = serial_port.read(4096) tcp_socket.send(data) Two simple loops, running concurrently. Pretty straight-forward as threads. Both of them will fall idle in their read/recv calls, so threading works very nicely here. ChrisA From dihedral88888 at gmail.com Mon May 5 19:08:45 2014 From: dihedral88888 at gmail.com (CHIN Dihedral) Date: Mon, 5 May 2014 16:08:45 -0700 (PDT) Subject: Tutorials for Reorganizing Spreadsheet Data In-Reply-To: <4c4b4c31-2a49-4ba1-93b4-16573116acff@googlegroups.com> References: <4c4b4c31-2a49-4ba1-93b4-16573116acff@googlegroups.com> Message-ID: <1178c74b-9a8f-48ef-8f4e-03f5488f1f29@googlegroups.com> On Wednesday, April 16, 2014 9:50:25 PM UTC+8, joseph... at gmail.com wrote: > Hello, I'm a high school physics teacher and while I've played with Python enough to make a rock paper scissors program or animation of a bouncing ball (with air resistance!), I've never used it to work with data from a spreadsheet. > > > > I have a large spreadsheet with a number of different student responses to a weekly prompt in various cells depending on which question they chose to answer. I'd like to organize these responses into something that make it easy for students to look back through their responses over time, and see how they've changed. > > > > This is obviously possible in Python, but I don't know where to begin learning the details of what I'll need to know to build it. Can anyone give me a specific recommendation of tutorials where I might begin? > > > > Thanks! > > > > Joe Check the source code here: http://manns.github.io/pyspread/ and http://www.python-excel.org/ . From invalid at invalid.invalid Mon May 5 22:13:09 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 6 May 2014 02:13:09 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? References: Message-ID: On 2014-05-05, Tim Chase wrote: > On 2014-05-05 20:58, Grant Edwards wrote: >> On 2014-05-05, Ethan Furman wrote: >> > On 05/05/2014 12:51 PM, Grant Edwards wrote: >> >> I'd like to do the polite thing and add a "Received:" header, >> >> but I can't figure out how to get Python's email module to add >> >> it in the correct place. It always ends up at the "bottom" of >> >> the headers below From: To: etc. It's supposed to go at the >> >> above all the Received: headers that where there when I received >> >> it. >> > >> > I don't know that it matters, but which Python version? >> >> Sorry, should have mentioned it: 2.7.5 > > Looking at the stdlib source, it doesn't look like there's an easy > way to specify where it gets inserted. Thanks. There's is a somewhat messy way to do it by calling msg.items() to retrieve all the current headers, removing all of them, and then adding them all back (includeing the new one) in the order I want them. > However, the source to email.message.Message.add_header() is all of 9 > lines of code, so it wouldn't be too hard to subclass Message and > twiddle self._headers as you would any other list (i.e., using > .insert() to specify an index). [ insert_header() method example that lets you specify an index ] A couple other options I was thinking about: * Just override __set_item__ so it treats 'Received' as a special case and inserts it before any existing 'Received' headers -- or prepends it if there aren't any. * Add a prepend_header() method that just sticks it at the top -- in most cases, I think that will be correct enough. I think I like your suggestion better. Since the keys() method preserves the order of header keys, that makes figuring out the insertion point trivial. -- Grant From satish.muthali at gmail.com Mon May 5 20:39:44 2014 From: satish.muthali at gmail.com (Satish Muthali) Date: Mon, 5 May 2014 17:39:44 -0700 Subject: Pass variable by reference Message-ID: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> Hello experts, I have a burning question on how to pass variable by reference in Python. I understand that the data type has to be mutable. For example, here?s the issue I am running in to: I am trying to extract the PostgreSQL DB version for example: pgVer = [s.split() for s in os.popen("psql --version").read().splitlines()] print pgVer[0] for i, var in enumerate(pgVer[0]): if i == len(pgVer[0]) - 1: pgversion = var I would now like to pass ?pgversion? (where the value of pgversion is 9.3.4) by reference, for example: I want to nuke /var/lib/postgresql/9.3.4/main/data , however programatically I want it to be as: /var/lib/postgresql//main/data Any help is appreciated. Thanks Satish -------------- next part -------------- An HTML attachment was scrubbed... URL: From kakonyet at hotmail.com Mon May 5 23:54:07 2014 From: kakonyet at hotmail.com (kakonyet) Date: Mon, 5 May 2014 20:54:07 -0700 (PDT) Subject: Stilhaus Kitchens Complaints Message-ID: <1399348447804-5055969.post@n6.nabble.com> Stilhaus Kitchens Complaints. fact is that there are no stilhaus kitchens complaints.stilhaus kitchens are the only kitchen company with no complaints -- View this message in context: http://python.6.x6.nabble.com/Stilhaus-Kitchens-Complaints-tp5055969.html Sent from the Python - python-list mailing list archive at Nabble.com. From rustompmody at gmail.com Tue May 6 00:32:23 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 5 May 2014 21:32:23 -0700 (PDT) Subject: Pass variable by reference In-Reply-To: References: Message-ID: <6fe61129-09d1-48eb-9877-effb7fa49d27@googlegroups.com> On Tuesday, May 6, 2014 6:09:44 AM UTC+5:30, Satish Muthali wrote: > Hello experts, > I have a burning question on how to pass variable by reference in Python. Technically correct answer: You cant. But see below. > I understand that the data type has to be mutable. I dont know that mutability has any bearing on this You can get mostly the effect of pass by reference by using: - multiple values (tuple) return - unpacking assignment Like so: >>> def foo(x,y): ... return x+1, y+3 ... >>> x,y= 1,2 >>> x,y=foo(x,y) >>> x,y (2, 5) >>> > For example, here's the issue I am running in to: > I am trying to extract the PostgreSQL DB version for example: > pgVer = [s.split() for s in os.popen("psql --version").read().splitlines()] > print pgVer[0] > for i, var in enumerate(pgVer[0]): > if i == len(pgVer[0]) - 1: > pgversion = var > I would now like to pass 'pgversion' (where the value of pgversion is 9.3.4) by reference, for example: > I want to nuke /var/lib/postgresql/9.3.4/main/data , however programatically I want it to be as: /var/lib/postgresql//main/data I dont really understand your example From gary.herron at islandtraining.com Tue May 6 00:42:05 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Mon, 05 May 2014 21:42:05 -0700 Subject: Pass variable by reference In-Reply-To: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> Message-ID: <5368681D.8070602@islandtraining.com> On 05/05/2014 05:39 PM, Satish Muthali wrote: > Hello experts, > > I have a burning question on how to pass variable by reference in > Python. I understand that the data type has to be mutable. This gets confusing, but in fact the most accurate answer is that Python does not have "variables", so there is no such thing as passing "variables" by reference or any other method. Python *does* have names bound to values, but that's a very different thing. If necessary, you may consider that the *values* are passed by reference. Your question is confused when it mentions "mutable" here -- that's something very different, And your question then goes on to end on an even more confused note with "I want to nuke ..." which seems to have nothing to do with passing values anywhere? Sorry to be of so little help, Gary Herron > > For example, here's the issue I am running in to: > > I am trying to extract the PostgreSQL DB version for example: > > /pgVer = [s.split() for s in os.popen("psql > --version").read().splitlines()]/ > / print pgVer[0]/ > / for i, var in enumerate(pgVer[0]):/ > / if i == len(pgVer[0]) - 1:/ > / pgversion = var/ > / > / > I would now like to pass 'pgversion' (where the value of pgversion is > 9.3.4) by reference, for example: > > I want to nuke /var/lib/postgresql/9.3.4/main/data , however > programatically I want it to be as: /var/lib/postgresql/*/ pgversion>/*/main/data > > Any help is appreciated. > > Thanks > Satish > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Tue May 6 04:18:52 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 06 May 2014 08:18:52 GMT Subject: Pass variable by reference References: Message-ID: <53689aeb$0$11109$c3e8da3@news.astraweb.com> On Mon, 05 May 2014 17:39:44 -0700, Satish Muthali wrote: > Hello experts, > > I have a burning question on how to pass variable by reference in > Python. I understand that the data type has to be mutable. Python provides neither pass-by-reference nor pass-by-value argument passing. Please read this for an explanation of why people sometimes think that it does, and what Python actually does instead: http://import-that.dreamwidth.org/1130.html To get an effect *similar* to pass-by-reference, you can wrap your variable in a list, and then only operate on the list item. For example: one = [1] two = [2] def swap(a, b): a[0], b[0] = b[0], a[0] swap(one, two) print one[0], two[0] => will print "2 1" But note carefully that in the swap function I do not assign directly to the arguments a and b, only to their items a[0] and b[0]. If you assign directly to a and b, you change the local variables. # This does not work. def swap(a, b): a, b = b, a Rather than trying to fake pass-by-reference semantics, it is much better to understand Python's capabilities and learn how to use it to get the same effect. For example, instead of writing a swap procedure, it is much simpler to just do this: one = 1 two = 2 one, two = two, one print one, two => will print "2 1" > For example, here?s the issue I am running in to: > > I am trying to extract the PostgreSQL DB version for example: > > pgVer = [s.split() for s in os.popen("psql > --version").read().splitlines()] > print pgVer[0] > for i, var in enumerate(pgVer[0]): > if i == len(pgVer[0]) - 1: > pgversion = var > > I would now like to pass ?pgversion? (where the value of pgversion is > 9.3.4) by reference, for example: > > I want to nuke /var/lib/postgresql/9.3.4/main/data , however > programatically I want it to be as: /var/lib/postgresql/ pgversion>/main/data I don't understand this. I think you mean that you want to delete a file, but you don't know the pathname of the file until you have extracted the version number as a string. path = "/var/lib/postgresql/%s/main/data" os.unlink(path % pgversion) will probably do what you want. Pass-by-reference doesn't come into this. If this is not what you mean, please explain in more detail. -- Steven From steve at pearwood.info Tue May 6 04:22:10 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 06 May 2014 08:22:10 GMT Subject: Add "Received:" header to email msg in correct position? References: Message-ID: <53689bb2$0$11109$c3e8da3@news.astraweb.com> On Tue, 06 May 2014 02:13:09 +0000, Grant Edwards wrote: > There's is a somewhat messy way to do it by calling msg.items() to > retrieve all the current headers, removing all of them, and then adding > them all back (includeing the new one) in the order I want them. Does msg.items() return the actual message header list, or a copy? Because if it returns the list itself, you can just insert directly into the list using the insert method. -- Steven From varun7rs at gmail.com Tue May 6 05:07:22 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Tue, 6 May 2014 02:07:22 -0700 (PDT) Subject: Mapping of node numbers Message-ID: <3c6c6424-0be2-456a-a41c-0178949bd5b9@googlegroups.com> Hello Everyone, I need to map the node ID to a number. I am using this xml file as of now. http://sndlib.zib.de/coredata.download.action?objectName=germany50&format=xml&objectType=network Also, I need to use the same node number whenever there is a node occurrence in the source and destination. If I have assigned numbers '4' and '32' to node IDs Berlin and Leipzig, I need to use the same node numbers at the links as well. For example, L22 has Leipzig Berlin I need two attributes next to them saying that sourceID = '32'targetID = '4' class PHY_NODES: def __init__(self, nodeID, nodenum, x, y, capacity_proc, capacity_stor, capacity_switch): self.id = nodeID self.nodenum = nodenum self.x = x self.y = y self.inEdges = [] self.outEdges = [] self.capacity_proc = capacity_proc self.capacity_stor = capacity_stor self.capacity_switch = capacity_switch self.capacity_bidirect = 0.0 def __str__(self): return "Physical Node ID: " % (self.id) "nodenum: %4d x: %.3f y: %.3f capProc: %.3f capStor: %.3f capSwitch: %.3f" %(self.nodenum, self.x, self.y, self.capacity_proc, self.capacity_stor, self.capacity_switch) def addInEdge (self, edge): self.inEdges.append(edge) self.capacity_bidirect = capacity_bidirect + edge.capacity def addOutEdge (self, edge): self.outEdges.append(edge) self.capacity_bidirect = capacity_bidirect + edge.capacity class PHY_LINKS: def __init__(self, linkID, source, destination, tailNodeId, headNodeId, capacity_bdw): self.linkID = linkID self.source = source self.destination = destination self.tailNodeId = tailNodeId self.headNodeId = headNodeId self.capacity_bdw = capacity_bdw def __str__(self): return "Physical Link ID: " % (self.linkID) "source: %s destination: %s tailNodeId: %4d headNodeId: %4d capacity_bdw: %.3f" %(self.source, self.destination, self.tailNodeId, self.headNodeId, self.capacity_bdw) class PHY_NETWORK: def __init__(self, nodes, edges, nameToIdMap) self.nodes = nodes self.edges = edges self.nameToIdMap = nameToIdMap def getEdge(self, tailId, headId): if tailId < 0 or tailId >= len( self.nodes ) or headId < 0 or headId >= len( self.nodes ): return None else: for edge in self.nodes[ tailId ].outEdges: if edge.headNodeId == headId: return self.edges[ edge.linkID ] for edge in self.nodes[ headId ].outEdges: if edge.headNodeId == tailId: return self.edges[ edge.linkID ] return None def hasEdge( self, tailId, headId ): if len( self.nodes ) <= tailId or len( self.nodes ) <= headId : return False for edge in self.nodes[tailId].outEdges: if edge.headNodeId == headId: return True for edge in self.nodes[tailId].inEdges: if edge.tailNodeId == tailId: return True return False def addNode(self, node): self.nodes.append( node ) self.nameToIdMap[ node.name ] = node.id def addEdge(self, edge): self.edges.append( edge ) self.nodes[ edge.headNodeId ].addInEdge( edge ) self.nodes[ edge.tailNodeId ].addOutEdge( edge ) nodes = [] edges = [] nodeNameToIdMap = {} Read_Data = parse(filename) # "germany50.xml" # Reading Nodes nodelist = Read_Data.getElementsByTagName("node") num = 0 for node in nodelist : nodes.append(node.getAttribute("id")) #nodeid = node.getAttribute("id") xCoordinates = node.getElementsByTagName("x") [0] yCoordinates = node.getElementsByTagName("y") [0] proc = random.randint(3500, 5000) stor = random.randint(7200, 8200) switch = random.randint(7000, 10000) num = num + 1 nodes.append(PHY_NODES( node.getAttribute("id"), int(num), float(xCoodinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch))) nodeNameToIdMap[ nodes[-1].num ] = nodes[-1].id # Reading Links linklist = Read_Data.getElementsByTagName("link") for link in linklist : linkid = link.getAttribute("id") Source = link.getElementsByTagName("source") [0] Destination = link.getElementsByTagName("target") [0] Capacity = link.getElementsByTagName("capacity") [0] SourceID = edges.append(PHY_LINKS( link.getAttribute("id"), Source.firstChild.data, Destination.firstChild.data, int(Capacity.firstChild.data) )) nodes[ edges[-1].source ].addInEdge( edges[-1] ) nodes[ edges[-1].destination ].addOutEdge( edges[-1] ) Could you please help me with this problem? Thanks a lot From marko at pacujo.net Tue May 6 05:11:15 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 06 May 2014 12:11:15 +0300 Subject: Pass variable by reference References: <53689aeb$0$11109$c3e8da3@news.astraweb.com> Message-ID: <87lhufi85o.fsf@elektro.pacujo.net> Steven D'Aprano : > On Mon, 05 May 2014 17:39:44 -0700, Satish Muthali wrote: >> I have a burning question on how to pass variable by reference in >> Python. I understand that the data type has to be mutable. > > [...] > > To get an effect *similar* to pass-by-reference, you can wrap your > variable in a list, and then only operate on the list item. Consider also returning multiple values in a tuple. In C: stats_read(stats, &characters, &words, &lines); In Python: characters, words, lines = stats.read() Marko From alister.nospam.ware at ntlworld.com Tue May 6 05:15:05 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 06 May 2014 09:15:05 GMT Subject: Add "Received:" header to email msg in correct position? References: Message-ID: On Mon, 05 May 2014 19:51:15 +0000, Grant Edwards wrote: > I'm working on a Python app that receives an e-mail message via SMTP, > does some trivial processing on it, and forwards it to another SMTP > server. > > I'd like to do the polite thing and add a "Received:" header, but I > can't figure out how to get Python's email module to add it in the > correct place. It always ends up at the "bottom" of the headers below > From: To: etc. It's supposed to go at the above all the Received: > headers that where there when I received it. Is this required or just being polite? what I mean is does the standard state the headers must be in a particular order or can they appear anywhere, you may be spending time trying to resolve an issue that does not need fixing. -- BTW: I have a better name for the software .... Microsoft Internet Exploder. -- George Bonser From rosuav at gmail.com Tue May 6 05:47:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 May 2014 19:47:54 +1000 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: Message-ID: On Tue, May 6, 2014 at 7:15 PM, alister wrote: > On Mon, 05 May 2014 19:51:15 +0000, Grant Edwards wrote: > >> I'm working on a Python app that receives an e-mail message via SMTP, >> does some trivial processing on it, and forwards it to another SMTP >> server. >> >> I'd like to do the polite thing and add a "Received:" header, but I >> can't figure out how to get Python's email module to add it in the >> correct place. It always ends up at the "bottom" of the headers below >> From: To: etc. It's supposed to go at the above all the Received: >> headers that where there when I received it. > > Is this required or just being polite? > what I mean is does the standard state the headers must be in a > particular order or can they appear anywhere, you may be spending time > trying to resolve an issue that does not need fixing. Yes, it's required. RFC 2821 [1] section 3.8.2 says "prepend". ChrisA [1] http://www.ietf.org/rfc/rfc2821.txt From rosuav at gmail.com Tue May 6 05:53:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 May 2014 19:53:15 +1000 Subject: Pass variable by reference In-Reply-To: <87lhufi85o.fsf@elektro.pacujo.net> References: <53689aeb$0$11109$c3e8da3@news.astraweb.com> <87lhufi85o.fsf@elektro.pacujo.net> Message-ID: On Tue, May 6, 2014 at 7:11 PM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Mon, 05 May 2014 17:39:44 -0700, Satish Muthali wrote: >>> I have a burning question on how to pass variable by reference in >>> Python. I understand that the data type has to be mutable. >> >> [...] >> >> To get an effect *similar* to pass-by-reference, you can wrap your >> variable in a list, and then only operate on the list item. > > Consider also returning multiple values in a tuple. > > In C: > > stats_read(stats, &characters, &words, &lines); > > In Python: > > characters, words, lines = stats.read() That's not really pass-by-reference, though. What you're doing is output parameters, which are usually implemented in C with pointers, but in Python with a return tuple. Pass-by-reference allows the callee to see and modify something in the caller's environment; for instance, the stats_read() C function might maintain stats in the three pointed-to integers, eg incrementing them for each char/word/line processed. The Python equivalent would need to pass them as parameters AND return them. For that sort of case, you'd probably want to pass an object with three attributes (or maybe a dict or a list), which would then be modified; that's a much closer approximation of pass-by-reference. Hence Steven's statement about wrapping it in a list. And, by the way, it's not purely academic. There have been times when I've done exactly that as a means of passing state around. It's not common, but it has its place. ChrisA From alister.nospam.ware at ntlworld.com Tue May 6 06:26:09 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 06 May 2014 10:26:09 GMT Subject: Add "Received:" header to email msg in correct position? References: Message-ID: <5N2av.257203$q95.207421@fx22.am4> On Tue, 06 May 2014 19:47:54 +1000, Chris Angelico wrote: > On Tue, May 6, 2014 at 7:15 PM, alister > wrote: >> On Mon, 05 May 2014 19:51:15 +0000, Grant Edwards wrote: >> >>> I'm working on a Python app that receives an e-mail message via SMTP, >>> does some trivial processing on it, and forwards it to another SMTP >>> server. >>> >>> I'd like to do the polite thing and add a "Received:" header, but I >>> can't figure out how to get Python's email module to add it in the >>> correct place. It always ends up at the "bottom" of the headers below >>> From: To: etc. It's supposed to go at the above all the Received: >>> headers that where there when I received it. >> >> Is this required or just being polite? >> what I mean is does the standard state the headers must be in a >> particular order or can they appear anywhere, you may be spending time >> trying to resolve an issue that does not need fixing. > > Yes, it's required. RFC 2821 [1] section 3.8.2 says "prepend". > > ChrisA > > [1] http://www.ietf.org/rfc/rfc2821.txt oh well, so much for the easy route :-) This suggests the email module could do with amending so that headers can be pretended as appended. -- The strong give up and move away, while the weak give up and stay. From marko at pacujo.net Tue May 6 06:38:14 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 06 May 2014 13:38:14 +0300 Subject: Pass variable by reference References: <53689aeb$0$11109$c3e8da3@news.astraweb.com> <87lhufi85o.fsf@elektro.pacujo.net> Message-ID: <87eh07i44p.fsf@elektro.pacujo.net> Chris Angelico : >> characters, words, lines = stats.read() > > That's not really pass-by-reference, though. What you're doing is > output parameters, which are usually implemented in C with pointers, > but in Python with a return tuple. Correct, but it is worth questioning the question itself: what do you need pass-by-reference for? A very common case is returning multiple values. For that, Python has other idioms available. > And, by the way, it's not purely academic. There have been times when > I've done exactly that as a means of passing state around. It's not > common, but it has its place. Nobody has been disputing Steven's technique. There are many variations to that as well. For example, instead of a list, there might be an appropriate class/object that could host the interesting piece of information and act as the desired reference. Marko From rosuav at gmail.com Tue May 6 06:41:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 May 2014 20:41:40 +1000 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: <5N2av.257203$q95.207421@fx22.am4> References: <5N2av.257203$q95.207421@fx22.am4> Message-ID: On Tue, May 6, 2014 at 8:26 PM, alister wrote: > On Tue, 06 May 2014 19:47:54 +1000, Chris Angelico wrote: > >> On Tue, May 6, 2014 at 7:15 PM, alister >> wrote: >>> On Mon, 05 May 2014 19:51:15 +0000, Grant Edwards wrote: >>> >>>> I'm working on a Python app that receives an e-mail message via SMTP, >>>> does some trivial processing on it, and forwards it to another SMTP >>>> server. >>>> >>>> I'd like to do the polite thing and add a "Received:" header, but I >>>> can't figure out how to get Python's email module to add it in the >>>> correct place. It always ends up at the "bottom" of the headers below >>>> From: To: etc. It's supposed to go at the above all the Received: >>>> headers that where there when I received it. >>> >>> Is this required or just being polite? >>> what I mean is does the standard state the headers must be in a >>> particular order or can they appear anywhere, you may be spending time >>> trying to resolve an issue that does not need fixing. >> >> Yes, it's required. RFC 2821 [1] section 3.8.2 says "prepend". >> >> ChrisA >> >> [1] http://www.ietf.org/rfc/rfc2821.txt > > oh well, so much for the easy route :-) > This suggests the email module could do with amending so that headers can > be pretended as appended. Even if it's special-cased as a dedicated "prepend received header" method, that would probably do. I can't think of any other headers where you need to specifically order them rather than appending. ChrisA From rosuav at gmail.com Tue May 6 06:45:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 May 2014 20:45:20 +1000 Subject: Pass variable by reference In-Reply-To: <87eh07i44p.fsf@elektro.pacujo.net> References: <53689aeb$0$11109$c3e8da3@news.astraweb.com> <87lhufi85o.fsf@elektro.pacujo.net> <87eh07i44p.fsf@elektro.pacujo.net> Message-ID: On Tue, May 6, 2014 at 8:38 PM, Marko Rauhamaa wrote: > Chris Angelico : > >>> characters, words, lines = stats.read() >> >> That's not really pass-by-reference, though. What you're doing is >> output parameters, which are usually implemented in C with pointers, >> but in Python with a return tuple. > > Correct, but it is worth questioning the question itself: what do you > need pass-by-reference for? A very common case is returning multiple > values. For that, Python has other idioms available. Oh, absolutely. As in many other cases, you shouldn't ask "How do I do in Python", but should ask "How do I accomplish in Python". Only in a few cases is the first question reasonable (eg "How do I call this function from Python", naming some function from a C library), and even then, it's semantically arguable. ChrisA From gelperto2002 at yahoo.com Tue May 6 08:09:25 2014 From: gelperto2002 at yahoo.com (doaa eman) Date: Tue, 6 May 2014 05:09:25 -0700 (PDT) Subject: A Question about Python Message-ID: <1399378165.32646.YahooMailNeo@web141402.mail.bf1.yahoo.com> hello; I'm a researcher from Cairo University (Information science Dep.) i want to know how can i use Paython language on CiteULike i need to use it for extracting only tagged articles in the field of medicine for example for my Ph.D research. another question please : can this webpage help me citeulike_api 0.1.3dev : Python Package Index citeulike_api 0.1.3dev : Python Package Index a python api for http://citeulike.org/ View on pypi.python.org Preview by Yahoo thanks for your time and i hope u can help me in that Eman Ali -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Tue May 6 08:20:43 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 6 May 2014 05:20:43 -0700 (PDT) Subject: A Question about Python In-Reply-To: References: Message-ID: <9fe8c3d5-2ebc-4994-a1da-eabcf4564a23@googlegroups.com> On Tuesday, May 6, 2014 5:39:25 PM UTC+5:30, doaa eman wrote: > hello; > > I'm a researcher from Cairo University (Information science Dep.) > i want to know how can i use Paython language on CiteULike > i need to use it for extracting only tagged articles in the field > of medicine for example for my Ph.D research. Do you know basics of programming? Which languages? If you do python is a pleasant language to use. If not you may be able to get on with a little help but more likely, you will suffer trying to do this... From denismfmcmahon at gmail.com Tue May 6 08:38:02 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 6 May 2014 12:38:02 +0000 (UTC) Subject: A Question about Python References: Message-ID: On Tue, 06 May 2014 05:09:25 -0700, doaa eman wrote: > I'm a researcher ...... Obviously part of your PhD research is going to be whether the citeulike_api 0.1.3dev python package can help you extract the information you want from http://citeulike.org/ We look forwards to seeing your conclusions in this matter. -- Denis McMahon, denismfmcmahon at gmail.com From shrikantah at gmail.com Tue May 6 10:07:14 2014 From: shrikantah at gmail.com (shrikant aher) Date: Tue, 6 May 2014 19:37:14 +0530 Subject: (question) How to use python get access to google search without query quota limit Message-ID: hey, will u please send me the code that you write. actually i'm trying to learn use of google search api but i'm not getting so please mail me the code. my mail id is shrikantah at gmail.com -- Shrikant -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Tue May 6 10:12:53 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 6 May 2014 14:12:53 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? References: <53689bb2$0$11109$c3e8da3@news.astraweb.com> Message-ID: On 2014-05-06, Steven D'Aprano wrote: > On Tue, 06 May 2014 02:13:09 +0000, Grant Edwards wrote: > >> There's is a somewhat messy way to do it by calling msg.items() to >> retrieve all the current headers, removing all of them, and then adding >> them all back (includeing the new one) in the order I want them. > > Does msg.items() return the actual message header list, or a copy? A shallow copy: def items(self): """Get all the message's header fields and values. These will be sorted in the order they appeared in the original message, or were added to the message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. """ return self._headers[:] > Because if it returns the list itself, you can just insert directly into > the list using the insert method. -- Grant Edwards grant.b.edwards Yow! What I need is a at MATURE RELATIONSHIP with a gmail.com FLOPPY DISK ... From invalid at invalid.invalid Tue May 6 10:15:08 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 6 May 2014 14:15:08 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? References: Message-ID: On 2014-05-06, alister wrote: > On Mon, 05 May 2014 19:51:15 +0000, Grant Edwards wrote: > >> I'm working on a Python app that receives an e-mail message via SMTP, >> does some trivial processing on it, and forwards it to another SMTP >> server. >> >> I'd like to do the polite thing and add a "Received:" header, but I >> can't figure out how to get Python's email module to add it in the >> correct place. It always ends up at the "bottom" of the headers below >> From: To: etc. It's supposed to go at the above all the Received: >> headers that where there when I received it. > > Is this required or just being polite? I couldn't find it in an RFC. But every reference I could find that mentioned Received: headers did say that you read them from the bottom up (most recent is on top). > what I mean is does the standard state the headers must be in a > particular order or can they appear anywhere, you may be spending > time trying to resolve an issue that does not need fixing. I'd like to do it the right way whether it's required by the letter of the law or not. -- Grant Edwards grant.b.edwards Yow! I'm GLAD I at remembered to XEROX all gmail.com my UNDERSHIRTS!! From invalid at invalid.invalid Tue May 6 10:19:28 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 6 May 2014 14:19:28 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? References: Message-ID: On 2014-05-06, Grant Edwards wrote: > On 2014-05-06, alister wrote: >> On Mon, 05 May 2014 19:51:15 +0000, Grant Edwards wrote: >> >>> I'm working on a Python app that receives an e-mail message via SMTP, >>> does some trivial processing on it, and forwards it to another SMTP >>> server. >>> >>> I'd like to do the polite thing and add a "Received:" header, but I >>> can't figure out how to get Python's email module to add it in the >>> correct place. It always ends up at the "bottom" of the headers below >>> From: To: etc. It's supposed to go at the above all the Received: >>> headers that where there when I received it. >> >> Is this required or just being polite? > > I couldn't find it in an RFC. I was looking in the message format RFCs, and as has already been pointed out, it's in the SMTP spec (RFC2821). Since there _is_ an RFC that specifically states you MUST prepend a header line to a message, this seems to be a hole in the email module... -- Grant Edwards grant.b.edwards Yow! If I am elected no one at will ever have to do their gmail.com laundry again! From rosuav at gmail.com Tue May 6 10:26:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 May 2014 00:26:24 +1000 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: Message-ID: On Wed, May 7, 2014 at 12:15 AM, Grant Edwards wrote: > On 2014-05-06, alister wrote: >> On Mon, 05 May 2014 19:51:15 +0000, Grant Edwards wrote: >> >>> I'm working on a Python app that receives an e-mail message via SMTP, >>> does some trivial processing on it, and forwards it to another SMTP >>> server. >>> >>> I'd like to do the polite thing and add a "Received:" header, but I >>> can't figure out how to get Python's email module to add it in the >>> correct place. It always ends up at the "bottom" of the headers below >>> From: To: etc. It's supposed to go at the above all the Received: >>> headers that where there when I received it. >> >> Is this required or just being polite? > > I couldn't find it in an RFC. But every reference I could find that > mentioned Received: headers did say that you read them from the bottom > up (most recent is on top). Yeah, I went looking for it in 2822 but didn't find much. After some digging, found it in 2821, section 3.8.2. It's not dwelled on, but the word "prepend" is used, which to my mind is a clear indication of necessary ordering. ChrisA From yimr00 at gmail.com Tue May 6 10:25:56 2014 From: yimr00 at gmail.com (Yimr Zero) Date: Tue, 6 May 2014 22:25:56 +0800 Subject: Add "Received:" header to email msg in correct position? Message-ID: If you use Python 2.7, you should add urllib, urllib2 modules. If you use Python 3, the two modules mentioned above are included in urllib. -------------- next part -------------- An HTML attachment was scrubbed... URL: From harrismh777 at gmail.com Tue May 6 10:51:25 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 06 May 2014 09:51:25 -0500 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> <7xeh0ekv7s.fsf@ruckus.brouhaha.com> <5361CA91.30401@gmail.com> Message-ID: On 5/1/14 9:06 PM, Dennis Lee Bieber wrote: >> The N4-ES and the N4-T (mine) are essentially the same rule. The N4-ES >> on the site is yellow (mine is white) and the site rule indicates Picket >> & Eckel Inc. (that's where the E comes from) Also the the ES states >> Chicage Ill USA where the T states Made in USA. > > ES was for "Eye-Saver" -- the yellow background vs the bright white of > the other models. Actually, I think you're right. I never used the a yellow rule, but I will say that my N4-T never caused me any eye-strain (but I was younger then). The N4-T was a flat white also... very easy to read. I really don't know what all the 'yellow' hype was all about. From harrismh777 at gmail.com Tue May 6 10:59:22 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 06 May 2014 09:59:22 -0500 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> Message-ID: On 5/1/14 8:47 PM, Dennis Lee Bieber wrote: > On Wed, 30 Apr 2014 22:54:21 -0500, Mark H Harris > declaimed the following: > >> >> My high school '74 was the last class to learn the slide-rule using >> the Sterling (we paid a deposit to use the school's). > Since calculators had started to appear, I never did get formal > training in slide-rules. The LL scales still require me to glance at a > guide book... > > I regret that I never risked the $35 dollars when my college bookstore > was closing out the slide-rule display. They had the top Post bamboo > laminate rule at half price. At the time I'd bought an HP-25 calculator > [they phased out the HP brand a year or two later -- apparently RPN was too > confusing]. Half way through my senior year the HP-65 "gold key" calculator was available for about $800.00 dollars. That sucker was programmable and had magnetic strip recorder for off-loading storage... but I digress. We all had our priorities... one guy bought one; the rest of us bought cars. ---for about the same price too! I used my rule well into college; the first calculator I owned was the Rockwell 63R --- "The Big green numbers, and the little rubber feet!" marcus From burak.arslan at arskom.com.tr Tue May 6 11:11:48 2014 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Tue, 06 May 2014 18:11:48 +0300 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: Message-ID: <5368FBB4.1020005@arskom.com.tr> On 05/06/14 12:47, Chris Angelico wrote: > On Tue, May 6, 2014 at 7:15 PM, alister > wrote: >> On Mon, 05 May 2014 19:51:15 +0000, Grant Edwards wrote: >> >>> I'm working on a Python app that receives an e-mail message via SMTP, >>> does some trivial processing on it, and forwards it to another SMTP >>> server. >>> >>> I'd like to do the polite thing and add a "Received:" header, but I >>> can't figure out how to get Python's email module to add it in the >>> correct place. It always ends up at the "bottom" of the headers below >>> From: To: etc. It's supposed to go at the above all the Received: >>> headers that where there when I received it. >> Is this required or just being polite? >> what I mean is does the standard state the headers must be in a >> particular order or can they appear anywhere, you may be spending time >> trying to resolve an issue that does not need fixing. > Yes, it's required. RFC 2821 [1] section 3.8.2 says "prepend". > > The rationale for "prepend" is to make it possible for MTAs to add their "Received:" headers to messages without having to parse them. So you're supposed to do the same: Just write your Received header, followed by '\r\n', followed by the rest of the message to the socket and you should be fine. Best, Burak From alister.nospam.ware at ntlworld.com Tue May 6 11:12:51 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 06 May 2014 15:12:51 GMT Subject: (question) How to use python get access to google search without query quota limit References: Message-ID: On Tue, 06 May 2014 19:37:14 +0530, shrikant aher wrote: > hey, > will u please send me the code that you write. actually i'm trying to > learn use of google search api but i'm not getting so please mail me the > code. my mail id is shrikantah at gmail.com it does not work like that here you show us the code you are trying along with the errors you are getting & we may help you correct it. -- Thus spake the master programmer: "After three days without programming, life becomes meaningless." -- Geoffrey James, "The Tao of Programming" From alister.nospam.ware at ntlworld.com Tue May 6 11:16:22 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 06 May 2014 15:16:22 GMT Subject: Add "Received:" header to email msg in correct position? References: Message-ID: On Tue, 06 May 2014 14:15:08 +0000, Grant Edwards wrote: > > I'd like to do it the right way whether it's required by the letter of > the law or not. So do I , although i might have left a cosmetic issue until the rest of the app was functioning as desired. As wiser minds than mine have now confirmed order is important this point is of course moot - sorry. -- Guns don't kill people. It's those damn bullets. Guns just make them go really really fast. -- Jake Johanson From alister.nospam.ware at ntlworld.com Tue May 6 11:18:46 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 06 May 2014 15:18:46 GMT Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> <7xeh0ekv7s.fsf@ruckus.brouhaha.com> <5361CA91.30401@gmail.com> Message-ID: On Tue, 06 May 2014 09:51:25 -0500, Mark H Harris wrote: > On 5/1/14 9:06 PM, Dennis Lee Bieber wrote: >>> The N4-ES and the N4-T (mine) are essentially the same rule. The N4-ES >>> on the site is yellow (mine is white) and the site rule indicates >>> Picket & Eckel Inc. (that's where the E comes from) Also the the ES >>> states Chicage Ill USA where the T states Made in USA. >> >> ES was for "Eye-Saver" -- the yellow background vs the bright white of >> the other models. > > Actually, I think you're right. I never used the a yellow rule, but > I will say that my N4-T never caused me any eye-strain (but I was > younger then). > > The N4-T was a flat white also... very easy to read. I really don't > know what all the 'yellow' hype was all about. probably about $XX.XX more :-) (before my time so I would not have a clue about the actual cost) -- If you don't do the things that are not worth doing, who will? From invalid at invalid.invalid Tue May 6 11:26:11 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 6 May 2014 15:26:11 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? References: Message-ID: On 2014-05-06, Burak Arslan wrote: > > On 05/06/14 12:47, Chris Angelico wrote: >> On Tue, May 6, 2014 at 7:15 PM, alister >> wrote: >>> On Mon, 05 May 2014 19:51:15 +0000, Grant Edwards wrote: >>> >>>> I'm working on a Python app that receives an e-mail message via SMTP, >>>> does some trivial processing on it, and forwards it to another SMTP >>>> server. >>>> >>>> I'd like to do the polite thing and add a "Received:" header, but I >>>> can't figure out how to get Python's email module to add it in the >>>> correct place. It always ends up at the "bottom" of the headers below >>>> From: To: etc. It's supposed to go at the above all the Received: >>>> headers that where there when I received it. >> >>> Is this required or just being polite? >>> what I mean is does the standard state the headers must be in a >>> particular order or can they appear anywhere, you may be spending time >>> trying to resolve an issue that does not need fixing. >> Yes, it's required. RFC 2821 [1] section 3.8.2 says "prepend". > > The rationale for "prepend" is to make it possible for MTAs to add > their "Received:" headers to messages without having to parse them. > > So you're supposed to do the same: Just write your Received header, > followed by '\r\n', followed by the rest of the message to the socket > and you should be fine. I need to check and manipulate other headers for other reasons, so I'm using the email module for that. In order to keep things consistent and easy to understand, I'd like to use the email module to prepend the Received header as well. That keeps my application from having to have any knowledge about e-mail message formatting. -- Grant Edwards grant.b.edwards Yow! ... I want a COLOR at T.V. and a VIBRATING BED!!! gmail.com From nh.jones01 at gmail.com Tue May 6 12:07:27 2014 From: nh.jones01 at gmail.com (Norah Jones) Date: Tue, 6 May 2014 16:07:27 +0000 Subject: How does apache runs a application when a request comes in? Message-ID: Hi, I have a python web application running on apache2 deployed with `mod_wsgi`. The application has a thread continuously running. This thread is a ZeroMQ thread and listening to a port in loop. The application is not maintaining session. Now if I open the browser and sends a request to the apache server the data is accepted for the first time. Now when second time I send the request It shows Internal server error. When I checked the error log file for traceback, It shows the ZMQError:- The address already in use. Does apache reloads the application on each request sent from the browser since so that the ZeroMQ thread is being created everytime and being assigned the port but since the port has already been assigned it shows error.... Thanks, Norah Jones From thomas.lehmann.private at googlemail.com Tue May 6 12:07:50 2014 From: thomas.lehmann.private at googlemail.com (thomas.lehmann.private at googlemail.com) Date: Tue, 6 May 2014 09:07:50 -0700 (PDT) Subject: xmlrpc: problems with socket handling, close, shutdown of server, TIME_WAIT, ... Message-ID: <01237970-87cd-4d29-a944-09e64b8efeee@googlegroups.com> Hi, taking the xml-rpc derived from standard example is working - basically - but with following scenario I do not understand the problem. Maybe you can help: - one Unittest that does create the xmlrpc server in a thread in "setUp" and shutdown of it in tearDown. The xml-rcp server does store/load a value for a key. (It's for testing/learning purpose) Problem(s): - If I run the test method twice (copy and paste and rename) then I get a "error: [Errno 98] Address already in use" (I assumend the tearDown would have closed all sockets) - Because of this I removed that second method and so it's fine but checking with "netstat -n | grep " I see as many sockets in TIME_WAIT as I did xml-rpc calls. Also that python test is not running anymore it take some time until those entries vanish from the netstat list. Question(s): I assumed that calling the shutdown of the server (in tearDown) does close all sockets. The SimpleXMLRPCServer is derived from SocketServer.TCPServer and those one is derived from BaseServer. Those has the shutdown which is documented to stop the serve_forever loop. Is this correct or do I have to shutdown in another way? At client side I'm using the ServerProxy. It does obviously not have a "close". From code it looks like that I could do something like "proxy("close")()" but that looks somehow wired? Can I close a proxy?, should I?, ... what is the way? From joel.goldstick at gmail.com Tue May 6 12:14:29 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 6 May 2014 12:14:29 -0400 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> <7xeh0ekv7s.fsf@ruckus.brouhaha.com> <5361CA91.30401@gmail.com> Message-ID: HP 35. $350 in 1973 or 4. Still have it somewhere. Tom yay! On May 6, 2014 11:20 AM, "alister" wrote: > On Tue, 06 May 2014 09:51:25 -0500, Mark H Harris wrote: > > > On 5/1/14 9:06 PM, Dennis Lee Bieber wrote: > >>> The N4-ES and the N4-T (mine) are essentially the same rule. The N4-ES > >>> on the site is yellow (mine is white) and the site rule indicates > >>> Picket & Eckel Inc. (that's where the E comes from) Also the the ES > >>> states Chicage Ill USA where the T states Made in USA. > >> > >> ES was for "Eye-Saver" -- the yellow background vs the bright > white of > >> the other models. > > > > Actually, I think you're right. I never used the a yellow rule, but > > I will say that my N4-T never caused me any eye-strain (but I was > > younger then). > > > > The N4-T was a flat white also... very easy to read. I really don't > > know what all the 'yellow' hype was all about. > > probably about $XX.XX more :-) (before my time so I would not have a clue > about the actual cost) > > > > -- > If you don't do the things that are not worth doing, who will? > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue May 6 12:10:06 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 May 2014 16:10:06 GMT Subject: [OT] Silde rules [was Re: Significant digits in a float?] References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> Message-ID: <5369095e$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 06 May 2014 09:59:22 -0500, Mark H Harris wrote: [...] > I used my rule well into college; the first calculator I owned was > the Rockwell 63R --- "The Big green numbers, and the little rubber > feet!" Guys, heaven knows I'm guilty of the occasional off-topic post myself, and I'm not obsessive about these things, but there comes a time in every off-topic thread where the right thing to do is to label it off-topic. And this thread has long passed that time! -- Steven D'Aprano http://import-that.dreamwidth.org/ From thomas.lehmann.private at googlemail.com Tue May 6 12:28:49 2014 From: thomas.lehmann.private at googlemail.com (Thomas Lehmann) Date: Tue, 6 May 2014 09:28:49 -0700 (PDT) Subject: Why Python 3? In-Reply-To: References: Message-ID: Hi, I can't give you the advise for a concrete version anyway there are lot of arguments given by the other posters. BUT there is a way how you can circumvent the problem to some extend: Are you intending to use Jenkins? I don't want to convince you here why to use Jenkins but maybe I don't need to and THEN you just install the ShiningPanda plugin and each time your project is build automatically because of a change all tests are running across multiple Python versions. This way you won't have too many problems to switch to another newer Python version. Keep the build "green". > > What is the general feel of /this/ community? I'm about to start a > > large scale Python project. Should it be done in 2 or 3? What are the > > benefits, aside from the 'it's the future' argument? From harrismh777 at gmail.com Tue May 6 12:29:50 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 06 May 2014 11:29:50 -0500 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> <7xeh0ekv7s.fsf@ruckus.brouhaha.com> <5361CA91.30401@gmail.com> Message-ID: On 5/1/14 10:53 AM, William Ray Wing wrote: > I?m surprised no one has jumped in to defend/tout the Dietzgen slide rules > (which I always thought were the ultimate). Mine (their Vector Log Log) is > one of their Microglide series that had teflon rails inserted in the body > and is still totally stick-free after nearly 50 years. > http://www.marksmath.com/slide-rules/img/ed-n1725.jpg The above link is nice for the Dietzgen Microglide. It doesn't have the CF/m DF/m scales, but is a very nice Vector type log log. Most of my drafting equipment from the same era was Dietzgen; it looked like the previous video post featured the same/ My dad has one of these; but I can't get him to part with it yet... marcus From johan.llewellyn at yahoo.com Tue May 6 14:45:40 2014 From: johan.llewellyn at yahoo.com (Johan Llewellyn) Date: Tue, 6 May 2014 11:45:40 -0700 (PDT) Subject: multiprocessing in a while loop? Message-ID: <1399401940.38145.YahooMailNeo@web121205.mail.ne1.yahoo.com> hi, I am struggling to understand how to leverage python's multiprocessing module in a while loop.? the examples I have found seem to assume it is known ahead of time how many items need to be processed. specifically, I am reading from an external queue.? I currently process items one at a time until the queue is empty.? I wrote a wrapper function to handle connecting to the queue, pulling the next message, and deleting it when I am done.? ideally, I'd like to modify this wrapper function to take an additional argument (processes) to specify the number of messages to process simultaneously. I've attached a script that captures what I am doing now.? unfortunately, the external queue object is not publicly accessible and I'm not quite sure how to set up a local object that would support testing.? any suggestions would be most welcome. thanks, Johan -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: mp_test.py Type: text/x-python Size: 793 bytes Desc: not available URL: From dieter at handshake.de Tue May 6 07:03:08 2014 From: dieter at handshake.de (dieter) Date: Tue, 06 May 2014 13:03:08 +0200 Subject: Problems with ZODB, I can not persist and object accessed from 2 threads References: Message-ID: <87iopjyxsj.fsf@handshake.de> Ariel Arga?araz writes: > Hello, I am sorry I am stuck in this. And I need some help > > I want to persist an Object with ZODB, the object can be accessed from 2 > different threads. The ZODB manual says: > > A multi-threaded program should open a separate Connection instance for > each thread. Different threads can then modify objects and commit their > modifications independently. > > But there isn't an example of how to create a connection for each thread. > Can someone tell me how to connect to the same DB from 2 threads?? You create a connection in the second thread in the same way as you have created/opened it in the first thread (unless something has done this automatically for you; in this case, you must learn how this something has opened it). Usually, you have one datebase (or more) (let's call it "db"). Then you open a connection to this database by "conn = db.open()". The database (we have called it "db") is global to all threads. Each thread must open (and maybe close) its own connection to the global database. You must never share the same connection or objects loaded via the connection between threads - very weird (and apparently non-deterministic) errors can result. Do not forget to "commit/abort" transactions, in order that modifications done in one thread become visible in other threads. Note that a connection "sees" the state of an object as it has been when the transaction has started (note that transactions are by default bound to threads -- thus each thread has its own (independent) transactions). A transaction starts when the former transaction has been "committed/aborted". Thus, in order to see changes, it thread may need to "commit/abort" its transaction even if it itself has changed nothing. > ... > I attached an example of what I am trying to do. > > And I get this error. > > Traceback (most recent call last): > File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner > self.run() > File "/usr/lib/python2.7/threading.py", line 763, in run > self.__target(*self.__args, **self.__kwargs) > File "main.py", line 33, in thread_1 > storage = FileStorage("/tmp/asdasd.fs") > File "/usr/lib/python2.7/site-packages/ZODB/FileStorage/FileStorage.py", > line 164, in *_init_* > self._lock_file = LockFile(file_name + '.lock') > File "/usr/lib/python2.7/site-packages/zc/lockfile/__init__.py", line 84, > in *_init_* > _lock_file(fp) > File "/usr/lib/python2.7/site-packages/zc/lockfile/__init__.py", line 59, > in _lock_file > raise LockError("Couldn't lock %r" % file.name) > LockError: Couldn't lock '/tmp/asdasd.fs.lock' You try to open the database a second time -- this is only possible in case you a using ZEO and a "ZEOClient" (not "FileStorage"). But, there is no need to open the database in each thread. The database can be shared across all your threads. Only the database connections must be thread local. From tjreedy at udel.edu Tue May 6 15:16:54 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 May 2014 15:16:54 -0400 Subject: Pass variable by reference In-Reply-To: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> Message-ID: On 5/5/2014 8:39 PM, Satish Muthali wrote: > Hello experts, > > I have a burning question on how to pass variable by reference in > Python. Python passes objects to functions. CPython implements this by passing object pointers. In one sense, your request is impossible. In another, it already happens. > I understand that the data type has to be mutable. In C, all data are mutable, so copying a block of memory versus passing a pointer is the meaningful distinction. In Python, mutable arguments can be mutated and immutable args cannot, so *that* is the only meaningful distinction. Strings are not mutable. > For example, here?s the issue I am running in to: > > I am trying to extract the PostgreSQL DB version for example: > > /pgVer = [s.split() for s in os.popen("psql > --version").read().splitlines()]/ > / print pgVer[0]/ > / for i, var in enumerate(pgVer[0]):/ > / if i == len(pgVer[0]) - 1:/ > / pgversion = var/ > / > / > I would now like to pass ?pgversion? (where the value of pgversion is > 9.3.4) by reference, for example: > > I want to nuke /var/lib/postgresql/9.3.4/main/data , however > programatically I want it to be as: /var/lib/postgresql/*/ pgversion>/*/main/data It is not clear whether you want to delete a file or rename it. Either is easy and neither depend on passing mechanism. -- Terry Jan Reedy From tjreedy at udel.edu Tue May 6 14:16:33 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 May 2014 14:16:33 -0400 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: Message-ID: On 5/5/2014 4:58 PM, Grant Edwards wrote: > On 2014-05-05, Ethan Furman wrote: >> I don't know that it matters, but which Python version? I usually does these days. > Sorry, should have mentioned it: 2.7.5 email has been improved with successive 3.x versions. https://docs.python.org/3/library/email.html#package-history There might be an email5 backport for 2.7 on pypi. If the prepend requirement is covered by "The email package is a library for managing email messages, including MIME and other RFC 2822-based message documents. It is specifically not designed to do any sending of email messages to SMTP (RFC 2821), NNTP, or other servers; those are functions of modules such as smtplib and nntplib. The email package attempts to be as RFC-compliant as possible, supporting in addition to RFC 2822, such MIME-related RFCs as RFC 2045, RFC 2046, RFC 2047, and RFC 2231." and the current 3.4/5 version does not prepend and there is no existing tracker issue, then a new issue would seem to be appropriate. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Tue May 6 15:27:43 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 06 May 2014 20:27:43 +0100 Subject: (question) How to use python get access to google search without query quota limit In-Reply-To: References: Message-ID: On 06/05/2014 15:07, shrikant aher wrote: > hey, > will u please send me the code that you write. actually i'm trying to > learn use of google search api but i'm not getting so please mail me the > code. > my mail id is shrikantah at gmail.com > > -- > Shrikant > > Sure but it's USD 1,000 cash or cheque made payable to the Python Software Foundation, backed up by bankers card. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From malaclypse2 at gmail.com Tue May 6 16:27:42 2014 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 6 May 2014 16:27:42 -0400 Subject: Joining centos 6.5 member Domain Controller to an existing Windows Domain In-Reply-To: References: Message-ID: On Mon, May 5, 2014 at 11:18 AM, Joshua Knights wrote: > > Here is my Issue and I think it may be a python path bug? It's not a bug in Python. It looks to me like a configuration problem. I'm going to assume you have a good reason for bypassing your OS's package management system. In general, this is a bad idea, but since this isn't a linux administration list, I'll leave it at that. > Then I downloaded Samba with the following command: > git clone git://git.samba.org/samba.git samba-master > Then I installed the additional openldap-devel Library > then I did the ./configure --enable-debug --enable-selftest > then initiated the make command So you configured it, and built it, but did not install it, right? You didn't do a make install or make altinstall? Installing would presumably have put the files in the right place for them to be picked up by python. Since you just built samba without installing it, it looks like you have to point python to the right place. > When I do a find / - name samba.netcmd.main > > It pulls up: NOTHING!! Right, that's not surprising. samba.netcmd.main is a python package, not a module, so it won't be named samba.netcmd.main.py or whatever you were thinking. > If I pull up : find / -name netcmd > > I get: > > /root/samba-master/python/samba/netcmd > /root/samba-master/bin/python/samba/netcmd > /root/samba-master/bin/default/python/samba/netcmd > > In my research somebody said: to export the PYTHONPATH and to change it to the correct path of the netcmd command. You'll want to add the directory up to the "/python" bit. I'm not sure which one of those three is really the right location for the module you're looking for, but I would start by trying '/root/samba-master/bin/python'. From there, python should be able to find the samba package. > if I wanted to fix it permanently then to update my bash.rc file. > > In other words Tell my samba tool where to look, and this look is only temporary till I close my terminal. Placing the command in the bash.rc file will run this script every time I open my terminal. Well, I tried all 3 and none of them worked. This is not a good way to leave your system. It's okay if you're just testing the new samba build, but you really ought to install the software, not just run it out of the build directory. Best of all would be to install a version that's actually been packaged up for your OS using the CentOS packaging system. -- Jerry From ned at nedbatchelder.com Tue May 6 16:31:35 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 06 May 2014 16:31:35 -0400 Subject: Pass variable by reference In-Reply-To: <5368681D.8070602@islandtraining.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: On 5/6/14 12:42 AM, Gary Herron wrote: > This gets confusing, but in fact the most accurate answer is that Python > does not have "variables", so there is no such thing as passing > "variables" by reference or any other method. Python *does* have names > bound to values, but that's a very different thing. If necessary, you > may consider that the *values* are passed by reference. This meme bugs me so much. Python has variables. They work differently than variables in C. In fact, they work by having names bound to values. If you want to insist that Python has no variables, you will have to also say that neither do Javascript, Ruby, Java, PHP, etc. And if Javascript has no variables, what does the var keyword mean? -- Ned Batchelder, http://nedbatchelder.com From harrismh777 at gmail.com Tue May 6 16:36:12 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 06 May 2014 15:36:12 -0500 Subject: (question) How to use python get access to google search without query quota limit References: Message-ID: On 5/6/14 2:27 PM, Mark Lawrence wrote: >> will u please send me the code that you write. actually i'm trying to >> learn use of google search api but i'm not getting so please mail me the >> code. >> > > Sure but it's USD 1,000 cash or cheque made payable to the Python > Software Foundation, backed up by bankers card. > QOTW From torriem at gmail.com Tue May 6 16:57:12 2014 From: torriem at gmail.com (Michael Torrie) Date: Tue, 06 May 2014 14:57:12 -0600 Subject: Pass variable by reference In-Reply-To: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> Message-ID: <53694CA8.3020000@gmail.com> On 05/05/2014 06:39 PM, Satish Muthali wrote: > I want to nuke /var/lib/postgresql/9.3.4/main/data , however > programatically I want it to be as: /var/lib/postgresql/ pgversion>/main/data > > Any help is appreciated. Not sure really. But if you want to pass a some data around that can be manipulated "in place" as it were, say in a function, then yes it must be either a mutable object like a list or a dictionary, or you can wrap up your data in a class and manipulate it via an instance of that class that you pass around. You can do the same thing in a module too, actually, which is a form of singleton. Another solution is just to have a function return a new cooked string, based on a raw string passed in as a parameter. Perhaps if you explained more clearly your end goal, people could suggest ideas in accomplishing it in a way that works well in Python. From harrismh777 at gmail.com Tue May 6 17:00:19 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 06 May 2014 16:00:19 -0500 Subject: Pass variable by reference References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: On 5/6/14 3:31 PM, Ned Batchelder wrote: > On 5/6/14 12:42 AM, Gary Herron wrote: >> This gets confusing, but in fact the most accurate answer is that Python >> does not have "variables", so there is no such thing as passing >> "variables" by reference or any other method. Python *does* have names >> bound to values, but that's a very different thing. If necessary, you >> may consider that the *values* are passed by reference. > > This meme bugs me so much. Python has variables. They work differently > than variables in C. In fact, they work by having names bound to values. What does the word "variable" mean. Think BASIC variables. You can set them, you can reset them, you can delete them, you can change them. ... because they are variable. Python has names bound to objects... some of which you may not change. Once the name is bound to an object you may bind it to another object, but you may not change it, nor may you change the object it is bound to if the object is immutable. marcus From ned at nedbatchelder.com Tue May 6 17:27:18 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 06 May 2014 17:27:18 -0400 Subject: Pass variable by reference In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: On 5/6/14 5:00 PM, Mark H Harris wrote: > On 5/6/14 3:31 PM, Ned Batchelder wrote: >> On 5/6/14 12:42 AM, Gary Herron wrote: >>> This gets confusing, but in fact the most accurate answer is that Python >>> does not have "variables", so there is no such thing as passing >>> "variables" by reference or any other method. Python *does* have names >>> bound to values, but that's a very different thing. If necessary, you >>> may consider that the *values* are passed by reference. >> >> This meme bugs me so much. Python has variables. They work differently >> than variables in C. In fact, they work by having names bound to values. > > What does the word "variable" mean. Think BASIC variables. You can set > them, you can reset them, you can delete them, you can change them. ... > because they are variable. > > Python has names bound to objects... some of which you may not change. > Once the name is bound to an object you may bind it to another object, > but you may not change it, nor may you change the object it is bound to > if the object is immutable. I quite like the definition I found on Wikipedia: "a symbolic name associated with a value and whose associated value may be changed." The word "change" here is ambiguous: it could mean mutating an existing value, or rebinding to another value. While I can't mutate immutable values, I can always rebind a Python name to another value. Python cannot do "pass variable by reference", but not because it lacks variables. What it lacks is the ability to refer to a variable. Names cannot be referred to, so there is no way to refer to a variable. This is definitely different than C. You are right about the comparison to BASIC: BASIC's variables can always be mutated. Python's variables cannot always be, because some of them have immutable values (or happen to at the moment, they can always be rebound!) -- Ned Batchelder, http://nedbatchelder.com From Joshua.R.English at gmail.com Tue May 6 19:30:06 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Tue, 6 May 2014 16:30:06 -0700 (PDT) Subject: [ANNC] pybotwar-0.9 : now using pybox2d-2.3b0 In-Reply-To: References: Message-ID: <21f08814-f8e1-4c85-9dce-c1742dce9513@googlegroups.com> I loved RoboWar on my Mac, many ages ago. I wrote a Stack based language very similar to the one RoboWar used. If you're interested, let me know. Josh English On Saturday, May 3, 2014 3:28:34 PM UTC-7, Lee Harr wrote: > pybotwar is a fun and educational game where players > write computer programs to control simulated robots. > > http://pybotwar.googlecode.com/ > From rosuav at gmail.com Tue May 6 19:46:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 May 2014 09:46:16 +1000 Subject: Pass variable by reference In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: On Wed, May 7, 2014 at 7:00 AM, Mark H Harris wrote: > What does the word "variable" mean. Think BASIC variables. You can set them, > you can reset them, you can delete them, you can change them. ... because > they are variable. > > Python has names bound to objects... some of which you may not change. Once > the name is bound to an object you may bind it to another object, but you > may not change it, nor may you change the object it is bound to if the > object is immutable. Is this code mutating or rebinding? x = 1.1 y = 2.2 x = x + y What language did I write that in? Is there really a fundamental difference between languages in which that is equally valid syntax and does exactly the same thing? Apart from the fact that BASIC defaults to single-precision float (in the absence of a hash suffix), Python uses double-precision, and REXX uses decimal strings, this sequence will work identically in all of them. Does BASIC have variables? Presumably, since you can pass them by reference. Does REXX? You can't pass by reference (all you can do is EXPOSE, which is more like scoping rules, only it isn't); a C function can fiddle with any named variable in its caller's scope, so a common way to "return" multiple values is to pass the name of a stem (which isn't an array, and isn't a dict/mapping, and isn't really an object at all) into which the results will be placed. Python has objects and names, and changes which object a name is bound to. The mechanics differ, but fundamentally, x started out as 1.1 and ended up as 3.3. That means x varied in value, and is thus a variable. The differences are relatively insignificant. ChrisA From ben at benfinney.id.au Tue May 6 19:55:24 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 07 May 2014 09:55:24 +1000 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables=3F?= =?utf-8?Q?=E2=80=9D?= debate (was: Pass variable by reference) References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: <85zjiuea37.fsf_-_@benfinney.id.au> Ned Batchelder writes: > This meme bugs me so much. Python has variables. They work differently > than variables in C. Which is why it's useful to intervene right at the start when someone comes in with assumptions about ?variables?; it's better that they discard that baggage and learn about reference binding, instead. > In fact, they work by having names bound to values. My position is that this concept is sufficiently different to what most newcomers to Python mean by ?variable? (those who have the term at all; and for those who don't, no need to introduce potentially-confusing terms) that it's better to avoid that term entirely and immediately use more-accurate terminology. > If you want to insist that Python has no variables, you will have to > also say that neither do Javascript, Ruby, Java, PHP, etc. I don't know enough Ruby to comment there. For Java, Javascript, PHP, they *do* have variables that work pretty much as expected by these newcomers: the variables are declared and exist before a value is assigned, they have the ?box containing a value? conceptual model (as contrasted with Python's ?value with sticky-notes attached? model), the ?how do I pass by reference or by value?? question is meaningful ? all of these are significantly different in Python, so the term ?variable? is useful in those other languages but mostly just a confusing obstacle in learning Python. > And if Javascript has no variables, what does the var keyword mean? Exactly; JavaScript *does* have variables, in the ways Python does not. -- \ ?If you have the facts on your side, pound the facts. If you | `\ have the law on your side, pound the law. If you have neither | _o__) on your side, pound the table.? ?anonymous | Ben Finney From ben at benfinney.id.au Tue May 6 20:01:43 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 07 May 2014 10:01:43 +1000 Subject: [OT] Silde rules References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> <5369095e$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85vbtie9so.fsf@benfinney.id.au> Steven D'Aprano writes: > Guys, heaven knows I'm guilty of the occasional off-topic post myself, > and I'm not obsessive about these things, but there comes a time in every > off-topic thread where the right thing to do is to label it off-topic. > And this thread has long passed that time! Yes. Changing the Subject field, while retaining the References field, is how we make threads continue uninterrupted across a change of topic. Sadly, this standard method is both unfamiliar to a lot of forum users, and (reportedly) disrupts regressively buggy forum interfaces like Google Groups which have a stupid broken implementation of threads. The solution IMO is to discard Google Groups as irretrievably broken, but I don't have much hope for that. Meanwhile I advocate using the full features of Usenet and encouraging as many as possible to use proper clients. -- \ ?I was once walking through the forest alone and a tree fell | `\ right in front of me, and I didn't hear it.? ?Steven Wright | _o__) | Ben Finney From rosuav at gmail.com Tue May 6 20:11:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 May 2014 10:11:01 +1000 Subject: =?UTF-8?Q?Re=3A_The_=E2=80=9Cdoes_Python_have_variables=3F=E2=80=9D_debate_=28wa?= =?UTF-8?Q?s=3A_Pass_variable_by_reference=29?= In-Reply-To: <85zjiuea37.fsf_-_@benfinney.id.au> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> Message-ID: On Wed, May 7, 2014 at 9:55 AM, Ben Finney wrote: >> If you want to insist that Python has no variables, you will have to >> also say that neither do Javascript, Ruby, Java, PHP, etc. > > I don't know enough Ruby to comment there. For Java, Javascript, PHP, > they *do* have variables that work pretty much as expected by these > newcomers: the variables are declared and exist before a value is > assigned, they have the ?box containing a value? conceptual model (as > contrasted with Python's ?value with sticky-notes attached? model), the > ?how do I pass by reference or by value?? question is meaningful ? all > of these are significantly different in Python, so the term ?variable? > is useful in those other languages but mostly just a confusing obstacle > in learning Python. JS "variables" are just name bindings. Imagine this change to the Python parser: abolish the 'global' and 'nonlocal' keywords, and instead declare 'local' anything that you want to be function-local. (Always function-local. No actual change to Python byte-code.) Instead of looking for assignment and declaring local on that basis, you look for a 'local x' declaration. (Function parameters are, of course, implicitly local, as in current model.) Now just rename "local" to "var" and you have the JS scope model. You can't pass by reference in JS; you pass objects around, exactly as with Python. (With an exception with functions, where "x.y()" is different from "f=x.y; f()", which strikes me as brain-dead design.) You can have multiple names bound to the same object, and a mutation in one is seen in the others. Rebinding a name disconnects it from the previous binding. From what I can see, it's the same object model as Python uses. And people are happy to talk about JS variables. ChrisA From rosuav at gmail.com Tue May 6 20:13:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 May 2014 10:13:58 +1000 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: Message-ID: On Wed, May 7, 2014 at 4:16 AM, Terry Reedy wrote: > If the prepend requirement is covered by > > "The email package is a library for managing email messages, including MIME > and other RFC 2822-based message documents. It is specifically not designed > to do any sending of email messages to SMTP (RFC 2821), NNTP, or other > servers; those are functions of modules such as smtplib and nntplib. The > email package attempts to be as RFC-compliant as possible, supporting in > addition to RFC 2822, such MIME-related RFCs as RFC 2045, RFC 2046, RFC > 2047, and RFC 2231." > > and the current 3.4/5 version does not prepend and there is no existing > tracker issue, then a new issue would seem to be appropriate. That's a bit tricky. RFC 2822 section 3.6.7 says the Received: headers are "strictly informational, and any formal interpretation of them is outside of the scope of this document", but it does reference RFC 2821. Should the addition of another Received header be part of building an RFC 2822 compliant message, or should you build up a message without that, and have one added at transport time? I would say that, even if this isn't considered a bug (as in, failure to comply with standards it claims to comply with), it would still be a viable feature addition. ChrisA From steve+comp.lang.python at pearwood.info Tue May 6 21:14:02 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2014 01:14:02 GMT Subject: Pass variable by reference References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: <536988da$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 06 May 2014 16:31:35 -0400, Ned Batchelder wrote: > On 5/6/14 12:42 AM, Gary Herron wrote: >> This gets confusing, but in fact the most accurate answer is that >> Python does not have "variables", so there is no such thing as passing >> "variables" by reference or any other method. Python *does* have names >> bound to values, but that's a very different thing. If necessary, you >> may consider that the *values* are passed by reference. > > This meme bugs me so much. Python has variables. They work differently > than variables in C. In fact, they work by having names bound to > values. > > If you want to insist that Python has no variables, you will have to > also say that neither do Javascript, Ruby, Java, PHP, etc. And if > Javascript has no variables, what does the var keyword mean? It's Javascript, which is barely one step up from PHP regarding consistency. It could mean "constant" for all I know :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ From ned at nedbatchelder.com Tue May 6 21:19:36 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 06 May 2014 21:19:36 -0400 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: <85zjiuea37.fsf_-_@benfinney.id.au> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> Message-ID: On 5/6/14 7:55 PM, Ben Finney wrote: > Ned Batchelder writes: > >> This meme bugs me so much. Python has variables. They work differently >> than variables in C. > > Which is why it's useful to intervene right at the start when someone > comes in with assumptions about ?variables?; it's better that they > discard that baggage and learn about reference binding, instead. Where do you draw the line? Python ints work differently than C ints, but we don't seem to mind using the same word for them. Same for strings and functions. Python's classes work differently than C++ or Java's, but we don't say that Python has no classes. And let's not discuss Lisp's lists, Haskell's functions, or Modula-2's modules. So many terms are used and re-used, and each language has differences. Why is "variable" sacrosanct and can only be used to describe C semantics, but we're OK reusing class, int, and function? > >> In fact, they work by having names bound to values. > > My position is that this concept is sufficiently different to what most > newcomers to Python mean by ?variable? (those who have the term at all; > and for those who don't, no need to introduce potentially-confusing > terms) that it's better to avoid that term entirely and immediately use > more-accurate terminology. > >> If you want to insist that Python has no variables, you will have to >> also say that neither do Javascript, Ruby, Java, PHP, etc. > > I don't know enough Ruby to comment there. For Java, Javascript, PHP, > they *do* have variables that work pretty much as expected by these > newcomers: the variables are declared and exist before a value is > assigned, they have the ?box containing a value? conceptual model (as > contrasted with Python's ?value with sticky-notes attached? model), the > ?how do I pass by reference or by value?? question is meaningful ? all > of these are significantly different in Python, so the term ?variable? > is useful in those other languages but mostly just a confusing obstacle > in learning Python. As Chris A. has pointed out, Javascript works like Python, and not much like C. > >> And if Javascript has no variables, what does the var keyword mean? > > Exactly; JavaScript *does* have variables, in the ways Python does not. > -- Ned Batchelder, http://nedbatchelder.com From steve+comp.lang.python at pearwood.info Tue May 6 21:18:15 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2014 01:18:15 GMT Subject: Pass variable by reference References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> Message-ID: <536989d6$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 06 May 2014 15:16:54 -0400, Terry Reedy wrote: > On 5/5/2014 8:39 PM, Satish Muthali wrote: >> Hello experts, >> >> I have a burning question on how to pass variable by reference in >> Python. > > Python passes objects to functions. CPython implements this by passing > object pointers. In one sense, your request is impossible. In another, > it already happens. Pass *by* reference is not the same as pass *a* reference. Confusing variables, values and references to values is how you get Ruby programmers swearing that Ruby does pass by reference, and Java programmers swearing that Java does pass by value, for *exactly* the same behaviour that Python has. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Tue May 6 22:18:26 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 6 May 2014 19:18:26 -0700 (PDT) Subject: Pass variable by reference In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: On Wednesday, May 7, 2014 5:16:16 AM UTC+5:30, Chris Angelico wrote: > On Wed, May 7, 2014 at 7:00 AM, Mark H Harris wrote: > Is this code mutating or rebinding? > x = 1.1 > y = 2.2 > x = x + y Heh! Neat example! > What language did I write that in? Is there really a fundamental > difference between languages in which that is equally valid syntax and > does exactly the same thing? Apart from the fact that BASIC defaults > to single-precision float (in the absence of a hash suffix), Python > uses double-precision, and REXX uses decimal strings, this sequence > will work identically in all of them. Does BASIC have variables? > Presumably, since you can pass them by reference. Does REXX? You can't > pass by reference (all you can do is EXPOSE, which is more like > scoping rules, only it isn't); a C function can fiddle with any named > variable in its caller's scope, so a common way to "return" multiple > values is to pass the name of a stem (which isn't an array, and isn't > a dict/mapping, and isn't really an object at all) into which the > results will be placed. Python has objects and names, and changes > which object a name is bound to. > The mechanics differ, but fundamentally, x started out as 1.1 and > ended up as 3.3. That means x varied in value, and is thus a variable. > The differences are relatively insignificant. Wrong conclusion! These 3 lines look the same and amount to much the same in python and C. But as the example widens to something beyond 3 lines, the difference will become more and more significant OTOH... As for meaning of the word 'variable,' the way mathematicians use it seems to date to the 16th century: http://en.wikipedia.org/wiki/Variable_%28mathematics%29#Genesis_and_evolution_of_the_concept That is, its closer to the binding notion of python than the imperative notion of C like languages. However if we go further back, the book by Al-Khwarizmi is about al-Jabr ie the name of the guy who invented algebra is used for 'algorithm'!! I find this ironic, given this current discussion: - algorithm corresponds to the mutating notion - algebra corresponds to the non-mutating notion From jessica.mckellar at gmail.com Tue May 6 22:31:48 2014 From: jessica.mckellar at gmail.com (Jessica McKellar) Date: Tue, 6 May 2014 19:31:48 -0700 Subject: Python under the sea and in space Message-ID: Hi folks, I'm trying to determine the greatest depth (in the ocean or underground) and highest altitude at which Python code has been executed. Please note that I'm interested in where the code was executed, and not, say, where data that Python analyzed was acquired. I know for example that NASA has analyzed plenty of data from space in Python, but the analysis was done in labs here on Earth. :) Do you have some good candidates? Please let me know! Regards, -Jessica -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 6 22:39:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 May 2014 12:39:34 +1000 Subject: Pass variable by reference In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: On Wed, May 7, 2014 at 12:18 PM, Rustom Mody wrote: > Wrong conclusion! > > These 3 lines look the same and amount to much the same in python and C. > > But as the example widens to something beyond 3 lines, the difference > will become more and more significant Python, C, REXX, BASIC, and pretty much anything else with a broadly imperative style. The thing is, though, the difference between one language's variable semantics and another's is similar to, as Ned said, the difference between one language's integer semantics and another's. What happens in C when you do this? x = 1 << 31; x += x; The only possible answer is "it depends", as you can't know how big an int is, but certainly it's of finite size. In Python, the equivalent is guaranteed to put 2**32 into x, because integers store arbitrary precision. That's a pretty important difference, yet we're happy to call both "integer". A Python list is very different from a LISP list. A Python array is very different from a Pike array. A Python function is very different from a mathematical function. Why do we object to the difference in "variable" but not the others? Yes, there are differences. That's why we have different languages; you can't do a minimalist transformation of source code and expect exactly identical semantics. But we start with familiar names that will give people some idea of what's going on. ChrisA From rustompmody at gmail.com Tue May 6 22:54:28 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 6 May 2014 19:54:28 -0700 (PDT) Subject: Pass variable by reference In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: <5640dd17-29ba-4430-9b71-38be94c76a17@googlegroups.com> On Wednesday, May 7, 2014 8:09:34 AM UTC+5:30, Chris Angelico wrote: > On Wed, May 7, 2014 at 12:18 PM, Rustom Mody wrote: > > Wrong conclusion! > > These 3 lines look the same and amount to much the same in python and C. > > But as the example widens to something beyond 3 lines, the difference > > will become more and more significant > Python, C, REXX, BASIC, and pretty much anything else with a broadly > imperative style. > The thing is, though, the difference between one language's variable > semantics and another's is similar to, as Ned said, the difference > between one language's integer semantics and another's. What happens > in C when you do this? > x = 1 << 31; > x += x; > The only possible answer is "it depends", as you can't know how big an > int is, but certainly it's of finite size. In Python, the equivalent > is guaranteed to put 2**32 into x, because integers store arbitrary > precision. That's a pretty important difference, yet we're happy to > call both "integer". A Python list is very different from a LISP list. > A Python array is very different from a Pike array. A Python function > is very different from a mathematical function. Why do we object to > the difference in "variable" but not the others? > Yes, there are differences. That's why we have different languages; > you can't do a minimalist transformation of source code and expect > exactly identical semantics. But we start with familiar names that > will give people some idea of what's going on. The number of possible concepts is infinite The number of words is finite (even assuming unicode!!) IOW A combinatorial problem... From steve at pearwood.info Wed May 7 00:59:47 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 07 May 2014 04:59:47 GMT Subject: Pass variable by reference References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <5640dd17-29ba-4430-9b71-38be94c76a17@googlegroups.com> Message-ID: <5369bdc2$0$11109$c3e8da3@news.astraweb.com> On Tue, 06 May 2014 19:54:28 -0700, Rustom Mody wrote: > The number of possible concepts is infinite > > The number of words is finite (even assuming unicode!!) Not true. If you allow longer and longer words, with no upper limit, the number of words is also infinite. If you allow compound words (joined by spaces or hyphens), with no limit on the number of parts, the number of words is also infinite. > IOW A combinatorial problem... Not really. The problem is actually a compression problem, not a combinatorial problem. We have no difficulty in coming up with a (possibly very long) word for the concepts: C uses "32-bit-twos-complement-signed-integers"; Python uses "twos-complement-signed-big-integer-objects" but since programmers are lazy, we like short names for things, and the more frequently we use something, the shorter we like it. Hence we apply lossy compression to the concepts to get short names: C uses ints; Python uses ints and the distinction between the two is lost. -- Steven From marko at pacujo.net Wed May 7 02:18:29 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 07 May 2014 09:18:29 +0300 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> Message-ID: <8738gmxgay.fsf@elektro.pacujo.net> Ned Batchelder : > Why is "variable" sacrosanct and can only be used to describe C > semantics, but we're OK reusing class, int, and function? The Python language specification calls them variables; the terminology discussion should end there. The complaint against variables seems to hinge on the fact that Python variables are not first-class objects. A manifestation of that is that you can't pass variables by reference to functions. Actually, while Python variables are not first-class objects, one could see them as dictionary-key pairs. So you can even pass them by reference by passing the dictionary and the key. Then the problem is lists. You can't represent a list element as a dictionary-key pair. Or can you? A list can be viewed as a "dictionary" whose key is an integer. Thus, the same pass-by-reference technique would work for lists as well. Marko From dieter at handshake.de Wed May 7 02:43:16 2014 From: dieter at handshake.de (dieter) Date: Wed, 07 May 2014 08:43:16 +0200 Subject: xmlrpc: problems with socket handling, close, shutdown of server, TIME_WAIT, ... References: <01237970-87cd-4d29-a944-09e64b8efeee@googlegroups.com> Message-ID: <878uqe143f.fsf@handshake.de> thomas.lehmann.private at googlemail.com writes: > ... > taking the xml-rpc derived from standard example is working - basically - but with following scenario I do not understand the problem. Maybe you can help: > > - one Unittest that does create the xmlrpc server in a thread > in "setUp" and shutdown of it in tearDown. > The xml-rcp server does store/load a value for a key. > (It's for testing/learning purpose) > > Problem(s): > > - If I run the test method twice (copy and paste and rename) > then I get a "error: [Errno 98] Address already in use" > (I assumend the tearDown would have closed all sockets) For reliability reasons (their might be (communication) packets under way that may arrive at the wrong partner), a port stays "in use" for twice (I think) the maximal packet lifetime after its "shutdown". This is a TCP (not a Python) property. There is a TCP(socket) option to supress this. For the details, consult the TCP specification. From dieter at handshake.de Wed May 7 02:48:29 2014 From: dieter at handshake.de (dieter) Date: Wed, 07 May 2014 08:48:29 +0200 Subject: Problems with ZODB, I can not persist and object accessed from 2 threads References: <87iopjyxsj.fsf@handshake.de> Message-ID: <874n1213uq.fsf@handshake.de> Dennis Lee Bieber writes: > On Tue, 06 May 2014 13:03:08 +0200, dieter declaimed > the following: > >> >>The database (we have called it "db") is global to all threads. >>Each thread must open (and maybe close) its own connection to the >>global database. You must never share the same connection or >>objects loaded via the connection between threads - very weird >>(and apparently non-deterministic) errors can result. >> > Actually, one should study the documentation for the dbapi adapter > being used -- some may allow the connection (db = adapter.connect(...)) to > be shared by threads, but require each thread to create its own cursor (cur > = db.cursor()) We are speaking here about the ZODB (= "Zope Object DataBase"). This is not a relational database - and does not have cursors (just databases, transactions and connections). From antoon.pardon at rece.vub.ac.be Wed May 7 02:58:45 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 07 May 2014 08:58:45 +0200 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: Message-ID: <5369D9A5.4040706@rece.vub.ac.be> On 05-05-14 21:51, Grant Edwards wrote: > I'm working on a Python app that receives an e-mail message via SMTP, > does some trivial processing on it, and forwards it to another SMTP > server. > > I'd like to do the polite thing and add a "Received:" header, but I > can't figure out how to get Python's email module to add it in the > correct place. It always ends up at the "bottom" of the headers below > From: To: etc. It's supposed to go at the above all the Received: > headers that where there when I received it. I thought that was the job of the SMTP servers, not of email applications. So I'm not sure that what you want to do is the polite thing to do. -- Antoon Pardon From emre at hasegeli.com Wed May 7 04:11:30 2014 From: emre at hasegeli.com (Emre Hasegeli) Date: Wed, 7 May 2014 11:11:30 +0300 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: <5369D9A5.4040706@rece.vub.ac.be> References: <5369D9A5.4040706@rece.vub.ac.be> Message-ID: Antoon Pardon : > I'm working on a Python app that receives an e-mail message via SMTP, > > does some trivial processing on it, and forwards it to another SMTP > > server. > > > > I'd like to do the polite thing and add a "Received:" header, but I > > can't figure out how to get Python's email module to add it in the > > correct place. It always ends up at the "bottom" of the headers below > > From: To: etc. It's supposed to go at the above all the Received: > > headers that where there when I received it. > > I thought that was the job of the SMTP servers, not of email > applications. So I'm not sure > that what you want to do is the polite thing to do. > This application seems like an SMTP server. -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed May 7 04:51:55 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 07 May 2014 09:51:55 +0100 Subject: The =?windows-1252?Q?=93does_Python_have_variables=3F=94?= =?windows-1252?Q?_debate?= In-Reply-To: <8738gmxgay.fsf@elektro.pacujo.net> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: On 07/05/2014 07:18, Marko Rauhamaa wrote: > Ned Batchelder : > >> Why is "variable" sacrosanct and can only be used to describe C >> semantics, but we're OK reusing class, int, and function? > > The Python language specification calls them variables; the terminology > discussion should end there. > I entirely agree. This discussion has been done to death an infinite number of times. It fits into my "I couldn't care less" category, I just want to write code. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From antoon.pardon at rece.vub.ac.be Wed May 7 04:57:51 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 07 May 2014 10:57:51 +0200 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: <5369D9A5.4040706@rece.vub.ac.be> Message-ID: <5369F58F.2060703@rece.vub.ac.be> On 07-05-14 10:11, Emre Hasegeli wrote: > Antoon Pardon >: > > > I'm working on a Python app that receives an e-mail message via > SMTP, > > does some trivial processing on it, and forwards it to another SMTP > > server. > > > > I'd like to do the polite thing and add a "Received:" header, but I > > can't figure out how to get Python's email module to add it in the > > correct place. It always ends up at the "bottom" of the headers > below > > From: To: etc. It's supposed to go at the above all the Received: > > headers that where there when I received it. > > I thought that was the job of the SMTP servers, not of email > applications. So I'm not sure > that what you want to do is the polite thing to do. > > > This application seems like an SMTP server. > It doesn't to me. As far as I can see what he wants to do can be done by a mail program like procmail in combination with some mail filtering/processing. -- Antoon Pardon -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at reportlab.com Wed May 7 06:42:24 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 07 May 2014 11:42:24 +0100 Subject: data: protocol Message-ID: <536A0E10.5030402@chamonix.reportlab.co.uk> I have an outstanding request for ReportLab to allow images to be opened using the data: scheme. That used to be supported in python 2.7 using urllib, but in python 3.3 urllib2 --> urllib and at least the default urlopener doesn't support data: Is there a way to use the residual legacy of the old urllib code that's now in urllib.URLopener to open unusual schemes? I know it can be used directly eg urllib.request.URLopener().open('data:.........') but that seems to leave the splitting & testing logic up to me when it logically belongs in some central place ie urllib.request.urlopen. -- Robin Becker From jason.mellone at gmail.com Wed May 7 07:55:11 2014 From: jason.mellone at gmail.com (Jason Mellone) Date: Wed, 7 May 2014 04:55:11 -0700 (PDT) Subject: Common issue but unable to find common solution (ez_setup.py on PC) Message-ID: <253cc793-655e-4b7d-a167-73bb8bebde90@googlegroups.com> Hello, By way of google I realize I am having what appears to be a pretty common issue install ez_setup.py on a PC (Windows XP, Python27). I receive an error message that looks like the following: Installing easy_install-2.7.exe.manifest script to C:\Python27\Scripts Installed c:\python27\lib\site-packages\setuptools-3.5.1-py2.7.egg Processing dependencies for setuptools==3.5.1 Traceback (most recent call last): File "setup.py", line 217, in dist = setuptools.setup(**setup_params) File "C:\Python27\lib\distutils\core.py", line 152, in setup dist.run_commands() File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands self.run_command(cmd) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\setuptools\co mmand\install.py", line 65, in run self.do_egg_install() File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\setuptools\co mmand\install.py", line 115, in do_egg_install cmd.run() File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\setuptools\co mmand\easy_install.py", line 360, in run self.easy_install(spec, not self.no_deps) File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\setuptools\co mmand\easy_install.py", line 576, in easy_install return self.install_item(None, spec, tmpdir, deps, True) File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\setuptools\co mmand\easy_install.py", line 627, in install_item self.process_distribution(spec, dist, deps) File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\setuptools\co mmand\easy_install.py", line 673, in process_distribution [requirement], self.local_index, self.easy_install File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\pkg_resources .py", line 633, in resolve requirements.extend(dist.requires(req.extras)[::-1]) File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\pkg_resources .py", line 2291, in requires dm = self._dep_map File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\pkg_resources .py", line 2277, in _dep_map for extra, reqs in split_sections(self._get_metadata(name)): File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\pkg_resources .py", line 2715, in split_sections for line in yield_lines(s): File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\pkg_resources .py", line 1989, in yield_lines for ss in strs: File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\pkg_resources .py", line 2305, in _get_metadata for line in self.get_metadata_lines(name): File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\pkg_resources .py", line 1369, in get_metadata_lines return yield_lines(self.get_metadata(name)) File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\pkg_resources .py", line 1361, in get_metadata return self._get(self._fn(self.egg_info, name)) File "c:\docume~1\jason\locals~1\temp\tmpqpn4qe\setuptools-3.5.1\pkg_resources .py", line 1425, in _get return self.loader.get_data(path) zipimport.ZipImportError: bad local file header in c:\python27\lib\site-packages \setuptools-3.5.1-py2.7.egg Something went wrong during the installation. See the error message above. C:\Python27>python ez_setup.py Is there a common solution for this issue? Thank you very much. From sjmsoft at gmail.com Wed May 7 08:17:14 2014 From: sjmsoft at gmail.com (sjmsoft at gmail.com) Date: Wed, 7 May 2014 05:17:14 -0700 (PDT) Subject: Python under the sea and in space In-Reply-To: References: Message-ID: <1ea091fc-d271-4f08-ab70-edfae941bf82@googlegroups.com> I don't suppose "eight miles high" in the figurative sense counts? Cheers, Steve J. Martin From acewebacademy at gmail.com Wed May 7 09:33:42 2014 From: acewebacademy at gmail.com (AWA Hyd) Date: Wed, 7 May 2014 06:33:42 -0700 (PDT) Subject: Good things come in small packages -Choose AWA s pay per click training programs! Message-ID: <0e73ee58-ec2d-4352-a96e-aedf837e6766@googlegroups.com> Effective marketing lies in understanding the behavior of an average user as he uses the internet. Since most users access the internet with a purpose which is in most cases to look for information, search engines revolve around the most likely key phrases or words used by the user to launch such a search. And hence if your website or blog or any piece of content is "optimized" to play within the search engine s rule, you may find your website listed in the first few results of the SERP or (Search Engine Results Page). Easier said than done, is it not really? PPC or pay per click campaign is that component of search engine marketing which is a type of sponsored online advertising used on a wide range of websites, and including search engines. In this type of online advertising the advertiser pay only if a web user clicks on the particular listed advertisement and hence the namesake- 'pay per click.' Behind the scenes of a PPC campaign- To begin with Advertisers place bids on these identified or likely keywords or phrases which their target audience would type in a search field in an attempt to look the particular product or service. Thereon when the user uses these words in the search query which match these identified words /phrases or possibly visits the web page with content containing these keywords or phrases so chosen, this PPC ad may be displayed on the page. With respect to display on search engines, a PPC ad is generally strategically placed just above or to the right of the search results for stronger visibility to the target audience. In websites however, the ad will be placed in a location which is deemed to be most advantageous to the site as well as the advertiser. So as to clearly differentiate PPC ads from the regular or organic search results that are displayed on a page, these PPC ads are mostly placed under "Sponsored Ads" or "Sponsored Links" for users to view them better above other text or competitor content. Overall, PPC ads are planned campaigns that are beneficial to advertisers and web users alike with measurable results. In a nut shell- * PPC helps you gather specific feedback on market conditions. * You are able to assess live audience, accordingly test and gather results. * You test water with a prototype floated around to track demand and feedback and accordingly step into a new venture. Launching a focused and effective PPC campaign will require the right foundation in ad words, understanding of search engines and the behavior of the target audience. It is imperative to learn a structured course on PPC and ad words from the right training institute and begin work on your website. At Ace web academy, we provide you with just the right foundation on PPC fundamentals to advanced concepts; a comprehensive training program from the experts at a reasonable cost! Need you ask for more? From jurko.gospodnetic at pke.hr Wed May 7 09:44:14 2014 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Wed, 07 May 2014 15:44:14 +0200 Subject: Common issue but unable to find common solution (ez_setup.py on PC) In-Reply-To: <253cc793-655e-4b7d-a167-73bb8bebde90@googlegroups.com> References: <253cc793-655e-4b7d-a167-73bb8bebde90@googlegroups.com> Message-ID: <536A38AE.9010302@pke.hr> Hi. On 7.5.2014. 13:55, Jason Mellone wrote: > By way of google I realize I am having what appears to be > a pretty common issue install ez_setup.py on a PC (Windows XP, Python27). > > I receive an error message that looks like the following: > > Installing easy_install-2.7.exe.manifest script to C:\Python27\Scripts > >[...snipped a long traceback...] > return self.loader.get_data(path) > zipimport.ZipImportError: bad local file header in c:\python27\lib\site-packages > \setuptools-3.5.1-py2.7.egg > Something went wrong during the installation. > See the error message above. You can run into this when attempting to upgrade an existing setuptools installation packaged as a zipped egg (due to some old zipimporter caches not getting cleaned up correctly). > Is there a common solution for this issue? It has already been reported and a patch has been prepared. See the following: https://bitbucket.org/pypa/setuptools/issue/168 https://bitbucket.org/pypa/setuptools/pull-request/48 But the patch is still waiting on the maintainer to apply it. Hope this helps. Best regards, Jurko Gospodneti? From ethan at stoneleaf.us Wed May 7 09:00:35 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 07 May 2014 06:00:35 -0700 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: <8738gmxgay.fsf@elektro.pacujo.net> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: <536A2E73.5030106@stoneleaf.us> On 05/06/2014 11:18 PM, Marko Rauhamaa wrote: > > Actually, while Python variables are not first-class objects, one could > see them as dictionary-key pairs. So you can even pass them by reference > by passing the dictionary and the key. Well, you could pass them that way, but not necessarily change them: --> def func1(): ... a = 1 ... b = 2 ... swap(locals(), 'a', 'b') ... print a ... print b ... --> def swap(d, key1, key2): ... print d[key1], d[key2] ... d[key1], d[key2] = d[key2], d[key1] ... print d[key1], d[key2] ... --> func1() 1 2 2 1 1 2 -- ~Ethan~ From jason.mellone at gmail.com Wed May 7 09:52:16 2014 From: jason.mellone at gmail.com (Jason Mellone) Date: Wed, 7 May 2014 06:52:16 -0700 (PDT) Subject: Common issue but unable to find common solution (ez_setup.py on PC) In-Reply-To: References: <253cc793-655e-4b7d-a167-73bb8bebde90@googlegroups.com> Message-ID: <50b03208-8a61-43fc-890e-09992c4c4759@googlegroups.com> On Wednesday, May 7, 2014 9:44:14 AM UTC-4, Jurko Gospodneti? wrote: > Hi. > > > > On 7.5.2014. 13:55, Jason Mellone wrote: > > > By way of google I realize I am having what appears to be > > > a pretty common issue install ez_setup.py on a PC (Windows XP, Python27). > > > > > > I receive an error message that looks like the following: > > > > > > Installing easy_install-2.7.exe.manifest script to C:\Python27\Scripts > > > > > >[...snipped a long traceback...] > > > return self.loader.get_data(path) > > > zipimport.ZipImportError: bad local file header in c:\python27\lib\site-packages > > > \setuptools-3.5.1-py2.7.egg > > > Something went wrong during the installation. > > > See the error message above. > > > > You can run into this when attempting to upgrade an existing > > setuptools installation packaged as a zipped egg (due to some old > > zipimporter caches not getting cleaned up correctly). > > > > > > > Is there a common solution for this issue? > > > > It has already been reported and a patch has been prepared. See the > > following: > > > > https://bitbucket.org/pypa/setuptools/issue/168 > > https://bitbucket.org/pypa/setuptools/pull-request/48 > > > > But the patch is still waiting on the maintainer to apply it. > > > > > > Hope this helps. > > > > Best regards, > > Jurko Gospodneti? So, is the answer: 1 - Until the patch is applied there is no answer or 2 - I can go in and manually modify the code, and have the ez setup work? From rosuav at gmail.com Wed May 7 10:14:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 00:14:27 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDigJxkb2VzIFB5dGhvbiBoYXZlIHZhcmlhYmxlcz/igJ0gZGViYXRl?= In-Reply-To: <536A2E73.5030106@stoneleaf.us> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <536A2E73.5030106@stoneleaf.us> Message-ID: On Wed, May 7, 2014 at 11:00 PM, Ethan Furman wrote: > On 05/06/2014 11:18 PM, Marko Rauhamaa wrote: >> >> Actually, while Python variables are not first-class objects, one could >> see them as dictionary-key pairs. So you can even pass them by reference >> by passing the dictionary and the key. > > > Well, you could pass them that way, but not necessarily change them: > [ chomp demo code using locals() ] That's because, while you can *think of* Python name bindings as being like dict key/value pairs, they aren't always that. Function locals, class locals, and other such namespaces aren't necessarily implemented with dicts. They're conceptually still a "dictionary" of sorts, but you can't actually pass anyone a dict and key and expect it to work. ChrisA From marko at pacujo.net Wed May 7 10:17:23 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 07 May 2014 17:17:23 +0300 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: <87r445hdvw.fsf@elektro.pacujo.net> Ethan Furman : > On 05/06/2014 11:18 PM, Marko Rauhamaa wrote: >> Actually, while Python variables are not first-class objects, one >> could see them as dictionary-key pairs. So you can even pass them by >> reference by passing the dictionary and the key. > > Well, you could pass them that way, but not necessarily change them: Weird. Some other tests of mine did work. But: Note: The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter. [] Marko From marko at pacujo.net Wed May 7 10:20:28 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 07 May 2014 17:20:28 +0300 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <536A2E73.5030106@stoneleaf.us> Message-ID: <87mwethdqr.fsf@elektro.pacujo.net> Chris Angelico : > That's because, while you can *think of* Python name bindings as being > like dict key/value pairs, they aren't always that. Function locals, > class locals, and other such namespaces aren't necessarily implemented > with dicts. They're conceptually still a "dictionary" of sorts, but > you can't actually pass anyone a dict and key and expect it to work. I see that as a glitch in the Matrix. Marko From rosuav at gmail.com Wed May 7 10:30:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 00:30:29 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDigJxkb2VzIFB5dGhvbiBoYXZlIHZhcmlhYmxlcz/igJ0gZGViYXRl?= In-Reply-To: <87r445hdvw.fsf@elektro.pacujo.net> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87r445hdvw.fsf@elektro.pacujo.net> Message-ID: On Thu, May 8, 2014 at 12:17 AM, Marko Rauhamaa wrote: > Weird. Some other tests of mine did work. But: > > Note: The contents of this dictionary should not be modified; changes > may not affect the values of local and free variables used by the > interpreter. [ https://docs.python.org/2/library/functions.html#locals>] If you test locals() at module level (including the interactive interpreter), things will work, because it just returns the same dict as globals() returns. It's only inside an actual function that it's different and magical. ChrisA From invalid at invalid.invalid Wed May 7 10:32:43 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 May 2014 14:32:43 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? References: Message-ID: On 2014-05-07, Antoon Pardon wrote: > On 05-05-14 21:51, Grant Edwards wrote: >> I'm working on a Python app that receives an e-mail message via SMTP, >> does some trivial processing on it, and forwards it to another SMTP >> server. >> >> I'd like to do the polite thing and add a "Received:" header, but I >> can't figure out how to get Python's email module to add it in the >> correct place. It always ends up at the "bottom" of the headers below >> From: To: etc. It's supposed to go at the above all the Received: >> headers that where there when I received it. > > I thought that was the job of the SMTP servers, not of email > applications. Exactly. And the SMTP server I'm writing uses the email module to manipulate headers as messages are processed. > So I'm not sure that what you want to do is the polite thing to do. Why not? -- Grant Edwards grant.b.edwards Yow! Th' MIND is the Pizza at Palace of th' SOUL gmail.com From invalid at invalid.invalid Wed May 7 10:33:27 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 May 2014 14:33:27 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? References: <5369D9A5.4040706@rece.vub.ac.be> Message-ID: On 2014-05-07, Antoon Pardon wrote: > On 07-05-14 10:11, Emre Hasegeli wrote: >> Antoon Pardon > >: >> >> > I'm working on a Python app that receives an e-mail message via >> SMTP, >> > does some trivial processing on it, and forwards it to another SMTP >> > server. >> > >> > I'd like to do the polite thing and add a "Received:" header, but I >> > can't figure out how to get Python's email module to add it in the >> > correct place. It always ends up at the "bottom" of the headers >> below >> > From: To: etc. It's supposed to go at the above all the Received: >> > headers that where there when I received it. >> >> I thought that was the job of the SMTP servers, not of email >> applications. So I'm not sure >> that what you want to do is the polite thing to do. >> >> >> This application seems like an SMTP server. > > It doesn't to me. As far as I can see what he wants to do can be done > by a mail program like procmail in combination with some mail > filtering/processing. Does procmail implement the server-side of SMTP? -- Grant Edwards grant.b.edwards Yow! I brought my BOWLING at BALL -- and some DRUGS!! gmail.com From burak.arslan at arskom.com.tr Wed May 7 11:06:31 2014 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Wed, 07 May 2014 18:06:31 +0300 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: Message-ID: <536A4BF7.6040000@arskom.com.tr> On 05/06/14 18:26, Grant Edwards wrote: > On 2014-05-06, Burak Arslan wrote: >> On 05/06/14 12:47, Chris Angelico wrote: >>> On Tue, May 6, 2014 at 7:15 PM, alister >>> wrote: >>>> On Mon, 05 May 2014 19:51:15 +0000, Grant Edwards wrote: >>>> >>>>> I'm working on a Python app that receives an e-mail message via SMTP, >>>>> does some trivial processing on it, and forwards it to another SMTP >>>>> server. >>>>> >>>>> I'd like to do the polite thing and add a "Received:" header, but I >>>>> can't figure out how to get Python's email module to add it in the >>>>> correct place. It always ends up at the "bottom" of the headers below >>>>> From: To: etc. It's supposed to go at the above all the Received: >>>>> headers that where there when I received it. >>>> Is this required or just being polite? >>>> what I mean is does the standard state the headers must be in a >>>> particular order or can they appear anywhere, you may be spending time >>>> trying to resolve an issue that does not need fixing. >>> Yes, it's required. RFC 2821 [1] section 3.8.2 says "prepend". >> The rationale for "prepend" is to make it possible for MTAs to add >> their "Received:" headers to messages without having to parse them. >> >> So you're supposed to do the same: Just write your Received header, >> followed by '\r\n', followed by the rest of the message to the socket >> and you should be fine. > I need to check and manipulate other headers for other reasons, so I'm > using the email module for that. In order to keep things consistent > and easy to understand, I'd like to use the email module to prepend > the Received header as well. That keeps my application from having to > have any knowledge about e-mail message formatting. > Seeing how discussion is still going on about this, I'd like to state once more what I said above in other words: You just need to do this: "Received: blah\r\n" + message.to_string() or better: socket.write("Received: blah\r\n") socket.write(message.to_string()) And again, this is not a hack, this is how it's supposed to work. Burak From boolegue at gmail.com Wed May 7 11:06:55 2014 From: boolegue at gmail.com (antoine) Date: Wed, 7 May 2014 08:06:55 -0700 (PDT) Subject: Normal dict behavior? Message-ID: <18f61e5d-f47b-4373-a835-67c6f20ef3d1@googlegroups.com> Hi, Python 2.7.5 (default, Nov 20 2013, 14:20:58) [GCC 4.7.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> {0.: None, 0:None} {0.0: None} The second item disappeared! Why? Is it normal? From rosuav at gmail.com Wed May 7 11:11:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 01:11:41 +1000 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: <536A4BF7.6040000@arskom.com.tr> References: <536A4BF7.6040000@arskom.com.tr> Message-ID: On Thu, May 8, 2014 at 1:06 AM, Burak Arslan wrote: > Seeing how discussion is still going on about this, I'd like to state > once more what I said above in other words: You just need to do this: > > "Received: blah\r\n" + message.to_string() > > or better: > > socket.write("Received: blah\r\n") > socket.write(message.to_string()) > > And again, this is not a hack, this is how it's supposed to work. Yes, that method does work... if you're taking it in and sending it right out again. But it means you have to hang onto two pieces of data - the message and the new Received header - until you write it to a file/socket. (By the way, side point: I tend to avoid calling a socket "socket", as that's the name of the module. I'd use "sock" in examples. Otherwise someone's liable to go digging for a top-level method "write" in the "socket" module, and get confused. And then think that sockets are confusing, which they're not!) ChrisA From bv4bv4bv4 at gmail.com Wed May 7 11:15:04 2014 From: bv4bv4bv4 at gmail.com (bv4bv4bv4 at gmail.com) Date: Wed, 7 May 2014 08:15:04 -0700 (PDT) Subject: Why Islam? The Beauty and Benefits of Islam Message-ID: Why Islam? The Beauty and Benefits of Islam Are all religions the same? How do I know which is correct? Why should I choose Islam? This pamphlet aims to discuss some of the beauties, benefits and unique aspects of Islam as compared to other beliefs and religions. 1. Close Relationship with the Creator At the core of Islam is the focus of an individual's personal relationship with God, their Creator. It encourages a believer to have sustained awareness of God which is a key to lasting happiness. Islam teaches that God is the source of peace. By focusing on this important relationship and following God's guidance, believers will be able to acquire inner peace and tranquillity. Seeking lasting happiness through other means, such as following one's desires or the accumulation of material possessions, will never fill the void we have. This need can only be filled with the awareness of God. True contentment is found in acknowledging and obeying the Creator: "Truly, in remembering God do hearts find rest." Quran 13:28 The primary reason for this close relationship is that Muslims have a direct connection with their Creator. There is no intermediary, such as praying to, or through, others, in worshipping God. 2. Positive Outlook on Life Islam gives a person a clear perspective on the events that happen in their life, both good and bad, as they are, in fact, tests from God. It encourages a person to understand events in the context of the overall purpose of life, which is to acknowledge God and obey Him. He created humans with intellect and free will to test them as to who will wilfully choose to follow His guidance. This life is an ultimate testing ground and although we cannot control everything that happens to us, we can control how we react. Islam encourages a person to focus on what is in their control, to be grateful to God for blessings, and to be patient during hardships. Patience or gratitude - this is the formula for a happy life. Islam encourages the believer to remain free from the extremes of worldly happiness that may cause one to forget God, and the extremes of sadness that may cause one to lose hope and blame God. By not being overly attached to the material world, a Muslim is empowered not only to better handle any calamities, but to be beneficial and generous to society. This leads to a more balanced and optimistic outlook on life. 3. Pure and Clear Concept of God Unlike other religions, Islam is not named after its founder or the community of its birth. Islam is an attributive title that signifies obedience to God, the Creator of the Universe. One of its main beauties is that it acknowledges the complete perfection, greatness and uniqueness of God with absolutely no compromises. This is reflected in Islam's pure teachings of the attributes of God. God is One and Unique: God has no partners, no equals and no rivals. God has no father, mother, sons, daughters or wives. God alone is worthy of all worship. God is the All-Powerful: God has full authority and power over all things. Obedience to God does not increase His Power, nor does disobedience decrease His power. God is the Most High: There is nothing above or comparable to God. The attributes of God do not resemble that of His creation. No part of God is present in anyone or anything. God is Perfect: God does not have any human limitations, such as resting on the seventh day after He created the universe. God always maintains attributes of perfection and does not do anything to compromise this perfection such as "becoming a man" as claimed by other religions. God does not do ungodly acts, so if God became man and took on human attributes, he would, necessarily, no longer be God. 4. Emphasises Both Evidence and Faith Islam is a religion in which faith is based on clear proof. It encourages people to use their God given intelligence to think and ponder over their life and the universe. Although this life is a test, God has provided sufficient signs and guidance to people who are open-minded and sincere to be able to acknowledge the truth. "We (God) have certainly sent down Signs that make things clear: and God guides whom He wills to the straight path."Quran 24:46 Unlike other religions, there are many clear proofs, signs and miracles that the book of Islam, The Quran, is from God. The Quran: Is free from any errors or contradictions, despite it being revealed over a period of 23 years. Is preserved, word-for-word, since it was revealed in its original Arabic language, unlike other scriptures which have been distorted, changed or lost. Contains a simple, pure and universal message that has a profound effect on all those who are sincerely searching for the truth. Contains a unique and inimitable style of language that is universally known as the pinnacle of Arabic eloquence and linguistic beauty - yet the Quran was revealed to Prophet Muhammad (peace be upon him) who was known to be illiterate. Contains many amazing scientific facts which have only been discovered recently, despite being revealed over 1400 years ago. The most rational explanation for the many unique and miraculous aspects of the Quran is that it cannot be from other than God. 5. Forgiveness of Sins Islam encourages a balance between hope in God's mercy and fear of His punishment - both of which are required to lead a positive and humble life. We are born sinless but have the free will to commit sins. God created us and knows we are imperfect and commit sins, but the key is how we react to committing those mistakes. "Do not despair of God's mercy; He will forgive you of all your sins."Quran 39:53 Islam teaches that God is the Most Merciful and will forgive and pardon those who sincerely want to repent. The beautiful steps for repentance include being sincere, remorseful, refraining from committing the sin as well as having the intention not to repeat it. Islam encourages a continuous process of self-development and self-purification. This process happens directly between the individual and God - there is no need for sins to be shared or "confessed" to a righteous person/priest. Furthermore, God does not need to sacrifice himself to forgive sins, nor is anyone "born into sin". 6. Accountability and Ultimate Justice Islam teaches that God is the Most Just and that each person will be held responsible for their own actions on the Day of Judgement. Each person is accountable, as they have freedom of choice and intelligence to discern between right and wrong. It is an absolute demand of justice that there be a Day of Judgement where every person is rewarded or punished, otherwise life would be unjust as not everyone receives true justice in this world. Islam teaches that ultimately we will be judged for how well we fulfilled our responsibilities and exercised our free will. We will be judged by God, the All Knowing and All Wise, who knows and sees everything we do. This encourages a more harmonious society and gives people contentment knowing that justice will ultimately prevail. 7. Practical and Balanced Way of Life Islam provides the right balance between faith and action, as both are required for a stable life. It provides guidance for all situations and circumstances. It is a practical religion with practical acts of worship that are designed to fulfil the spiritual, physical, psychological and social needs of people. Examples of practical acts of worship that have numerous benefits include: The five daily prayers - Enriches the soul by satisfying the spiritual need of being in regular contact with God (especially in today's busy lifestyle); makes one humble by bowing and prostrating to God; removes any barriers/pride/racism between believers praying in congregation; helps one refrain from committing sins given the person stands regularly before God. The obligatory charity - Purifies a person from selfishness; encourages empathy to the poor; reminds one of the blessings of God; helps reduce poverty; bridges the gap between rich and poor. The fasting in Ramadan - Promotes spiritual self-purification, self-restraint and growth; scientifically proven health benefits; empathy and awareness of those less fortunate; trains people to acquire the habit of obeying God. The pilgrimage - Unites people of every colour, race, status and nationality, as pilgrims wear simple and similar clothing, while performing a range of good deeds in congregation. Given that Islam is from God, every command found in the religion is ultimately good and beneficial to the individual and society when practised correctly. Quranic examples include being honest, forgiving, truthful, kind to one's wife, patient, fair, moderate, modest, sincere, and respecting parents, family and the elderly. There are also many principles in the teachings of Islam that prevent or reduce many of the individual and social ills facing the world today. 8. Universal and Timeless Message Islam has a message that applies to all people at all times, from the creation of Adam up until the Day of Judgement. It is applicable today as it always has been. God is accessible to everyone. People may distinguish themselves and earn God's favour through belief and righteous actions only - not through race, wealth, gender, nationality or social class. Conclusion Islam's timeless and beautiful message is the same message of all Prophets, including Noah, Abraham, Moses, Jesus and Muhammad (peace be upon them all). They all called their people to "Submit to the One True God" which, in Arabic, means to become a "Muslim". This submission to God enables one to fulfil the purpose of life by acknowledging the greatness of God and sincerely worshipping him alone. In doing so, one will acquire the countless benefits of Islam mentioned above. http://islamicpamphlets.com/why-islam-the-beauty-and-benefits-of-islam/ Thank you From ned at nedbatchelder.com Wed May 7 11:20:33 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 07 May 2014 11:20:33 -0400 Subject: Normal dict behavior? In-Reply-To: <18f61e5d-f47b-4373-a835-67c6f20ef3d1@googlegroups.com> References: <18f61e5d-f47b-4373-a835-67c6f20ef3d1@googlegroups.com> Message-ID: On 5/7/14 11:06 AM, antoine wrote: > Hi, > > Python 2.7.5 (default, Nov 20 2013, 14:20:58) > [GCC 4.7.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> {0.: None, 0:None} > {0.0: None} > > The second item disappeared! > > Why? > Is it normal? > Because 0 == 0.0 -- Ned Batchelder, http://nedbatchelder.com From rosuav at gmail.com Wed May 7 11:22:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 01:22:59 +1000 Subject: Normal dict behavior? In-Reply-To: <18f61e5d-f47b-4373-a835-67c6f20ef3d1@googlegroups.com> References: <18f61e5d-f47b-4373-a835-67c6f20ef3d1@googlegroups.com> Message-ID: On Thu, May 8, 2014 at 1:06 AM, antoine wrote: > Hi, > > Python 2.7.5 (default, Nov 20 2013, 14:20:58) > [GCC 4.7.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> {0.: None, 0:None} > {0.0: None} > > The second item disappeared! > > Why? > Is it normal? There are two things happening here. Firstly: >>> 0 == 0.0 True Secondly: >>> {"spam":1, "spam":2} {'spam': 2} I think you'll agree that, in the second case, Python cannot store both values. You might say that this ought to be an error, but certainly it can't return a dict with two values when you attached them to the same key. The first part is that a dict is defined on the basis of equality, and the integer 0 and the floating point 0.0 are equal. So to the dict, they are just as much equal as the two strings "spam" are, and it's a duplicate key. Obviously the dict can't be defined on the basis of object identity, as you'd then have to carefully intern all strings used, etc, etc. (Though an identity-based mapping would have some value. i'm sure you could make a MutableMapping that internally maps id(key) to (key, value) and handles everything uniquely. Might already exist, even. But it's definitely not what the inbuilt dict should do.) So the two arguable points are: 1) Should 0 and 0.0 compare equal? Both choices make sense, and different languages choose differently, but Python has declared that numerics representing the same number are equal. So, this one isn't changing. 2) Should the dict give you some kind of notification when it overwrites a key/value pair during construction/display? Maybe. It does seem a little illogical to write something in that will get ignored, so I could imagine this giving a warning or error. The question is probably: How much do you gain by having the dict check for this, and how much effort is it therefore worth? Considering how pervasive the dict is in Python's own internals, not to mention how many times it's used in user-level code, any performance hit would multiply out, so it would need to be extremely beneficial. But it's a possibility for a linter, maybe. ChrisA From christian at python.org Wed May 7 11:34:26 2014 From: christian at python.org (Christian Heimes) Date: Wed, 07 May 2014 17:34:26 +0200 Subject: Normal dict behavior? In-Reply-To: References: <18f61e5d-f47b-4373-a835-67c6f20ef3d1@googlegroups.com> Message-ID: On 07.05.2014 17:20, Ned Batchelder wrote: > Because 0 == 0.0 > hash(0) == hash(0.0) and 0 == 0.0 Christian From rosuav at gmail.com Wed May 7 11:38:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 01:38:29 +1000 Subject: Normal dict behavior? In-Reply-To: References: <18f61e5d-f47b-4373-a835-67c6f20ef3d1@googlegroups.com> Message-ID: On Thu, May 8, 2014 at 1:34 AM, Christian Heimes wrote: > hash(0) == hash(0.0) and 0 == 0.0 In theory, the former should be implied by the latter. Any deviation from that is a bug in __hash__ for the two objects. ChrisA From invalid at invalid.invalid Wed May 7 11:42:45 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 May 2014 15:42:45 +0000 (UTC) Subject: Using ssl.wrap_socket() in chroot jail Message-ID: Let's say you have a server/daemon application written in python that accepts incoming SSL connections. You want to run that application in a chroot jail. The last thing you want in that jail is your SSL certificate private key file. But, it appears the ssl module won't accept SSL certificates and keys as data strings, or as stringio file objects. It will only accept a filename, and it has to open/read that file every time a connection is accepted. So how do you avoid having your certificate key file sitting, readable, in the chroot jail? -- Grant Edwards grant.b.edwards Yow! An Italian is COMBING at his hair in suburban DES gmail.com MOINES! From malaclypse2 at gmail.com Wed May 7 11:48:15 2014 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 7 May 2014 11:48:15 -0400 Subject: =?UTF-8?B?UmU6IFRoZSDigJxkb2VzIFB5dGhvbiBoYXZlIHZhcmlhYmxlcz/igJ0gZGViYXRl?= In-Reply-To: <8738gmxgay.fsf@elektro.pacujo.net> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: On Wed, May 7, 2014 at 2:18 AM, Marko Rauhamaa wrote: > Ned Batchelder : > >> Why is "variable" sacrosanct and can only be used to describe C >> semantics, but we're OK reusing class, int, and function? > > The Python language specification calls them variables; the terminology > discussion should end there. Personally, I found the idea that a python variable is a name + value pairing to be useful when learning the language, especially when I was struggling with the calling semantics (that is, the differences between call-by-value, call-by-reference, and call-by-object). I think it's rather silly for someone to insist that python doesn't have variables. On the other hand, I think it can be useful to point out that python variable aren't like C variables, and that thinking of python variables as having two parts -- names and values -- really can help people who are struggling to learn the language. I know it certainly helped me. -- Jerry From rosuav at gmail.com Wed May 7 12:04:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 02:04:45 +1000 Subject: Using ssl.wrap_socket() in chroot jail In-Reply-To: References: Message-ID: On Thu, May 8, 2014 at 1:42 AM, Grant Edwards wrote: > But, it appears the ssl module won't accept SSL certificates and keys > as data strings, or as stringio file objects. It will only accept a > filename, and it has to open/read that file every time a connection is > accepted. > > So how do you avoid having your certificate key file sitting, readable, > in the chroot jail? I was going to say "if all else fails, monkey-patch", but the source code shows that the Python ssl module just passes the file name straight on to _ssl... and, what's more, that _ssl.c just passes it right along to SSL_CTX_use_PrivateKey_file which I presume is part of OpenSSL. Is it possible for you to initialize an SSLContext before chrooting, and just hold that in memory? You can then use its wrap_socket instead of the default wrap_socket. According to the docstring for SSLContext, it can hold "... possibly a private key", but I don't see a parameter for that; that's probably just indicative of my lack of experience with Python's ssl module, though. If you invoke Python entirely within the chroot jail, though, I don't know of a way around it. ChrisA From jurko.gospodnetic at pke.hr Wed May 7 12:58:55 2014 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Wed, 07 May 2014 18:58:55 +0200 Subject: Common issue but unable to find common solution (ez_setup.py on PC) In-Reply-To: <50b03208-8a61-43fc-890e-09992c4c4759@googlegroups.com> References: <253cc793-655e-4b7d-a167-73bb8bebde90@googlegroups.com> <50b03208-8a61-43fc-890e-09992c4c4759@googlegroups.com> Message-ID: <536A664F.7020600@pke.hr> Hi Jason, On 7.5.2014. 15:52, Jason Mellone wrote: > So, is the answer: > > 1 - Until the patch is applied there is no answer > > or > > 2 - I can go in and manually modify the code, and have the ez setup work? I see the patch has just been applied to the setuptools development repo, so the bug will be fixed in the next setuptools release, which seems imminent, judging from the latest setuptools commits. Related commits (see them at https://bitbucket.org/pypa/setuptools/commits/all) are on a branch containing the c95540cfeaec64251e78add403513a4f30700319 commit from 2014-04-15. But, if you need to fix your problem sooner, you can always do one of the following: 1. Not run ez_setup.py if setuptools is already installed and instead just run 'easy_install -U setuptools' to perform the upgrade. (I think that avoids the problem at hand, but I don't recall all the details so I could be mistaken.) 2. Manually remove setuptools before running ez_setup.py (either by removing the setuptools egg from your site-packages folder or perhaps by running 'pip uninstall setuptools'). 3. Checkout the development version of setuptools and install from there or prepare your own private setuptools package based on the current development tip. So you should be able to get your scenario to work, whatever it is. Hope this helps. Best regards, Jurko Gospodneti? P.S. I guess you're using google groups. I really hate the double spacing that leaves in your quotes and thus makes me scroll a lot and waste a lot of time trying to parse your message. Please try to use a different newsgroup client, e.g. Thunderbird. Many thanks. From invalid at invalid.invalid Wed May 7 13:04:18 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 May 2014 17:04:18 +0000 (UTC) Subject: python-daemon interaction with multiprocessing (secure-smtpd) Message-ID: With Python 2.7.5, I'm trying to use the python-daemon 1.6 and its DaemonRunner helper with the seucre-smtpd 1.1.9 which appears to use multiprocessing and a process pool under the covers. There seem to be a couple process issues: 1) The pid file created by DaemonRunner dissappears. This seems to happen when the SMTP client closes the connection without saying goodbye first. The process who's PID was in the pid file before it vanished is still running (as is the pool of worker processes), and they are still accepting connections and working as it should. Has anybody else had any luck with DaemonRunner and pidfiles? 2) When DaemonRunner kills the "lead" process (the parent of the worker pool), the worker pools stays alive and continues to handle accept and handle requests. [I've tried kill -TERM and -QUIT on the lead process by hand with the TERM signal, and got the same results: the worker pool continues to run.] How so you terminate a Python program that's using multiprocessing? -- Grant Edwards grant.b.edwards Yow! Look! A ladder! at Maybe it leads to heaven, gmail.com or a sandwich! From invalid at invalid.invalid Wed May 7 13:55:45 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 May 2014 17:55:45 +0000 (UTC) Subject: python-daemon interaction with multiprocessing (secure-smtpd) References: Message-ID: On 2014-05-07, Grant Edwards wrote: > With Python 2.7.5, I'm trying to use the python-daemon 1.6 and its > DaemonRunner helper with the seucre-smtpd 1.1.9 which appears to use > multiprocessing and a process pool under the covers. There seem to be > a couple process issues: > > 1) The pid file created by DaemonRunner disappears. This seems to > happen when the SMTP client closes the connection without saying > goodbye first. Hmm. After some further testing, it looks like it often disappears as soon as the first connection is accepted (which I think is when the first worker process is created). > How do you terminate a Python program that's using multiprocessing? It looks like you have to kill all the threads individually. :/ -- Grant Edwards grant.b.edwards Yow! We are now enjoying at total mutual interaction in gmail.com an imaginary hot tub ... From harrismh777 at gmail.com Wed May 7 13:56:38 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 07 May 2014 12:56:38 -0500 Subject: idle glitch while building python 3.4 from sources Message-ID: hi folks, I got bit again trying to build python3.4 from sources (mea culpa, of course). The symptom is everything (except ensure pip) builds, installs, and runs fine with the small baby problem that IDLE will not run (-tkinter isn't even there) even though tcl/tk 8.5 is loaded and running. This happens to me from time to time when I'm building on a new machine (this one is a T-61 ThinkPad running Mint Maya). The solution is simple, if I could remember it. The dev packages for tcl/tk have to be installed or the python build will not self-configure for tkinter. Make sure these are installed before ./configure; make; sudo make install : tcl8.5-dev tk8.5-dev That is assuming that the dev packages (as well as tcl/tk) are installed to the standard places on my distro (they were). We can point the build at another location in setup.py, or with ./configure options, or with make options (complicated). Why am I posting? Glad you asked. I am wondering if the build scripts could be updated slightly by prompting the user for IDLE preferences; and|or by being more robust about determining where tcl/tk lives, and|or by explicitly telling the user in the logs (or preferably right there on-screen) that the dev header packages for tcl/tk are not installed, and|or by refusing to build until the tcl/tk dev packages are installed, and|or refusing to build unless the user explicitly opts to bypass tkinter and build python anyway. I know its my own fault (because I should just know this) but I got to wondering about others who 'might not know' about the tcl/tk dev packages and would be scratching their heads about why _tkinter is missing and IDLE won't run, although tcl/tk is installed correctly and running? Just a suggestion... marcus From christian at python.org Wed May 7 14:11:39 2014 From: christian at python.org (Christian Heimes) Date: Wed, 07 May 2014 20:11:39 +0200 Subject: Using ssl.wrap_socket() in chroot jail In-Reply-To: References: Message-ID: On 07.05.2014 17:42, Grant Edwards wrote: > Let's say you have a server/daemon application written in python that > accepts incoming SSL connections. > > You want to run that application in a chroot jail. > > The last thing you want in that jail is your SSL certificate private > key file. > > But, it appears the ssl module won't accept SSL certificates and keys > as data strings, or as stringio file objects. It will only accept a > filename, and it has to open/read that file every time a connection is > accepted. > > So how do you avoid having your certificate key file sitting, readable, > in the chroot jail? Python's SSL module can't load private key from memory. I wanted to implement that feature for 3.4 but the feature wasn't ready by then. You have multiple options: * create a SSLContext, then chroot() * use pyOpenSSL / cryptography als TLS library * don't do SSL in your daemon and let some proxy or load balancer do TLS offloading, e.g. NGinx or Apache + mod_proxy Christian From harrismh777 at gmail.com Wed May 7 14:11:46 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 07 May 2014 13:11:46 -0500 Subject: Pass variable by reference References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: On 5/6/14 6:46 PM, Chris Angelico wrote: > Is there really a fundamental > difference between languages in which that is equally valid syntax and > does exactly the same thing? No. And from that standpoint, python has variables. I know, because I thought about python's 'variables' as variables for quite sometime before I learned about the 'beautiful heart of python'. AND I used them as variables too, ignorantly of course. And we must never forget that CPython's underpinnings, uhm C, uses variables, C ones... (never mind) Here is the rub. What happens when a newbie (me, some some years ago) gets a strange 'surprise' when trying to use python's variables: Given that A is bound to 3.5, and B is also bound to another object 3.5: A == B True A is B False ... and now they want to know why if A == 3.5 and B == 3.5 does (A is B) come up False? This is just one of a dozen 'different' kinds of examples. And the answer is the same, Python does not have variables, Python has names bound to objects. The cleanest clearest explanation of Python's (name-->object) model is 'the beautiful heart of python' in Mark Summerfield's Programming Python 3. I think we should STOP saying that python does not have variables (like that horse hasn't been beaten before, to death) but instead explain Python's beautiful heart. uhm, "What you have been using in ignorance as a simple variable is, uhm, a 'name' bound to an object... and these are its strange properties: ... enumerated... marcus From nad at acm.org Wed May 7 14:19:58 2014 From: nad at acm.org (Ned Deily) Date: Wed, 07 May 2014 11:19:58 -0700 Subject: idle glitch while building python 3.4 from sources References: Message-ID: In article , Mark H Harris wrote: > I know its my own fault (because I should just know this) but I got to > wondering about others who 'might not know' about the tcl/tk dev > packages and would be scratching their heads about why _tkinter is > missing and IDLE won't run, although tcl/tk is installed correctly and > running? If the Python build (the "make sharedmods" build step) can't successfully build the _tkinter extension module (because, for example, it couldn't find the Tk headers or libraries), the build step already reports that it could not build _tkinter. It does the same for all of the other extension module builds, some of which also require third-party headers and libraries, like those from OpenSSL, zlib, bz2, etc. Also, most people don't build Python from source - they install Python from a distributor - and the people who do generally know (or learn quickly) what dependencies are needed for their needs. -- Ned Deily, nad at acm.org From invalid at invalid.invalid Wed May 7 14:51:19 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 May 2014 18:51:19 +0000 (UTC) Subject: Using ssl.wrap_socket() in chroot jail References: Message-ID: On 2014-05-07, Christian Heimes wrote: > On 07.05.2014 17:42, Grant Edwards wrote: >> Let's say you have a server/daemon application written in python that >> accepts incoming SSL connections. >> >> You want to run that application in a chroot jail. >> >> The last thing you want in that jail is your SSL certificate private >> key file. [...] > Python's SSL module can't load private key from memory. I wanted to > implement that feature for 3.4 but the feature wasn't ready by then. > You have multiple options: > > * create a SSLContext, then chroot() > * use pyOpenSSL / cryptography als TLS library > * don't do SSL in your daemon and let some proxy or load balancer do TLS > offloading, e.g. NGinx or Apache + mod_proxy Unfortunately, the actual SSL wrapping stuff isn't being done in my code. It's being done by the secure-smtpd module, which will pass whatever cert/key params I give it to ssl.wrap_socket(). That still leaves the third option (e.g. stunnel). Thanks. -- Grant Edwards grant.b.edwards Yow! I'm wearing PAMPERS!! at gmail.com From ben at benfinney.id.au Wed May 7 15:01:56 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 08 May 2014 05:01:56 +1000 Subject: python-daemon interaction with multiprocessing (secure-smtpd) References: Message-ID: <85siolct0b.fsf@benfinney.id.au> Grant Edwards writes: > On 2014-05-07, Grant Edwards wrote: > > How do you terminate a Python program that's using multiprocessing? > > It looks like you have to kill all the threads individually. :/ As I understand it, the ?multiprocessing? module does not create multiple threads; it creates multiple processes. It also closely follows the API for the ?threading? module. That includes the ability to manage a pool of workers . You can ask the pool of workers to close when they're done . Does that address the requirement? -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but if we give peas a chance, won't the lima beans feel | _o__) left out?? ?_Pinky and The Brain_ | Ben Finney From invalid at invalid.invalid Wed May 7 15:11:37 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 May 2014 19:11:37 +0000 (UTC) Subject: python-daemon interaction with multiprocessing (secure-smtpd) References: Message-ID: On 2014-05-07, Ben Finney wrote: > Grant Edwards writes: > >> On 2014-05-07, Grant Edwards wrote: >> > How do you terminate a Python program that's using multiprocessing? >> >> It looks like you have to kill all the threads individually. :/ > > As I understand it, the ?multiprocessing? module > does not > create multiple threads; it creates multiple processes. Right. I should have written processes rather than threads. > It also closely follows the API for the ?threading? module. That > includes the ability to manage a pool of workers >. Except when you kill the parent of a bunch of threads, they all get killed. That doesn't seem to be the case for multiprocessing. > You can ask the pool of workers to close when they're done >. > Does that address the requirement? I'm not sure. It's not really my code that's creating and managing the pool: that's happening inside the secure-smtpd module from https://github.com/bcoe/secure-smtpd. There's a little bit of wrapper code that configures the server and then starts it -- after that I don't have much control over anything. Mainly, I'm just trying to figure out the right way to terminate the server from an /etc/init script. -- Grant Edwards grant.b.edwards Yow! We're going to a at new disco! gmail.com From harrismh777 at gmail.com Wed May 7 15:31:13 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 07 May 2014 14:31:13 -0500 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: On 5/7/14 10:48 AM, Jerry Hill wrote: > I think it's rather silly for someone to insist that python doesn't have > variables. On the other hand, I think it can be useful to point out > that python variable aren't like C variables, and that thinking of > python variables as having two parts -- names and values -- really can > help people who are struggling to learn the language. I know it > certainly helped me. > But here is the rub: BASIC also has -- names and values --; although they are in a variable table, and they refer to memory not objects. C is the same, basically. ehem. ... a name bound to an address that references a chunk of memory (by type) of a certain length. ... and we could go on. But, Python's names bound to objects not only doesn't behave like the 'variables' mentioned above, they provide for serious side-effects for the programmer if the coder does not think of them properly as names bound to objects. And that means surprises. So, when anyone points out that Python does not have variables, but rather Python has names bound to objects... they are being most helpful. As I pointed out earlier, I think the better approach would be to find positive language for helping new folks understand Python's beautiful heart, than the relatively negative language of stating Python has no variables. From harrismh777 at gmail.com Wed May 7 15:42:13 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 07 May 2014 14:42:13 -0500 Subject: idle glitch while building python 3.4 from sources In-Reply-To: References: Message-ID: <536A8C95.6050103@gmail.com> On 5/7/14 1:19 PM, Ned Deily wrote: > If the Python build (the "make sharedmods" build step) can't > successfully build the _tkinter extension module (because, for example, > it couldn't find the Tk headers or libraries), the build step already > reports that it could not build _tkinter. hi Ned, where is the report? Its not obvious; where does one look for this step output? I did not see it on my build attempts last night. I'm assuming its in one of the logs. What would be nice is a final (at the end) report listing of the modules|extention modules that did not get built (for whatever reason). As an aside, the ensure pip is disabled for some reason (I'm reading the pep, and such, which is confusing). There isn't much to go on from the build listing about ensure pip either. marcus From harrismh777 at gmail.com Wed May 7 15:42:13 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 07 May 2014 14:42:13 -0500 Subject: idle glitch while building python 3.4 from sources References: Message-ID: <536A8C95.6050103@gmail.com> On 5/7/14 1:19 PM, Ned Deily wrote: > If the Python build (the "make sharedmods" build step) can't > successfully build the _tkinter extension module (because, for example, > it couldn't find the Tk headers or libraries), the build step already > reports that it could not build _tkinter. hi Ned, where is the report? Its not obvious; where does one look for this step output? I did not see it on my build attempts last night. I'm assuming its in one of the logs. What would be nice is a final (at the end) report listing of the modules|extention modules that did not get built (for whatever reason). As an aside, the ensure pip is disabled for some reason (I'm reading the pep, and such, which is confusing). There isn't much to go on from the build listing about ensure pip either. marcus From ben at benfinney.id.au Wed May 7 15:57:49 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 08 May 2014 05:57:49 +1000 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: <85oaz9cqf6.fsf@benfinney.id.au> Mark H Harris writes: > So, when anyone points out that Python does not have variables, but > rather Python has names bound to objects... they are being most > helpful. > > As I pointed out earlier, I think the better approach would be to find > positive language for helping new folks understand Python's beautiful > heart, than the relatively negative language of stating Python has no > variables. You are implying a dichotomy which I don't think is useful: that providing accurate models is ?a better approach? than pointing out existing fallacies. Rather, the better approach IMO is to use *both*: point out existing fallacies *and* replace them with more accurate models. That's why I always try to say ?Python doesn't have variables the way you might know from many other languages?, *and* say ?instead, it has references bound to objects? ? *in the same message*. Negative, to point out the fallacy; positive, to provide the replacement. Presenting an accurate model is valuable, but it's much less valuable in isolation than pointing out that the accurate model *is superior to*, and should replace, the existing less-accurate model in the receiver's brain. One must necessarily use negative language to achieve that. -- \ ?Religious faith is the one species of human ignorance that | `\ will not admit of even the *possibility* of correction.? ?Sam | _o__) Harris, _The End of Faith_, 2004 | Ben Finney From invalid at invalid.invalid Wed May 7 17:07:41 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 May 2014 21:07:41 +0000 (UTC) Subject: python-daemon interaction with multiprocessing (secure-smtpd) References: Message-ID: On 2014-05-07, Grant Edwards wrote: > With Python 2.7.5, I'm trying to use the python-daemon 1.6 and its > DaemonRunner helper with the seucre-smtpd 1.1.9 which appears to use > multiprocessing and a process pool under the covers. There seem to be > a couple process issues: > > 1) The pid file created by DaemonRunner dissappears. [...] > > 2) When DaemonRunner kills the "lead" process (the parent of the > worker pool), the worker pools stays alive and continues to handle > accept and handle requests. [...] I've tracked both these problems down to a single bug in secure_smtpd. The secure_smtpd server is a normal asyncore server until the first connection arrives. At that point, it creates a bunch of multiprocessor worker processes _without_ the daemon flag which all loop doing blocking accept() calls. The parent process then shuts down the asyncore server and returns. When the parent process returns, DaemonRunner removes the pidfile, since it thinks the server has terminated. However, the parent process never actually dies -- it just hangs until all the children terminate. At this point, killing the parent process (whose PID _was_ in the pidfile, and is now idle) does nothing: even though the parent process gets killed, the worker processes keeps working. The fix is to 1) Change secure_smtpd to create the worker processes with daemon=True 2) After asyncore.loop() returns (which means the children have been created), do a while 1: time.sleep(1) to wait for SIGTERM. -- Grant Edwards grant.b.edwards Yow! Maybe we could paint at GOLDIE HAWN a rich PRUSSIAN gmail.com BLUE -- From antoon.pardon at rece.vub.ac.be Wed May 7 15:45:28 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 07 May 2014 21:45:28 +0200 Subject: python-daemon interaction with multiprocessing (secure-smtpd) In-Reply-To: References: Message-ID: <536A8D58.6070202@rece.vub.ac.be> op 07-05-14 21:11, Grant Edwards schreef: > > Mainly, I'm just trying to figure out the right way to terminate the > server from an /etc/init script. > As far as I understand you have to make sure that your daemon is a proces group leader. All the children it will fork will then belong to its proces group. You can then normally kill all process with pkill -g ... -- Antoon Pardon From marko at pacujo.net Wed May 7 17:15:48 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 08 May 2014 00:15:48 +0300 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: <87tx91warf.fsf@elektro.pacujo.net> Ben Finney : > That's why I always try to say ?Python doesn't have variables the way > you might know from many other languages?, Please elaborate. To me, Python variables are like variables in all programming languages I know. Python currently does not allow me to obtain the "address" of a variable, but that doesn't make me think of Python variables any differently. Marko From marko at pacujo.net Wed May 7 17:22:55 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 08 May 2014 00:22:55 +0300 Subject: Pass variable by reference References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: <87ppjpwafk.fsf@elektro.pacujo.net> Mark H Harris : > A == B > True > > A is B > False > > [...] > > This is just one of a dozen 'different' kinds of examples. And the > answer is the same, Python does not have variables, Python has names > bound to objects. That is a different topic and isn't related to variables at all. Instead, you are talking about object identity: >>> 2 * 3000 == 6000 True >>> 2 * 3000 is 6000 False >>> "abc"[:1] == "a" True >>> "abc"[:1] is "a" False But hey, we can open another thread for whether Python has values or objects! Marko From harrismh777 at gmail.com Wed May 7 17:35:00 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 07 May 2014 16:35:00 -0500 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> Message-ID: On 5/7/14 4:15 PM, Marko Rauhamaa wrote: >> That's why I always try to say ?Python doesn't have variables the way >> you might know from many other languages?, > > Please elaborate. To me, Python variables are like variables in all > programming languages I know. Python currently does not allow me to > obtain the "address" of a variable, but that doesn't make me think of > Python variables any differently. Here is the difference... in almost every other language you know. A = macTruck B = A In almost every other language you know A and B each "contain" by reference (and almost always by static type) macTruck. But NOT python. A --> {macTruck} <-- B In almost every other language you know there is some kind of binding table (name reference to type/length) and BOTH A and B are bound to data in memory macTruck... and usually its a different place in memory! NOT python. No doubt you may use A and B in python the way other people use their variables in their language... but it MEANS something different. marcus From harrismh777 at gmail.com Wed May 7 17:37:47 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 07 May 2014 16:37:47 -0500 Subject: right click cut copy past context menu in IDLE in 3.4 Message-ID: Greetings, thanks to the folks who worked on the right click context menu in IDLE for python 3.4! Nice job. marcus From cube345 at optonline.net Wed May 7 18:33:15 2014 From: cube345 at optonline.net (cube345 at optonline.net) Date: Wed, 7 May 2014 15:33:15 -0700 (PDT) Subject: How to tell Script to use pythonw.exe ? In-Reply-To: References: Message-ID: <1e627a8a-d66f-46b8-95b7-0b7947a524eb@googlegroups.com> On Tuesday, July 2, 2013 9:20:12 PM UTC-4, goldtech wrote: > Hi, > > > > I want to run a .py file script using pythonw.exe so the DOS box will not open. Is there a way from inside the script to say "run me with pythonw.exe and not python.exe"? > > > > Thanks From ian.g.kelly at gmail.com Wed May 7 18:29:34 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 May 2014 16:29:34 -0600 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: <536A4BF7.6040000@arskom.com.tr> Message-ID: On May 7, 2014 9:13 AM, "Chris Angelico" wrote: > > On Thu, May 8, 2014 at 1:06 AM, Burak Arslan wrote: > > Seeing how discussion is still going on about this, I'd like to state > > once more what I said above in other words: You just need to do this: > > > > "Received: blah\r\n" + message.to_string() > > > > or better: > > > > socket.write("Received: blah\r\n") > > socket.write(message.to_string()) > > > > And again, this is not a hack, this is how it's supposed to work. > > Yes, that method does work... if you're taking it in and sending it > right out again. But it means you have to hang onto two pieces of data > - the message and the new Received header - until you write it to a > file/socket. Alternatively, you could use a BytesIO to prepend the Received header to the raw data *before* you parse it with the email module. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed May 7 19:26:43 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 May 2014 19:26:43 -0400 Subject: right click cut copy past context menu in IDLE in 3.4 In-Reply-To: References: Message-ID: On 5/7/2014 5:37 PM, Mark H Harris wrote: > Greetings, thanks to the folks who worked on the right click context > menu in IDLE for python 3.4! I am not one of those who directly worked on that, but on their behalf, "you'r wellcome'. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed May 7 20:34:14 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2014 00:34:14 GMT Subject: Python under the sea and in space References: <1ea091fc-d271-4f08-ab70-edfae941bf82@googlegroups.com> Message-ID: <536ad106$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 07 May 2014 05:17:14 -0700, sjmsoft wrote: > I don't suppose "eight miles high" in the figurative sense counts? I'm afraid I don't know what "eight miles high" in the figurative sense means. There's at least two songs by that name, and a German movie, and I wonder whether you're thinking of the "mile high club", but other than that, I'm lost. In any case, O doubt that Jessica is asking in a figurative sense. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ben at benfinney.id.au Wed May 7 20:35:46 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 08 May 2014 10:35:46 +1000 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> Message-ID: <85eh05cdjx.fsf@benfinney.id.au> Marko Rauhamaa writes: > Ben Finney : > > > That's why I always try to say ?Python doesn't have variables the way > > you might know from many other languages?, > > Please elaborate. To me, Python variables are like variables in all > programming languages I know. Many established and still-popular languages have the following behaviour:: # pseudocode foo = [1, 2, 3] bar = foo # bar gets the value [1, 2, 3] assert foo == bar # succeeds foo[1] = "spam" # foo is now == [1, "spam", 3] assert foo == bar # FAILS, ?bar? == [1, 2, 3] This is because such languages treat each variable as ?containing? a value. Assignment puts another copy of the value in the variable, after which those two values have a distinct history. What happens to one value does not affect the other. Python, on the other hand, has this behaviour:: foo = [1, 2, 3] bar = foo # ?bar? binds to the value ?[1, 2, 3]? assert foo == bar # succeeds foo[1] = "spam" # ?foo? *and* ?bar? now == [1, "spam", 3] assert foo == bar # succeeds, ?bar? is bound to ?[1, "spam", 3]? The assignment statement in Python does not put a value in a container, the way it does for variables in many popular languages. Instead, assignment binds the left-hand-side reference (in these examples, names) to the right-hand-side value. Both remain references to the same value until the binding changes to some other value. So Python doesn't have variables in the way programmers coming from many other languages expect. Instead, it has references bound to values. -- \ ?Actually I made up the term ?object-oriented?, and I can tell | `\ you I did not have C++ in mind.? ?Alan Kay, creator of | _o__) Smalltalk, at OOPSLA 1997 | Ben Finney From steve+comp.lang.python at pearwood.info Wed May 7 20:57:31 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2014 00:57:31 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: <536ad67b$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 07 May 2014 11:48:15 -0400, Jerry Hill wrote: > On Wed, May 7, 2014 at 2:18 AM, Marko Rauhamaa wrote: >> Ned Batchelder : >> >>> Why is "variable" sacrosanct and can only be used to describe C >>> semantics, but we're OK reusing class, int, and function? >> >> The Python language specification calls them variables; the terminology >> discussion should end there. > > Personally, I found the idea that a python variable is a name + value > pairing to be useful when learning the language, especially when I was > struggling with the calling semantics (that is, the differences between > call-by-value, call-by-reference, and call-by-object). I think it's > rather silly for someone to insist that python doesn't have variables. > On the other hand, I think it can be useful to point out that python > variable aren't like C variables, and that thinking of python variables > as having two parts -- names and values -- really can help people who > are struggling to learn the language. I know it certainly helped me. +1 I was in the same position, and I found that while I saw people talking about "name bindings" and similar, the difference never sank in until somebody (I forget who) said "Python doesn't have variables, it has name bindings". Until then, I was still labouring under the misapprehension that my mental model of variables I learned from Pascal (equivalent to that of C) applied to Python too. Being exposed to an outrageous claim like "Python has no variables" lead me to question my assumptions. Most of the time, when you're just assigning values to a variable name, it's a difference that makes no difference. But at the edges, you run into some of the differences: * If you think that variables are necessarily known at compile-time, then Python has no variables. * If you think that variables have an address, then Python has no variables. * If you think of variables as a box inside of which the compiler puts a value, then Python has no variables. * If you think of id(x) as the identity of the *name* "x" rather than the identity of the object bound to "x", that is, if you think of id(x) as like a pointer to x, then you are mistaken. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Wed May 7 21:08:02 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2014 01:08:02 GMT Subject: Values and objects [was Re: Pass variable by reference] References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> Message-ID: <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 08 May 2014 00:22:55 +0300, Marko Rauhamaa wrote: > But hey, we can open another thread for whether Python has values or > objects! In Python, all values *are* objects. It isn't a matter of choosing one or the other. The value 1 is an object, not a native (low-level, unboxed) 32 or 64 bit int. Unlike C# or Java, there is no direct language facility to box native values into objects or unbox objects to native values. But note that Python objects can encompass machine values. For example, the array type is implemented as an array of native values, transparently packing and unpacking the values as needed. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Wed May 7 21:27:08 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2014 01:27:08 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> Message-ID: <536add6b$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 07 May 2014 16:35:00 -0500, Mark H Harris wrote: > On 5/7/14 4:15 PM, Marko Rauhamaa wrote: >>> That's why I always try to say ?Python doesn't have variables the way >>> you might know from many other languages?, >> >> Please elaborate. To me, Python variables are like variables in all >> programming languages I know. Python currently does not allow me to >> obtain the "address" of a variable, but that doesn't make me think of >> Python variables any differently. > > Here is the difference... in almost every other language you know. How do you know which languages Marko knows? > A = macTruck > B = A > > In almost every other language you know A and B each "contain" by > reference (and almost always by static type) macTruck. But NOT python. Nor Javascript, Ruby, Perl, PHP, Lua, or (I think) Lisp or Java. To mention only a few. I think it is easy to exaggerate the difference between Python and "almost every other language". Python's name binding model is very common amongst dynamically typed languages, and there are many dynamically typed languages. If I have understood correctly, and I welcome confirmation or correction, one can have any combination of: * dynamic typing and name binding (e.g. Python and Ruby); * static typing and name binding (e.g. Java); * dynamic typing and fixed-location variables (any examples?); * static typing and fixed-location variables (C, Pascal). Where do VB and Perl fit into this? There are probably other variations as well. E.g. Cobra has both dynamic typed variables and static typed variables. > In almost every other language you know there is some kind of binding > table (name reference to type/length) and BOTH A and B are bound to data > in memory macTruck... and usually its a different place in memory! > > NOT python. Python has "binding tables" too. They are dicts. Any language with variables must have some way of mapping the name to the value. In some languages that mapping is available only to the compiler, and no longer exists at runtime (e.g. the assignment "x := 1;" is compiled to the equivalent of "copy value 1 into memory location 1234", with no reference to "x" remaining). In some languages the mapping is only available at runtime (e.g. the assignment "x := 1;" is compiled to the equivalent of "look up x and bind the value 1 to it"). In Python, lookups occur at runtime, not compile time. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Wed May 7 21:31:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 11:31:56 +1000 Subject: Pass variable by reference In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: On Thu, May 8, 2014 at 4:11 AM, Mark H Harris wrote: > And we must never forget that CPython's underpinnings, uhm C, uses > variables, C ones... (never mind) Be careful of this one. It's utterly irrelevant to your point, and may be distracting. I could implement Ook in Python; does that mean that Ook has a socket library? Clearly not. ChrisA From ned at nedbatchelder.com Wed May 7 21:33:01 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 07 May 2014 21:33:01 -0400 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: <85eh05cdjx.fsf@benfinney.id.au> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> Message-ID: On 5/7/14 8:35 PM, Ben Finney wrote: > Marko Rauhamaa writes: > >> Ben Finney : >> >>> That's why I always try to say ?Python doesn't have variables the way >>> you might know from many other languages?, >> >> Please elaborate. To me, Python variables are like variables in all >> programming languages I know. > > Many established and still-popular languages have the following > behaviour:: > > # pseudocode > > foo = [1, 2, 3] > bar = foo # bar gets the value [1, 2, 3] > assert foo == bar # succeeds > foo[1] = "spam" # foo is now == [1, "spam", 3] > assert foo == bar # FAILS, ?bar? == [1, 2, 3] > Can we make this concrete by speaking about a specific language? I don't recognize this. I thought we were concerned with beginners incorrectly thinking Python worked like C, but this is nothing like C. -- Ned Batchelder, http://nedbatchelder.com From steve+comp.lang.python at pearwood.info Wed May 7 21:32:15 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2014 01:32:15 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> Message-ID: <536ade9f$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 08 May 2014 10:35:46 +1000, Ben Finney wrote: > Marko Rauhamaa writes: > >> Ben Finney : >> >> > That's why I always try to say ?Python doesn't have variables the way >> > you might know from many other languages?, >> >> Please elaborate. To me, Python variables are like variables in all >> programming languages I know. > > Many established and still-popular languages have the following > behaviour:: > > # pseudocode > foo = [1, 2, 3] > bar = foo # bar gets the value [1, 2, 3] > assert foo == bar # succeeds > foo[1] = "spam" # foo is now == [1, "spam", 3] > assert foo == bar # FAILS, ?bar? == [1, 2, 3] Pascal and Fortran are examples of this. Any more recent examples? Any examples of languages with dynamic typing but this behaviour? I note also that one may still have a name-binding model with copy-on- assign semantics. For example, one might add syntactic sugar to a Python- like language such that: spam = eggs is a name binding, and spam := eggs makes a copy of eggs before binding. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Wed May 7 22:02:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 12:02:05 +1000 Subject: Value vs Identity (was Re: Pass variable by reference) Message-ID: On Thu, May 8, 2014 at 7:22 AM, Marko Rauhamaa wrote: > Mark H Harris : > >> A == B >> True >> >> A is B >> False >> >> [...] >> >> This is just one of a dozen 'different' kinds of examples. And the >> answer is the same, Python does not have variables, Python has names >> bound to objects. > > That is a different topic and isn't related to variables at all. > Instead, you are talking about object identity: > > >>> 2 * 3000 == 6000 > True > >>> 2 * 3000 is 6000 > False > >>> "abc"[:1] == "a" > True > >>> "abc"[:1] is "a" > False > > But hey, we can open another thread for whether Python has values or > objects! Python has objects. Objects have both identity and value. This is true of every language I can think of that has any sort of pointer type; a few examples: 1) A C string is a pointer-to-char. You compare string identity as pointer value, and string value with strcmp(). Same with anything you malloc(); its value is what's in the memory, its identity is the pointer value (or memory location). 2) A REXX string, under the covers, is implemented as a C string, so the same applies. But that's cheating a little, as there's no way in REXX itself to probe identity; all you can work with is value. 3) Pike strings are always interned, so their identities and values will always correspond, but arrays, mappings, and other refcounted pointer types are compared for identity with == and for value with equal(). 4) Python objects always have identities, which are compared with 'is', and values, which are compared with '=='. 5) JavaScript objects are always compared by identity, and there are numerous posts on StackOverflow etc about how to compare value. But strings, AFAICT, are always compared by value. 6) A tuple in a database (okay, this is pushing the "language" bit a little) ought, in a good design, be able to be identified and compared exclusively by value. But since good design is not 100% prevalent, every table row must have an identity as well. In PostgreSQL, this can be done with OIDs and such; in BTrieve, the file position is a fundamental attribute of the record. 7) BASIC has strings in memory, just like C does; using VARPTR and PEEK, you can find that address, and use it as the string's identity. You can then use LSET or RSET to mutate it without changing its identity, or reassign it to do a Python-style rebinding. I would put a caveat here that it's inadvisable, except that... well, it's BASIC, so writing any code at all is inadvisable. 8) PHP objects have separate identity and value, although AFAIK arrays, strings, and integers don't. So, this isn't really a Python question at all. It's more like trying to figure out which is the evil twin (pro tip: he's the one sticking a dagger into you [1]), where the two are indistinguishable (value) but are distinct (identity). ChrisA [1] http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=229965 From rosuav at gmail.com Wed May 7 22:09:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 12:09:21 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDigJxkb2VzIFB5dGhvbiBoYXZlIHZhcmlhYmxlcz/igJ0gZGViYXRl?= In-Reply-To: <536add6b$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <536add6b$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 8, 2014 at 11:27 AM, Steven D'Aprano wrote: > If I have understood correctly, and I welcome confirmation or correction, > one can have any combination of: > > * dynamic typing and name binding (e.g. Python and Ruby); > * static typing and name binding (e.g. Java); > * dynamic typing and fixed-location variables (any examples?); > * static typing and fixed-location variables (C, Pascal). Dynamic typing and fixed locations could really only be assembly language, I think. It's all just bits in memory, and you treat them as whatever you want. In C, signed and unsigned integers are different types; in 80x86 assembly language, they're just integers, and you use either JA or JG (Jump if Above vs Jump if Greater) to make unsigned or signed comparisons. Or you can fetch a set of four bytes out of a byte ("character", ha) string and treat it as an integer - see for instance the FOURCC system used in some audio files. It's certainly not a normal way of writing code, but hey, it fills in the hole in your set of four :) ChrisA From rosuav at gmail.com Wed May 7 22:12:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 12:12:08 +1000 Subject: Using ssl.wrap_socket() in chroot jail In-Reply-To: References: Message-ID: On Thu, May 8, 2014 at 4:51 AM, Grant Edwards wrote: > Unfortunately, the actual SSL wrapping stuff isn't being done in my > code. It's being done by the secure-smtpd module, which will pass > whatever cert/key params I give it to ssl.wrap_socket(). That still > leaves the third option (e.g. stunnel). I'll go back to the naughty-crazy idea of monkey-patching, then: can you create an SSLContext prior to chrooting, then stuff its wrap_socket back into the ssl module? ChrisA From nad at acm.org Wed May 7 22:49:46 2014 From: nad at acm.org (Ned Deily) Date: Wed, 07 May 2014 19:49:46 -0700 Subject: idle glitch while building python 3.4 from sources References: <536A8C95.6050103@gmail.com> Message-ID: In article <536A8C95.6050103 at gmail.com>, Mark H Harris wrote: > On 5/7/14 1:19 PM, Ned Deily wrote: > > If the Python build (the "make sharedmods" build step) can't > > successfully build the _tkinter extension module (because, for example, > > it couldn't find the Tk headers or libraries), the build step already > > reports that it could not build _tkinter. > > hi Ned, where is the report? Its not obvious; where does one look for > this step output? I did not see it on my build attempts last night. I'm > assuming its in one of the logs. What would be nice is a final (at the > end) report listing of the modules|extention modules that did not get > built (for whatever reason). $ sudo aptitude remove tk-dev tcl-dev $ make clean $ make gcc -pthread -c -fno-strict-aliasing -g -O2 -g -O0 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -DPy_BUILD_CORE -o Modules/python.o ./Modules/python.c [...] ./python -E -S -m sysconfig --generate-posix-vars [20560 refs] running build running build_ext building dbm using gdbm INFO: Can't locate Tcl/Tk libs and/or headers [...] Python build finished, but the necessary bits to build these modules were not found: _bsddb _tkinter bsddb185 sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. running build_scripts $ > As an aside, the ensure pip is disabled for some reason (I'm reading the > pep, and such, which is confusing). There isn't much to go on from the > build listing about ensure pip either. What do you mean by "disabled"? Are you building from a source tarball or from some package from your distribution? You'll need to do a "make install" for pip to be installed and it will be installed in your --prefix bin (default, /usr/local/bin) as pip3 and pip3.4. -- Ned Deily, nad at acm.org From steve at pearwood.info Wed May 7 23:41:44 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 08 May 2014 03:41:44 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <536add6b$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536afcf8$0$11109$c3e8da3@news.astraweb.com> On Thu, 08 May 2014 12:09:21 +1000, Chris Angelico wrote: > On Thu, May 8, 2014 at 11:27 AM, Steven D'Aprano > wrote: >> If I have understood correctly, and I welcome confirmation or >> correction, one can have any combination of: >> >> * dynamic typing and name binding (e.g. Python and Ruby); * static >> typing and name binding (e.g. Java); * dynamic typing and >> fixed-location variables (any examples?); * static typing and >> fixed-location variables (C, Pascal). > > Dynamic typing and fixed locations could really only be assembly > language, I think. Not so! That's how __slots__ and local variables work in CPython. Objects are different sizes, so CPython can't allocate a box of a fixed size unless it knows how big the box needs to be. Fortunately, pointers are all the same size, so the object lives on the heap and the pointer goes in the box. The point being, there could be a language that used fixed locations for variables, while still being fully dynamically typed. That would allow the language to use pass-by-name or pass-by-reference semantics instead of pass-by-value or pass-by-shared-object. -- Steven From dan at tombstonezero.net Wed May 7 23:43:49 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Thu, 8 May 2014 03:43:49 +0000 (UTC) Subject: The =?iso-8859-13?Q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <536add6b$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 08 May 2014 01:27:08 +0000, Steven D'Aprano wrote: > If I have understood correctly, and I welcome confirmation or > correction, one can have any combination of: > * dynamic typing and name binding (e.g. Python and Ruby); > * static typing and name binding (e.g. Java); > * dynamic typing and fixed-location variables (any examples?); > * static typing and fixed-location variables (C, Pascal). C unions, if you squint just right, are fixed location variables and at least partially dynamic, within the bounds of what you define at compile time. And at the risk of opening another can of worms, C's typing is sufficiently weak that it can be way more dynamic than many programmers want. It's this |?| close to assembly language (ChrisA's example of the combination of dynamic typing and fixed locations). Dan From steve at pearwood.info Wed May 7 23:46:27 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 08 May 2014 03:46:27 GMT Subject: data: protocol References: Message-ID: <536afe13$0$11109$c3e8da3@news.astraweb.com> On Wed, 07 May 2014 11:42:24 +0100, Robin Becker wrote: > I have an outstanding request for ReportLab to allow images to be opened > using the data: scheme. That used to be supported in python 2.7 using > urllib, but in python 3.3 urllib2 --> urllib and at least the default > urlopener doesn't support data: It looks like you intended to show an example, but left it out. > Is there a way to use the residual legacy of the old urllib code that's > now in urllib.URLopener to open unusual schemes? I know it can be used > directly eg > > urllib.request.URLopener().open('data:.........') > > but that seems to leave the splitting & testing logic up to me when it > logically belongs in some central place ie urllib.request.urlopen. You may need to explain in a little more detail. When you say "splitting and testing", what are you splitting and testing? It may also help if you show some Python 2.7 code that works, and what happens in 3.3. -- Steven From ian.g.kelly at gmail.com Thu May 8 00:17:20 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 May 2014 22:17:20 -0600 Subject: data: protocol In-Reply-To: <536A0E10.5030402@chamonix.reportlab.co.uk> References: <536A0E10.5030402@chamonix.reportlab.co.uk> Message-ID: On Wed, May 7, 2014 at 4:42 AM, Robin Becker wrote: > I have an outstanding request for ReportLab to allow images to be opened > using the data: scheme. That used to be supported in python 2.7 using > urllib, but in python 3.3 urllib2 --> urllib and at least the default > urlopener doesn't support data: > > Is there a way to use the residual legacy of the old urllib code that's now > in urllib.URLopener to open unusual schemes? I know it can be used directly > eg > > urllib.request.URLopener().open('data:.........') > > but that seems to leave the splitting & testing logic up to me when it > logically belongs in some central place ie urllib.request.urlopen. Seems to be fixed in Python 3.4: Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (In tel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib.request >>> url = 'data:text/plain;charset=UTF-8,Hello%20World' >>> urllib.request.urlopen(url).read() b'Hello World' From ian.g.kelly at gmail.com Thu May 8 01:52:32 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 May 2014 23:52:32 -0600 Subject: Python under the sea and in space In-Reply-To: References: Message-ID: On Tue, May 6, 2014 at 8:31 PM, Jessica McKellar wrote: > Hi folks, > > I'm trying to determine the greatest depth (in the ocean or underground) and > highest altitude at which Python code has been executed. > > Please note that I'm interested in where the code was executed, and not, > say, where data that Python analyzed was acquired. I know for example that > NASA has analyzed plenty of data from space in Python, but the analysis was > done in labs here on Earth. :) That may be true, but considering that the laptops on the ISS reportedly run Linux nowadays, I would be surprised if Python hasn't been used for *something* up there, even if it's just something mundane like an OS utility. From wxjmfauth at gmail.com Thu May 8 02:04:07 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 7 May 2014 23:04:07 -0700 (PDT) Subject: Unicode in Python In-Reply-To: References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> <03bb12d8-93be-4ef6-94ae-4a02789aea2d@googlegroups.com> Message-ID: <90b5fb36-e99d-4dcb-8df0-77044ff53be9@googlegroups.com> Le jeudi 1 mai 2014 19:21:14 UTC+2, rand... at fastmail.us a ?crit?: > On Mon, Apr 28, 2014, at 4:57, wxjmfauth at gmail.com wrote: > > > Python 3: > > > - It missed the unicode shift. > > > - Covering the whole unicode range will not make > > > Python a unicode compliant product. > > > > Please cite exactly what portion of the unicode standard requires > > operations with all characters to be handled in the same amount of time > > and space, and forbids optimizations that make some characters handled > > faster or in less space than others. ========== I missed you comment. Regression is only a side effect. I can make Python failing (lead Python to failures) with any piece of text or valid sequence of characters I wish [*]. I'm no more writing code (apps), only maintaining my interactive interpreters. [*] I do not count as failures, issues like cp65001, only "basic" text/string manipulations. jmf From marko at pacujo.net Thu May 8 02:19:23 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 08 May 2014 09:19:23 +0300 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> Message-ID: <87y4ycvllg.fsf@elektro.pacujo.net> Ben Finney : > Many established and still-popular languages have the following > behaviour:: > > # pseudocode > > foo = [1, 2, 3] > bar = foo # bar gets the value [1, 2, 3] > assert foo == bar # succeeds > foo[1] = "spam" # foo is now == [1, "spam", 3] > assert foo == bar # FAILS, ?bar? == [1, 2, 3] > > This is because such languages treat each variable as ?containing? a > value. I don't think that has much to do with variables but rather the values. What you are describing is that Python has pointer semantics. Your example, properly understood and translated, will yield Python-esque results in any programming language: #!/bin/bash a = /tmp/xyz touch $a b = $a cmp $a $b || exit echo z >>/tmp/xyz cmp $a $b || exit #include #include int main(void) { int *a = malloc(sizeof *a); *a = 7; int *b = a; assert(*a == *b); *a = 8; assert(*a == *b); return 0; } Marko From ben at benfinney.id.au Thu May 8 02:40:45 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 08 May 2014 16:40:45 +1000 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <87y4ycvllg.fsf@elektro.pacujo.net> Message-ID: <85siokbwnm.fsf@benfinney.id.au> Marko Rauhamaa writes: > What you are describing is that Python has pointer semantics. That doesn't describe it, no. To my eye, ?pointer semantics? entails that one can directly pass a pointer around as a value (which can't be done for Python references), and that one can de-reference a pointer to get the value pointed at (which can't be done for Python references). > Your example, properly understood and translated, will yield > Python-esque results in any programming language: > > #!/bin/bash > a = /tmp/xyz > touch $a Of course, if you feel free to turn ?assignment? into something that isn't assignment at all, you can get different results. But to do so, you've had to ignore the language's native assignment operator, which *doesn't* work that way. I get the impression you're no longer engaging in this discussion trying to learn, but rather to score points. I refuse to play. -- \ ?Of all classes the rich are the most noticed and the least | `\ studied.? ?John Kenneth Galbraith, _The Age of Uncertainty_, | _o__) 1977 | Ben Finney From rustompmody at gmail.com Thu May 8 02:50:51 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 7 May 2014 23:50:51 -0700 (PDT) Subject: The "does Python have variables?" debate In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <87y4ycvllg.fsf@elektro.pacujo.net> Message-ID: <77bf971a-53d6-422c-ae69-e3a0245050c2@googlegroups.com> On Thursday, May 8, 2014 12:10:45 PM UTC+5:30, Ben Finney wrote: > Marko Rauhamaa writes: > > What you are describing is that Python has pointer semantics. > That doesn't describe it, no. To my eye, "pointer semantics" entails > that one can directly pass a pointer around as a value (which can't be > done for Python references), and that one can de-reference a pointer to > get the value pointed at (which can't be done for Python references). > > Your example, properly understood and translated, will yield > > Python-esque results in any programming language: > > #!/bin/bash > > a = /tmp/xyz > > touch $a > Of course, if you feel free to turn "assignment" into something that > isn't assignment at all, you can get different results. But to do so, > you've had to ignore the language's native assignment operator, which > *doesn't* work that way. > I get the impression you're no longer engaging in this discussion trying > to learn, but rather to score points. I refuse to play. I get the impression that you dont get the difference (I think Marko is making) between - language has pointers - language has pointer semantics From marko at pacujo.net Thu May 8 03:03:07 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 08 May 2014 10:03:07 +0300 Subject: The "does Python have variables?" debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <87y4ycvllg.fsf@elektro.pacujo.net> <77bf971a-53d6-422c-ae69-e3a0245050c2@googlegroups.com> Message-ID: <87eh04vjkk.fsf@elektro.pacujo.net> Rustom Mody : > I get the impression that you dont get the difference (I think Marko > is making) between > - language has pointers > - language has pointer semantics Yes. Like Python, Java doesn't have pointers. However, when you try to dereference null, a NullPointerException is thrown. Pointers shining through... Lisp never tried to pretend otherwise. Any introductory lisp tutorial will draw pictures of CAR/CDR cells with pointers coming out. Marko From antoon.pardon at rece.vub.ac.be Thu May 8 03:44:45 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 08 May 2014 09:44:45 +0200 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: Message-ID: <536B35ED.70102@rece.vub.ac.be> On 07-05-14 16:32, Grant Edwards wrote: >> So I'm not sure that what you want to do is the polite thing to do. > Why not? Nevermind, I originally hadn't thought things completly through. -- Antoon Pardon From johannes.schneider at galileo-press.de Thu May 8 03:26:57 2014 From: johannes.schneider at galileo-press.de (Johannes Schneider) Date: Thu, 08 May 2014 09:26:57 +0200 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: <85eh05cdjx.fsf@benfinney.id.au> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> Message-ID: <536B31C1.5010400@galileo-press.de> On 08.05.2014 02:35, Ben Finney wrote: > Marko Rauhamaa writes: [..] > Python, on the other hand, has this behaviour:: > > foo = [1, 2, 3] > bar = foo # ?bar? binds to the value ?[1, 2, 3]? > assert foo == bar # succeeds > foo[1] = "spam" # ?foo? *and* ?bar? now == [1, "spam", 3] [..] IMHO this is the behavior of having a variable pointing to it's value; foo to the list and bar to foo. consider the following: >>> def f(l): ... l[1] = 'foo' ... >>> l1 = [1,2,3] >>> f(l1) >>> l1 [1, 'foo', 3] this means, l1 consists of "pointers" to its values. Otherwise, it's not calling by reference, because >>> g(l1) >>> l1 [1, 'foo', 3] does not change l1. Once again, if I pass an object it behaves like calling by reference: >>> class A: ... a = 0 ... >>> a = A() >>> a.a 0 >>> def h(a1): ... a1.a = 1 ... >>> h(a) >>> a.a 1 bg, Johannes -- Johannes Schneider Webentwicklung johannes.schneider at galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Gesch?ftsf?hrer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn From joseph.martinot-lagarde at m4x.org Thu May 8 04:07:11 2014 From: joseph.martinot-lagarde at m4x.org (Joseph Martinot-Lagarde) Date: Thu, 08 May 2014 10:07:11 +0200 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: <85eh05cdjx.fsf@benfinney.id.au> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> Message-ID: <536B3B2F.8060200@m4x.org> Le 08/05/2014 02:35, Ben Finney a ?crit : > Marko Rauhamaa writes: > >> Ben Finney : >> >>> That's why I always try to say ?Python doesn't have variables the way >>> you might know from many other languages?, >> >> Please elaborate. To me, Python variables are like variables in all >> programming languages I know. > > Many established and still-popular languages have the following > behaviour:: > > # pseudocode > > foo = [1, 2, 3] > bar = foo # bar gets the value [1, 2, 3] > assert foo == bar # succeeds > foo[1] = "spam" # foo is now == [1, "spam", 3] > assert foo == bar # FAILS, ?bar? == [1, 2, 3] > > This is because such languages treat each variable as ?containing? a > value. Assignment puts another copy of the value in the variable, after > which those two values have a distinct history. What happens to one > value does not affect the other. > > Python, on the other hand, has this behaviour:: > > foo = [1, 2, 3] > bar = foo # ?bar? binds to the value ?[1, 2, 3]? > assert foo == bar # succeeds > foo[1] = "spam" # ?foo? *and* ?bar? now == [1, "spam", 3] > assert foo == bar # succeeds, ?bar? is bound to ?[1, "spam", 3]? > > The assignment statement in Python does not put a value in a container, > the way it does for variables in many popular languages. Instead, > assignment binds the left-hand-side reference (in these examples, names) > to the right-hand-side value. Both remain references to the same value > until the binding changes to some other value. > > So Python doesn't have variables in the way programmers coming from many > other languages expect. Instead, it has references bound to values. > For me, names bound to values is the same concept as pointer pointing to memory. bar = foo copies the pointer and not the underlying memory. This is not a foreign concept to C programmers. --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com From rosuav at gmail.com Thu May 8 04:14:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 18:14:48 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDigJxkb2VzIFB5dGhvbiBoYXZlIHZhcmlhYmxlcz/igJ0gZGViYXRl?= In-Reply-To: <536B3B2F.8060200@m4x.org> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <536B3B2F.8060200@m4x.org> Message-ID: On Thu, May 8, 2014 at 6:07 PM, Joseph Martinot-Lagarde wrote: > For me, names bound to values is the same concept as pointer pointing to > memory. bar = foo copies the pointer and not the underlying memory. This is > not a foreign concept to C programmers. > That is how it's implemented in CPython, after all... modulo the whole refcounting thing, of course. But that's not strictly a part of the definition of Python; it's just implementation. You could implement Python on pencil-and-paper (aka a dry run), and as long as you have a concept of names that reference objects, it's going to be fine. The "reference" might be done with a physical piece of string connecting a Post-It note with a name to a box with the object's state, meaning there's no way of copying any pointer, and it's still Python. ChrisA From ben at benfinney.id.au Thu May 8 04:34:21 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 08 May 2014 18:34:21 +1000 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> Message-ID: <85bnv8brea.fsf@benfinney.id.au> Ned Batchelder writes: > I thought we were concerned with beginners incorrectly thinking Python > worked like C, but this [pseudocode] is nothing like C. I'm not concerned about where these misconceptions come from, whether C or any other language. The concern is that the term ?variable?'s existing baggage in the programming community encourages *false inferences* that a beginner doesn't even realise they're drawing. By discouraging use of that term and replacing it with ?name binding? or ?reference?, a more accurate model is implied, to the extent that its existing baggage encourages significantly fewer false inferences. (good sigmonster, have a cookie) -- \ ?We suffer primarily not from our vices or our weaknesses, but | `\ from our illusions.? ?Daniel J. Boorstin, historian, 1914?2004 | _o__) | Ben Finney From marko at pacujo.net Thu May 8 05:43:29 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 08 May 2014 12:43:29 +0300 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> Message-ID: <87ha50hagu.fsf@elektro.pacujo.net> Ben Finney : > The concern is that the term ?variable?'s existing baggage in the > programming community encourages *false inferences* that a beginner > doesn't even realise they're drawing. By discouraging use of that term > and replacing it with ?name binding? or ?reference?, a more accurate > model is implied, to the extent that its existing baggage encourages > significantly fewer false inferences. I don't think flogging the beginner for talking about variables helps them get Python's data model. All that accomplishes is that they will shut up about variables in the fear of being flogged and not understand the data model any better. Any C programmer will get Python easily because they are familiar with malloc() and pointers. You will have more trouble with the beginner who has no prior programming knowledge. Do you first have to drag them along the keel by teaching them C and them graduating them to higher-level programming languages? Back to the topic of variables. IMO the crucial factor that makes Python's variables ordinary, prosaic, programming language variables is the assignment. A real "non-variable" name-value binding would be permanent. Lisp without setq (or scheme without set!) would be such a language; in fact, the implementation would then not have anything resembling variables on the inside. It's the resettability that makes a variable a mundane memory slot, whether you have access to its address or not. (BTW, in lambda calculus and predicate logic, the names cannot be rebound, but they are still called variables.) Marko From robin at reportlab.com Thu May 8 06:34:01 2014 From: robin at reportlab.com (Robin Becker) Date: Thu, 08 May 2014 11:34:01 +0100 Subject: data: protocol In-Reply-To: <536afe13$0$11109$c3e8da3@news.astraweb.com> References: <536afe13$0$11109$c3e8da3@news.astraweb.com> Message-ID: <536B5D99.1020509@chamonix.reportlab.co.uk> On 08/05/2014 04:46, Steven D'Aprano wrote: > On Wed, 07 May 2014 11:42:24 +0100, Robin Becker wrote: > >> I have an outstanding request for ReportLab to allow images to be opened >> using the data: scheme. That used to be supported in python 2.7 using >> urllib, but in python 3.3 urllib2 --> urllib and at least the default >> urlopener doesn't support data: > > > It looks like you intended to show an example, but left it out. > >> Is there a way to use the residual legacy of the old urllib code that's >> now in urllib.URLopener to open unusual schemes? I know it can be used >> directly eg >> >> urllib.request.URLopener().open('data:.........') >> >> but that seems to leave the splitting & testing logic up to me when it >> logically belongs in some central place ie urllib.request.urlopen. > > You may need to explain in a little more detail. When you say "splitting > and testing", what are you splitting and testing? It may also help if you > show some Python 2.7 code that works, and what happens in 3.3. > > OK not sure about 3.4, but in 3.3 the urllib module cannot open a request like this C:\code-trunk\hg-repos\reportlab\tests>\python33\python.exe Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib.request >>> urllib.request.urlopen('data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=').read() Traceback (most recent call last): File "", line 1, in File "C:\python33\lib\urllib\request.py", line 156, in urlopen return opener.open(url, data, timeout) File "C:\python33\lib\urllib\request.py", line 469, in open response = self._open(req, data) File "C:\python33\lib\urllib\request.py", line 492, in _open 'unknown_open', req) File "C:\python33\lib\urllib\request.py", line 447, in _call_chain result = func(*args) File "C:\python33\lib\urllib\request.py", line 1310, in unknown_open raise URLError('unknown url type: %s' % type) urllib.error.URLError: >>> in python27 one can do C:\tmp>python Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> data=urllib.urlopen('data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=').read() >>> len(data) 35 >>> and as indicated by Ian Kelly in 3.4 C:\tmp>\python34\python.exe Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib.request >>> data=urllib.request.urlopen('data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=').read() >>> len(data) 35 in 3.3 we have the old code URLopener class. However, when I use that I see this C:\code-trunk\hg-repos\reportlab\tests>\python33\python.exe Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from urllib.request import URLopener >>> data = URLopener().open('data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=').read() >>> len(data) 115 >>> data 'Date: Thu, 08 May 2014 10:21:45 GMT\nContent-type: image/gif\nContent-Length: 35\n\nGIF87a\x01\x00\x01\x00\x80\x00\x00? ???????????,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;' >>> so I seem to be getting the real data and some headers now. I think this is different from what is expected, but that code is labelled as old/deprecated and possibly going away. Since urllib doesn't always work as expected in 3.3 I've had to write a small stub for the special data: case. Doing all the splitting off of the headers seems harder than just doing the special case. However, there are a lot of these 'schemes' so should I be doing this sort of thing? Apparently it's taken 4 versions of python to get urllib in 3.4 to do this so it's not clear to me whether all schemes are supposed to hang off urllib.request.urlopen or if instead of special casing the 3.3 data: I should have special cased a handler for it and injected that into my opener (or possibly the default opener). Doing the handler means I do have to handle the headers stuff whereas my stub is just returning the data bits. -- Robin Becker From jamiemitchell1604 at gmail.com Thu May 8 06:33:32 2014 From: jamiemitchell1604 at gmail.com (Jamie Mitchell) Date: Thu, 8 May 2014 03:33:32 -0700 (PDT) Subject: Saving a file as netCDF4 in Python Message-ID: Dear all, Apologies as this sounds like a very simple question but I can't find an answer anywhere. I have loaded a netCDF4 file into python as follows: swh=netCDF4.Dataset('path/to/netCDFfile,'r') I then isolate the variables I wish to plot: hs=swh.variables['hs'] year=swh.variables['year'] I would then like to save these hs and year variables so that I don't have to isolate them every time I want to plot them. Any help would be much appreciated. Cheers, Jamie From ben at benfinney.id.au Thu May 8 07:14:12 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 08 May 2014 21:14:12 +1000 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> Message-ID: <857g5wbjzv.fsf@benfinney.id.au> Marko Rauhamaa writes: > I don't think flogging the beginner for talking about variables helps > them get Python's data model. All that accomplishes is that they will > shut up about variables in the fear of being flogged and not understand > the data model any better. Who does that? I haven't seen anyone raising this topic with a beginner in a hostile manner (?flogging?? why the hyperbole?), and it's certainly not characteristic of how the topic is raised here. I don't know what your point is, but please don't prop up straw men to make it. -- \ ?Humanity has advanced, when it has advanced, not because it | `\ has been sober, responsible, and cautious, but because it has | _o__) been playful, rebellious, and immature.? ?Tom Robbins | Ben Finney From marko at pacujo.net Thu May 8 08:01:49 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 08 May 2014 15:01:49 +0300 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> Message-ID: <8738gkh42a.fsf@elektro.pacujo.net> Ben Finney : > Marko Rauhamaa writes: > >> I don't think flogging the beginner for talking about variables helps >> them get Python's data model. All that accomplishes is that they will >> shut up about variables in the fear of being flogged and not >> understand the data model any better. > > Who does that? I haven't seen anyone raising this topic with a > beginner in a hostile manner (?flogging?? why the hyperbole?), and > it's certainly not characteristic of how the topic is raised here. Flogging, spanking, admonishing, whatever. > I don't know what your point is, but please don't prop up straw men to > make it. Does that count as admonishing, at least? Point being, shunning the term "variable" is counterproductive. Python variables are nothing special and calling them "variables" doesn't mislead anybody. Marko From robin at reportlab.com Thu May 8 06:34:01 2014 From: robin at reportlab.com (Robin Becker) Date: Thu, 08 May 2014 11:34:01 +0100 Subject: data: protocol In-Reply-To: <536afe13$0$11109$c3e8da3@news.astraweb.com> References: <536afe13$0$11109$c3e8da3@news.astraweb.com> Message-ID: <536B5D99.1020509@chamonix.reportlab.co.uk> On 08/05/2014 04:46, Steven D'Aprano wrote: > On Wed, 07 May 2014 11:42:24 +0100, Robin Becker wrote: > >> I have an outstanding request for ReportLab to allow images to be opened >> using the data: scheme. That used to be supported in python 2.7 using >> urllib, but in python 3.3 urllib2 --> urllib and at least the default >> urlopener doesn't support data: > > > It looks like you intended to show an example, but left it out. > >> Is there a way to use the residual legacy of the old urllib code that's >> now in urllib.URLopener to open unusual schemes? I know it can be used >> directly eg >> >> urllib.request.URLopener().open('data:.........') >> >> but that seems to leave the splitting & testing logic up to me when it >> logically belongs in some central place ie urllib.request.urlopen. > > You may need to explain in a little more detail. When you say "splitting > and testing", what are you splitting and testing? It may also help if you > show some Python 2.7 code that works, and what happens in 3.3. > > OK not sure about 3.4, but in 3.3 the urllib module cannot open a request like this C:\code-trunk\hg-repos\reportlab\tests>\python33\python.exe Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib.request >>> urllib.request.urlopen('data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=').read() Traceback (most recent call last): File "", line 1, in File "C:\python33\lib\urllib\request.py", line 156, in urlopen return opener.open(url, data, timeout) File "C:\python33\lib\urllib\request.py", line 469, in open response = self._open(req, data) File "C:\python33\lib\urllib\request.py", line 492, in _open 'unknown_open', req) File "C:\python33\lib\urllib\request.py", line 447, in _call_chain result = func(*args) File "C:\python33\lib\urllib\request.py", line 1310, in unknown_open raise URLError('unknown url type: %s' % type) urllib.error.URLError: >>> in python27 one can do C:\tmp>python Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> data=urllib.urlopen('data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=').read() >>> len(data) 35 >>> and as indicated by Ian Kelly in 3.4 C:\tmp>\python34\python.exe Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib.request >>> data=urllib.request.urlopen('data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=').read() >>> len(data) 35 in 3.3 we have the old code URLopener class. However, when I use that I see this C:\code-trunk\hg-repos\reportlab\tests>\python33\python.exe Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from urllib.request import URLopener >>> data = URLopener().open('data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=').read() >>> len(data) 115 >>> data 'Date: Thu, 08 May 2014 10:21:45 GMT\nContent-type: image/gif\nContent-Length: 35\n\nGIF87a\x01\x00\x01\x00\x80\x00\x00? ???????????,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;' >>> so I seem to be getting the real data and some headers now. I think this is different from what is expected, but that code is labelled as old/deprecated and possibly going away. Since urllib doesn't always work as expected in 3.3 I've had to write a small stub for the special data: case. Doing all the splitting off of the headers seems harder than just doing the special case. However, there are a lot of these 'schemes' so should I be doing this sort of thing? Apparently it's taken 4 versions of python to get urllib in 3.4 to do this so it's not clear to me whether all schemes are supposed to hang off urllib.request.urlopen or if instead of special casing the 3.3 data: I should have special cased a handler for it and injected that into my opener (or possibly the default opener). Doing the handler means I do have to handle the headers stuff whereas my stub is just returning the data bits. -- Robin Becker From roy at panix.com Thu May 8 08:41:30 2014 From: roy at panix.com (Roy Smith) Date: Thu, 08 May 2014 08:41:30 -0400 Subject: The “does Python have variables?” debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: In article , Jerry Hill wrote: > thinking of python variables as having two parts -- names and values > -- really can help people who are struggling to learn the language. There's many levels of learning, and we see them all on this list. For people who are just learning programming, and are learning Python as their first language, we need to keep things simple. These are the people who are still struggling to understand basic concepts such as algorithms, loops, and the most fundamental data structures. For those people, talking about variables as a container to hold a value is the right level of abstraction. At some point, that model no longer fits reality well enough that it becomes a barrier to further learning. When I write: def mutate(x, y): x = 42 y[0] = 42 x = 4 y = [4] mutate(x, y) print x, y and run it, unless I really understand about name binding and argument passing, I'm going to be totally befuddled by the result. At that point, I need to unlearn something I thought I understood, and that's really hard (en.wikipedia.org/wiki/Principles_of_learning#Primacy). So, this leads us to the classic dilemma in teaching. If I simplify things at first, it's easier to learn initially, but I'm setting the student up for problems later. If I try to be 100% correct about everything initially, it's like drinking from a firehose. It's hard to say which is better. I do know that when I first learned F = M * A in high-school physics, we didn't worry about what happens if the M is moving very fast, or is very small, or if its quarks are spinning in the wrong direction. OK, so that takes care of newbies. There's another whole class of people who learn Python. These are the people who have been doing this for a long time. They already know several of C, C++, Java, Lisp, Javascript, Go, Fortran, Pascal, Forth, etc. For them, learning a new language is an entirely different process from the newbie. For them, it's just a matter of "Oh, yeah, Python does classes this way, and has that kind of scoping, and the standard library includes this bunch of data structures, and ints are really bignums, and this flavor of strings, and there's some funky whitespace thing going on". Those are the people who want to know about name binding up front. From rosuav at gmail.com Thu May 8 08:54:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 22:54:24 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDigJxkb2VzIFB5dGhvbiBoYXZlIHZhcmlhYmxlcz/igJ0gZGViYXRl?= In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: On Thu, May 8, 2014 at 10:41 PM, Roy Smith wrote: > At some point, that model no longer fits reality well enough that it > becomes a barrier to further learning. When I write: > > def mutate(x, y): > x = 42 > y[0] = 42 > > x = 4 > y = [4] > > mutate(x, y) > print x, y > > and run it, unless I really understand about name binding and argument > passing, I'm going to be totally befuddled by the result. Easiest way to explain that is probably to just say, right at the beginning, that *assignment to a name is special*. When you assign to x inside mutate(), stuff happens. You're not assigning to y, so different stuff happens. If you called a method on y, or anything like that, it'd be the same kind of "stuff" as you're seeing here; but assigning directly to the name is a different sort of operation from everything else. (Explaining the difference between "x = x + 1" and "x += 1" can come later. MUCH later, probably when you try to augassign to a tuple's element.) The advantage of singling out assignment is that, as well as handling the difference between rebinding and mutation, it also picks up the magic "this is now local" mode change. Compare: x = [1,2,3] def mutate1(): x += [4] def mutate2(): x.append(4) One of them needs a 'global' declaration to work, and the other doesn't, because assigning is special. ChrisA From steve+comp.lang.python at pearwood.info Thu May 8 09:18:10 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2014 13:18:10 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> Message-ID: <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 08 May 2014 12:43:29 +0300, Marko Rauhamaa wrote: > Ben Finney : > >> The concern is that the term ?variable?'s existing baggage in the >> programming community encourages *false inferences* that a beginner >> doesn't even realise they're drawing. By discouraging use of that term >> and replacing it with ?name binding? or ?reference?, a more accurate >> model is implied, to the extent that its existing baggage encourages >> significantly fewer false inferences. > > I don't think flogging the beginner for talking about variables Nobody has suggested flogging anyone, not even figuratively. Unless you believe that correcting a misapprehension, no matter how gently it is done, is a flogging, I don't see how you draw the conclusion that Ben is talking about flogging anyone. > helps > them get Python's data model. All that accomplishes is that they will > shut up about variables in the fear of being flogged and not understand > the data model any better. So far, we have had at least two people (myself and Jerry Hill) have stated that the names/values model has helped them learn the language. One of them (me) has even stated that the meme "Python has no variables" ACTIVELY HELPED (sorry for shouting) in learning the language as a beginner. In contrast, we have some experts (like Ned) disagree with the meme, but I haven't seen anyone state that the meme "Python has no variables" has *hurt* their understanding. (I suspect that now I've raised this issue, some people will make a point of explicitly saying so, to counter my point.) In any case, I regularly see people confused by wrongly applying C-like variable semantics to Python. E.g. the idea that Python may have pass by reference semantics comes up regularly. So is the idea that one can use id() to get a pointer to a variable, usually followed by the question "how do I dereference that pointer". I'm yet to see anyone whose understanding of Python was hurt by the "no variables" meme. So... although I don't go quite so far as Ben in thinking that using the term "variable" in describing Python is harmful, I will say that the "no variables" meme is *useful* precisely because it is so shocking and so counter-intuitive that it forces[1] you to question your assumptions about how programming languages operate. > Any C programmer will get Python easily because they are familiar with > malloc() and pointers. They'll easily get Python *wrong* if they apply C semantics to Python, which many of them do. > You will have more trouble with the beginner who > has no prior programming knowledge. Do you first have to drag them along > the keel by teaching them C and them graduating them to higher-level > programming languages? Good gods no. Teaching C is perhaps not as bad as teaching then BASIC, but that's a cruel and counter-productive thing to do to them if you want them to understand Python semantics. If you want them to learn Python, teach them Python. > Back to the topic of variables. IMO the crucial factor that makes > Python's variables ordinary, prosaic, programming language variables is > the assignment. A real "non-variable" name-value binding would be > permanent. Ah, you're contrasting the idea of "variable" with "constant". > Lisp without setq (or scheme without set!) would be such a > language; in fact, the implementation would then not have anything > resembling variables on the inside. It's the resettability that makes a > variable a mundane memory slot, whether you have access to its address > or not. That does not make even a little sense. That's like saying that it's the presence of protein molecules in a hamburger that makes it soup. The ability to rebind a name is not part of the definition of a memory slot. Memory slots are not necessarily rebindable -- a memory slot might be constant. Name bindings, whether variable or constant, may not have a fixed address. They might be key/value pairs in a dict, where the key is quite capable of being moved, as they are in Python -- dicts can be resized, even shrunk, and keys may move when they do so. In Jython, the entire dict can move in memory, since Java's memory management allows objects to be moved, unlike C-based implementations. Or we might be talking about a language implemented in some exotic computing device, using clockwork, hydraulics, DNA recombination, or Conway's Game Of Life (which is Turing Complete), none of which have the concept of memory locations. The fact that you seem to believe that *memory locations* are somehow fundamental to computing goes to show just how pernicious the concept is. > (BTW, in lambda calculus and predicate logic, the names cannot be > rebound, but they are still called variables.) > > > Marko [1] Not actually forced, of course, because rejecting the claim as "obviously wrong" without thought is possible. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Thu May 8 09:22:00 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2014 13:22:00 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <536B3B2F.8060200@m4x.org> Message-ID: <536b84f7$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 08 May 2014 18:14:48 +1000, Chris Angelico wrote: > On Thu, May 8, 2014 at 6:07 PM, Joseph Martinot-Lagarde > wrote: >> For me, names bound to values is the same concept as pointer pointing >> to memory. bar = foo copies the pointer and not the underlying memory. >> This is not a foreign concept to C programmers. >> >> > That is how it's implemented in CPython, after all... modulo the whole > refcounting thing, of course. But that's not strictly a part of the > definition of Python; it's just implementation. Yes. And that's *not* how Jython or IronPython implement it, since neither Java nor .Net provide pointers (in the C sense). Nor does PyPy, which is Python written in Python (to be pedantic, RPython). Now obviously you need to have *some* way to implement indirect references. If this were 1965 or so and we were implementing Python in FORTRAN, we'd use a big array and use array indexes as our "pointers". After all, isn't that what C pointers are like? The index (address) of a block of memory in a giant array (the heap)? Given the architecture of our computing devices, I would expect that if you go down deep enough, you would find something like a C pointer. But Python is not necessarily implemented on such a device. In principle, we could write a Python interpreter on a Turing machine, or using clockwork. "Python uses pointers" is an *implementation detail*, not a language feature. > You could implement > Python on pencil-and-paper (aka a dry run), and as long as you have a > concept of names that reference objects, it's going to be fine. The > "reference" might be done with a physical piece of string connecting a > Post-It note with a name to a box with the object's state, meaning > there's no way of copying any pointer, and it's still Python. Yes, exactly. -- Steven D'Aprano http://import-that.dreamwidth.org/ From invalid at invalid.invalid Thu May 8 09:28:48 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 8 May 2014 13:28:48 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? References: <536A4BF7.6040000@arskom.com.tr> Message-ID: On 2014-05-07, Ian Kelly wrote: > On May 7, 2014 9:13 AM, "Chris Angelico" wrote: >> >> On Thu, May 8, 2014 at 1:06 AM, Burak Arslan > wrote: >> > Seeing how discussion is still going on about this, I'd like to state >> > once more what I said above in other words: You just need to do this: >> > >> > "Received: blah\r\n" + message.to_string() >> > >> > or better: >> > >> > socket.write("Received: blah\r\n") >> > socket.write(message.to_string()) >> > >> > And again, this is not a hack, this is how it's supposed to work. >> >> Yes, that method does work... if you're taking it in and sending it >> right out again. But it means you have to hang onto two pieces of data >> - the message and the new Received header - until you write it to a >> file/socket. > > Alternatively, you could use a BytesIO to prepend the Received header to > the raw data *before* you parse it with the email module. That's probably what I ought to do. But subclassing Message and adding a prepend_header was just too easy, and it avoids having to have my app know anything about the format of an email message in general or a header in particular. For example, I don't know what characters (if any) need to be escaped or specially encoded in the contents of a header. I also don't remember off the top of my head what you're supposed to do with headers that get too long (I think you just stick in a \r\n followed by some whitespace and then continue the header, but I'd have to look that up and then test it). I did know how to insert a tuple of two strings at the beginning of a list. :) -- Grant Edwards grant.b.edwards Yow! All this time I've at been VIEWING a RUSSIAN gmail.com MIDGET SODOMIZE a HOUSECAT! From invalid at invalid.invalid Thu May 8 09:31:17 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 8 May 2014 13:31:17 +0000 (UTC) Subject: Using ssl.wrap_socket() in chroot jail References: Message-ID: On 2014-05-08, Chris Angelico wrote: > On Thu, May 8, 2014 at 4:51 AM, Grant Edwards wrote: >> Unfortunately, the actual SSL wrapping stuff isn't being done in my >> code. It's being done by the secure-smtpd module, which will pass >> whatever cert/key params I give it to ssl.wrap_socket(). That still >> leaves the third option (e.g. stunnel). > > I'll go back to the naughty-crazy idea of monkey-patching, then: can > you create an SSLContext prior to chrooting, then stuff its > wrap_socket back into the ssl module? Probably. I'll have to give that a try after I figure out some of the other "Unix daemon" issues. Any imports that happen after chroot()ing are going to fail (I think), and I'm not sure if that's going to be a problem or not... -- Grant Edwards grant.b.edwards Yow! Do you like "TENDER at VITTLES"? gmail.com From ethan at stoneleaf.us Thu May 8 09:18:15 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 May 2014 06:18:15 -0700 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: <536B8417.60307@stoneleaf.us> On 05/08/2014 05:41 AM, Roy Smith wrote: > In article , > Jerry Hill wrote: > >> thinking of python variables as having two parts -- names and values >> -- really can help people who are struggling to learn the language. > > There's many levels of learning, and we see them all on this list. > > For people who are just learning programming, and are learning Python as > their first language, we need to keep things simple. These are the > people who are still struggling to understand basic concepts such as > algorithms, loops, and the most fundamental data structures. For those > people, talking about variables as a container to hold a value is the > right level of abstraction. -1 There is nothing wrong with simplifying concepts for newbies, but use one that fits the language. There is nothing difficult with either the sticky note analogy or the pieces of paper and a string analogy. Teaching someone that Python variables are containers is a massive fail. > OK, so that takes care of newbies. There's another whole class of > people who learn Python. These are the people who have been doing this > for a long time. There's also the whole class of programmers who only know one language, or only a small handful of related languages that all pretty much operate the same as far as variables are concerned. The simple analogies is also helpful for them. -- ~Ethan~ From rosuav at gmail.com Thu May 8 09:46:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 23:46:31 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDigJxkb2VzIFB5dGhvbiBoYXZlIHZhcmlhYmxlcz/igJ0gZGViYXRl?= In-Reply-To: <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 8, 2014 at 11:18 PM, Steven D'Aprano wrote: > So... although I don't go quite so far as Ben in thinking that using the > term "variable" in describing Python is harmful, I will say that the "no > variables" meme is *useful* precisely because it is so shocking and so > counter-intuitive that it forces[1] you to question your assumptions > about how programming languages operate. Maybe the shock value is helpful, but that doesn't mean the statement's strictly correct. It seems that every time we have one of these discussions, someone claims that Python's name->object bindings are utterly unique in the world of programming, which is patently false, as a number of other languages do the same thing (often calling them variables). So what does "Python doesn't have variables" mean? Really it's "Python doesn't have variables like C's or Pascal's". ChrisA From rosuav at gmail.com Thu May 8 09:47:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 May 2014 23:47:34 +1000 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: <536A4BF7.6040000@arskom.com.tr> Message-ID: On Thu, May 8, 2014 at 11:28 PM, Grant Edwards wrote: > I also don't remember off the top of my head what you're > supposed to do with headers that get too long (I think you just stick > in a \r\n followed by some whitespace and then continue the header, > but I'd have to look that up and then test it). That would be correct, fwiw. ChrisA From marko at pacujo.net Thu May 8 10:03:48 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 08 May 2014 17:03:48 +0300 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: <87y4ycfjuj.fsf@elektro.pacujo.net> Ethan Furman : > On 05/08/2014 05:41 AM, Roy Smith wrote: >> For those people, talking about variables as a container to hold a >> value is the right level of abstraction. > > [...] > > Teaching someone that Python variables are containers is a massive fail. But that's what they are. We are really debating on the suitability of a metaphor. The palm of my hand is a "container" for a horse. You can ask, Which horse are you holding? when it's only the reins I'm holding. Or maybe we can think of Python's data model as a city with structures of different sizes and shapes. A variable is a container that holds the address of a structure... Marko From torriem at gmail.com Thu May 8 10:06:40 2014 From: torriem at gmail.com (Michael Torrie) Date: Thu, 08 May 2014 08:06:40 -0600 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536B8F70.1050208@gmail.com> On 05/08/2014 07:18 AM, Steven D'Aprano wrote: > Nobody has suggested flogging anyone, not even figuratively. Unless you > believe that correcting a misapprehension, no matter how gently it is > done, is a flogging, I don't see how you draw the conclusion that Ben is > talking about flogging anyone. Agreed, although this entire thread of conversation kind of illustrates a kind of debating of issues that happen regularly on this mailing list and probably does turn off a lot of newbies, and probably turned off the original poster a long time ago. Kind of reminds me of the three-headed knight scene in Monty Python. While the heads debate amongst themselves, Robin sneaks off and the heads don't even notice. Here, someone comes along and asks the list a question, and while answering the question, the discussion rapidly takes off in its own direction as members debate some underlying fact that may or may not be important to the original poster. In fact by now I'm sure most people have completely forgotten the original post entirely and I'm can't even remember if we even answered his question. But I am pretty sure he's long gone from the lists. Of course there is also a problem of drive-by questions on this list, so we often never know if the poster did get an answer. Obviously there's nothing wrong with having this discussion in general. I think it's been quite interesting. From rosuav at gmail.com Thu May 8 10:13:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 May 2014 00:13:04 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDigJxkb2VzIFB5dGhvbiBoYXZlIHZhcmlhYmxlcz/igJ0gZGViYXRl?= In-Reply-To: <536B8F70.1050208@gmail.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536B8F70.1050208@gmail.com> Message-ID: On Fri, May 9, 2014 at 12:06 AM, Michael Torrie wrote: > Agreed, although this entire thread of conversation kind of illustrates > a kind of debating of issues that happen regularly on this mailing list > and probably does turn off a lot of newbies, and probably turned off the > original poster a long time ago. The subject line has been changed. I don't see a problem with tangential discussions that were spawned by someone's question. ChrisA From steve+comp.lang.python at pearwood.info Thu May 8 10:22:00 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2014 14:22:00 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 08 May 2014 23:46:31 +1000, Chris Angelico wrote: > On Thu, May 8, 2014 at 11:18 PM, Steven D'Aprano > wrote: >> So... although I don't go quite so far as Ben in thinking that using >> the term "variable" in describing Python is harmful, I will say that >> the "no variables" meme is *useful* precisely because it is so shocking >> and so counter-intuitive that it forces[1] you to question your >> assumptions about how programming languages operate. > > Maybe the shock value is helpful, but that doesn't mean the statement's > strictly correct. It seems that every time we have one of these > discussions, someone claims that Python's name->object bindings are > utterly unique in the world of programming, I'm pretty sure I've never seen anyone make that claim explicitly. I'm not even sure anyone has implied it, although I have seen people counter the "no variables" meme with the *accusation* that the meme wrongly makes Python out to be radically different from other programming languages. I think there is a kernel of truth to that accusation. I know that when I was first exposed to this meme, I got the impression that Python was, if not unique, at least rare. Eventually somebody challenged that meme by pointing out that Ruby, Javascript and Java use the same model, and that it is pretty much standard for high-level languages. > which is patently false, as > a number of other languages do the same thing (often calling them > variables). So what does "Python doesn't have variables" mean? Really > it's "Python doesn't have variables like C's or Pascal's". Which is what both Ben and I *explicitly* say, when we use this meme. I won't speak for Ben, but I admit that when I first came across this meme some years back, in my enthusiasm and ignorance of other languages I may not have qualified it. I was young, or at least younger, and my mental model of "variables" was 100% Pascal, so to me, the idea that Python so- called "variables" weren't *really* variables ("no true Scotsman") was quite heady and I may have been a bit over-enthusiastic for it. But you know what? It takes a lot of discipline and effort to avoid using the term "variable" in favour of "name binding". It's not just a matter of extra typing, sometimes the word *variable* as in "something that varies" is exactly the right word and trying to find an alternative is too hard. So I've settled on what I think is the right strategy: * if I need a word for "something which varies", I normally use "variable"; * if somebody appears to have misunderstood Python's semantics, often because they're applying C-like semantics to name bindings, I'll explicitly say that Python doesn't have variables in the C sense of fixed memory locations known at compile-time, and introduce them to the idea of run-time "name bindings". -- Steven D'Aprano http://import-that.dreamwidth.org/ From ethan at stoneleaf.us Thu May 8 09:46:47 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 May 2014 06:46:47 -0700 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: <536A4BF7.6040000@arskom.com.tr> Message-ID: <536B8AC7.3060103@stoneleaf.us> On 05/08/2014 06:28 AM, Grant Edwards wrote: > > Yow! All this time I've at been VIEWING a RUSSIAN MIDGET SODOMIZE a HOUSECAT! Some filtering of your sigs would be appreciated. -- ~Ethan~ From neilc at norwich.edu Thu May 8 10:47:42 2014 From: neilc at norwich.edu (Neil D. Cerutti) Date: Thu, 08 May 2014 10:47:42 -0400 Subject: The =?windows-1252?Q?=93does_Python_have_variables=3F=94?= =?windows-1252?Q?_debate?= In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> Message-ID: On 5/8/2014 8:41 AM, Roy Smith wrote: > In article , > Jerry Hill wrote: > >> thinking of python variables as having two parts -- names and values >> -- really can help people who are struggling to learn the language. > > There's many levels of learning, and we see them all on this list. > > For people who are just learning programming, and are learning Python as > their first language, we need to keep things simple. These are the > people who are still struggling to understand basic concepts such as > algorithms, loops, and the most fundamental data structures. For those > people, talking about variables as a container to hold a value is the > right level of abstraction. > > At some point, that model no longer fits reality well enough that it > becomes a barrier to further learning. When I write: > > def mutate(x, y): > x = 42 > y[0] = 42 > > x = 4 > y = [4] > > mutate(x, y) > print x, y > > and run it, unless I really understand about name binding and argument > passing, I'm going to be totally befuddled by the result. At that > point, I need to unlearn something I thought I understood, and that's > really hard (en.wikipedia.org/wiki/Principles_of_learning#Primacy). The "surprising" things can be demonstrated without using functions. Once assignment statements are mastered, the way argument passing works can be extrapolated. New programmers will have to further be taught about shadowing and scopes, while experienced programmers should already be up and running (until they try to get cute). Of course everybody has to eventually learn about the special syntax usable in function definitions and function calls. -- Neil Cerutti From skip at pobox.com Thu May 8 10:50:25 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 8 May 2014 09:50:25 -0500 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: <536B8AC7.3060103@stoneleaf.us> References: <536A4BF7.6040000@arskom.com.tr> <536B8AC7.3060103@stoneleaf.us> Message-ID: On Thu, May 8, 2014 at 8:46 AM, Ethan Furman wrote: > Some filtering of your sigs would be appreciated. Looks like a Zippy the Pinhead quote to me... http://rosinstrument.com/cgi-bin/fortune.pl/21?97 Skip From rosuav at gmail.com Thu May 8 10:51:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 May 2014 00:51:01 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDigJxkb2VzIFB5dGhvbiBoYXZlIHZhcmlhYmxlcz/igJ0gZGViYXRl?= In-Reply-To: <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 9, 2014 at 12:22 AM, Steven D'Aprano wrote: >> Maybe the shock value is helpful, but that doesn't mean the statement's >> strictly correct. It seems that every time we have one of these >> discussions, someone claims that Python's name->object bindings are >> utterly unique in the world of programming, > > I'm pretty sure I've never seen anyone make that claim explicitly. I'm > not even sure anyone has implied it, although I have seen people counter > the "no variables" meme with the *accusation* that the meme wrongly makes > Python out to be radically different from other programming languages. > > I think there is a kernel of truth to that accusation. I know that when I > was first exposed to this meme, I got the impression that Python was, if > not unique, at least rare. Eventually somebody challenged that meme by > pointing out that Ruby, Javascript and Java use the same model, and that > it is pretty much standard for high-level languages. > > >> which is patently false, as >> a number of other languages do the same thing (often calling them >> variables). So what does "Python doesn't have variables" mean? Really >> it's "Python doesn't have variables like C's or Pascal's". > > Which is what both Ben and I *explicitly* say, when we use this meme. You might, but he didn't. Compare what he wrote recently: On Wed, May 7, 2014 at 9:55 AM, Ben Finney wrote: > I don't know enough Ruby to comment there. For Java, Javascript, PHP, > they *do* have variables that work pretty much as expected by these > newcomers: the variables are declared and exist before a value is > assigned, they have the ?box containing a value? conceptual model (as > contrasted with Python's ?value with sticky-notes attached? model), the > ?how do I pass by reference or by value?? question is meaningful ? all > of these are significantly different in Python, so the term ?variable? > is useful in those other languages but mostly just a confusing obstacle > in learning Python. Implication: That Java, JavaScript, and PHP, with Ruby as the only omission, all have C/Pascal variables, and Python doesn't. Reality: Java and JavaScript follow Python-like semantics (at least as regards boxed objects, in the case of the former; unboxed integers in Java are more akin to C's integers), and PHP is... well, PHP is PHP, I don't think there's really much comparison. But even in PHP, the 'object' type more-or-less follows Python-like semantics. (There are some extreme weirdnesses as regards arrays, which are notionally copied whenever they're passed around, but it seems in most cases to be optimized to copy-on-write. I'm not sure what happens when you use a PHP reference. So I'm just going back to "PHP is PHP".) Since Ruby also follows Python-like semantics, as do Pike, and (IIUC) C#, and many other languages, the overall result is that Python is far from unique, and that the explicit "like C's or Pascal's" is important. And then the question becomes: How useful is it to argue that "Python doesn't have variables like C's or Pascal's" to someone who has never used C or Pascal? And if that person has experience with JavaScript's variables, is it as counterproductive to say "Python doesn't have variables" as to watch the Ruby people argue that it's really called pass-by-reference? ChrisA From ian.g.kelly at gmail.com Thu May 8 11:07:25 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 8 May 2014 09:07:25 -0600 Subject: data: protocol In-Reply-To: <536B5D99.1020509@chamonix.reportlab.co.uk> References: <536afe13$0$11109$c3e8da3@news.astraweb.com> <536B5D99.1020509@chamonix.reportlab.co.uk> Message-ID: On Thu, May 8, 2014 at 4:34 AM, Robin Becker wrote: > Since urllib doesn't always work as expected in 3.3 I've had to write a > small stub for the special data: case. Doing all the splitting off of the > headers seems harder than just doing the special case. > > However, there are a lot of these 'schemes' so should I be doing this sort > of thing? Apparently it's taken 4 versions of python to get urllib in 3.4 to > do this so it's not clear to me whether all schemes are supposed to hang off > urllib.request.urlopen or if instead of special casing the 3.3 data: I > should have special cased a handler for it and injected that into my opener > (or possibly the default opener). Doing the handler means I do have to > handle the headers stuff whereas my stub is just returning the data bits. The DataHandler class in 3.4 is all of 14 lines of code. My first instinct would be to backport that and add it to some OpenerDirector instance. From sjmsoft at gmail.com Thu May 8 11:51:06 2014 From: sjmsoft at gmail.com (sjmsoft at gmail.com) Date: Thu, 8 May 2014 08:51:06 -0700 (PDT) Subject: Python under the sea and in space In-Reply-To: <536ad106$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <1ea091fc-d271-4f08-ab70-edfae941bf82@googlegroups.com> <536ad106$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50c66635-828b-46f6-918d-5546c38d8c65@googlegroups.com> On Wednesday, May 7, 2014 9:34:14 PM UTC-3, Steven D'Aprano wrote: > I'm afraid I don't know what "eight miles high" in the figurative sense > means. I was referring to the Byrd's song "Eight Miles High"--purportedly a drug song. -- SJM From steve+comp.lang.python at pearwood.info Thu May 8 12:04:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2014 16:04:51 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> On Fri, 09 May 2014 00:51:01 +1000, Chris Angelico wrote: >>> which is patently false, as >>> a number of other languages do the same thing (often calling them >>> variables). So what does "Python doesn't have variables" mean? Really >>> it's "Python doesn't have variables like C's or Pascal's". >> >> Which is what both Ben and I *explicitly* say, when we use this meme. > > You might, but he didn't. Compare what he wrote recently: [...] If you want to argue that Ben is factually mistaken about Java and Javascript, go right ahead. But he earlier wrote: That's why I always try to say ?Python doesn't have variables the way you might know from many other languages? and So Python doesn't have variables in the way programmers coming from many other languages expect. Instead, it has references bound to values. Personally, I think that trying to be general and talk about "many other languages" is a failing strategy. Better to be concrete: C, Pascal, Algol, Fortran, VB (I think) are good examples of the "value in a box at a fixed location" model. Of those, Algol, Pascal and Fortran are either obsolete or legacy, and C is by far the most well-known by people here. (For some reason, few people seem to migrate from VB to Python.) Hence, "C-like". -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Thu May 8 12:10:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 May 2014 02:10:47 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDigJxkb2VzIFB5dGhvbiBoYXZlIHZhcmlhYmxlcz/igJ0gZGViYXRl?= In-Reply-To: <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 9, 2014 at 2:04 AM, Steven D'Aprano wrote: > Personally, I think that trying to be general and talk about "many other > languages" is a failing strategy. Better to be concrete: C, Pascal, > Algol, Fortran, VB (I think) are good examples of the "value in a box at > a fixed location" model. Of those, Algol, Pascal and Fortran are either > obsolete or legacy, and C is by far the most well-known by people here. > (For some reason, few people seem to migrate from VB to Python.) Hence, > "C-like". Agreed. So long as the statement is "Python doesn't have variables", I'm going to have to disagree; but "Python doesn't have variables the way C does" is definitely true, and probably as helpful as the shorter version. ChrisA From robin at reportlab.com Thu May 8 12:52:10 2014 From: robin at reportlab.com (Robin Becker) Date: Thu, 08 May 2014 17:52:10 +0100 Subject: data: protocol In-Reply-To: References: <536afe13$0$11109$c3e8da3@news.astraweb.com> <536B5D99.1020509@chamonix.reportlab.co.uk> Message-ID: <536BB63A.6090002@chamonix.reportlab.co.uk> On 08/05/2014 16:07, Ian Kelly wrote: ........ > The DataHandler class in 3.4 is all of 14 lines of code. My first which makes me wonder why the old URLopener is still there and why all this wasn't done before 3.0 appeared. > instinct would be to backport that and add it to some OpenerDirector > instance. > Using a director would be possible, but it's not much cleaner than special casing the function and I don't have to worry about which opener to use; I use the one provided by the user -- Robin Becker From none at mailinator.com Thu May 8 13:06:55 2014 From: none at mailinator.com (mm0fmf) Date: Thu, 08 May 2014 18:06:55 +0100 Subject: Python under the sea and in space In-Reply-To: References: Message-ID: On 07/05/2014 03:31, Jessica McKellar wrote: > Hi folks, > > I'm trying to determine the greatest depth (in the ocean or underground) > and highest altitude at which Python code has been executed. > [snip] > Do you have some good candidates? Please let me know! > I have executed Python code (bottle web framework) on a Raspberry Pi at 590m ASL when hill walking. The Pi provides a Wifi AP and web server, pages are viewed on a smartphone browser, data entered on the web pages gets sent to an Iridium satellite modem over a USB/serial link. It then gets downlinked and stuffed on the web. 590m is not much but I only got it all working the other week and 590m is the biggest mountain I've been up since! Andy From larry.martell at gmail.com Thu May 8 13:14:22 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 8 May 2014 11:14:22 -0600 Subject: Python under the sea and in space In-Reply-To: References: Message-ID: On Tue, May 6, 2014 at 8:31 PM, Jessica McKellar wrote: > Hi folks, > > I'm trying to determine the greatest depth (in the ocean or underground) and > highest altitude at which Python code has been executed. I have written avionics data collection apps there were used in small general aviation aircraft that flew as high as 10,000 ft and perhaps higher. From invalid at invalid.invalid Thu May 8 14:39:27 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 8 May 2014 18:39:27 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? References: <536A4BF7.6040000@arskom.com.tr> <536B8AC7.3060103@stoneleaf.us> Message-ID: On 2014-05-08, Skip Montanaro wrote: > On Thu, May 8, 2014 at 8:46 AM, Ethan Furman wrote: >> Some filtering of your sigs would be appreciated. > > Looks like a Zippy the Pinhead quote to me... > > http://rosinstrument.com/cgi-bin/fortune.pl/21?97 Yep. I've removed a few of them from the file over the years because some people were offended by them. And I'll continue to do so... -- Grant Edwards grant.b.edwards Yow! I don't understand at the HUMOUR of the THREE gmail.com STOOGES!! From lists at andros.org.uk Thu May 8 14:55:52 2014 From: lists at andros.org.uk (Andrew McLean) Date: Thu, 08 May 2014 19:55:52 +0100 Subject: Real-world use of concurrent.futures Message-ID: <536BD338.4070004@andros.org.uk> I have a problem that would benefit from a multithreaded implementation and having trouble understanding how to approach it using concurrent.futures. The details don't really matter, but it will probably help to be explicit. I have a large CSV file that contains a lot of fields, amongst them one containing email addresses. I want to write a program that validates the email addresses by checking that the domain names have a valid MX record. The output will be a copy of the file with any invalid email addresses removed. Because of latency in the DNS lookup this could benefit from multithreading. I have written similar code in the past using explicit threads communicating via queues. For this example, I could have a thread that read the file using csv.DictReader, putting dicts containing records from the input file into a (finite length) queue. Then I would have a number of worker threads reading the queue, performing the validation and putting validated results in a second queue. A final thread would read from the second queue writing the results to the output file. So far so good. However, I thought this would be an opportunity to explore concurrent.futures and to see whether it offered any benefits over the more explicit approach discussed above. The problem I am having is that all the discussions I can find of the use of concurrent.futures show use with toy problems involving just a few tasks. The url downloader in the documentation is typical, it proceeds as follows: 1. Get an instance of concurrent.futuresThreadPoolExecutor 2. Submit a few tasks to the executer 3. Iterate over the results using concurrent.futures.as_completed That's fine, but I suspect that isn't a helpful pattern if I have a very large number of tasks. In my case I could run out of memory if I tried submitting all of the tasks to the executor before processing any of the results. I'm guessing what I want to do is, submit tasks in batches of perhaps a few hundred, iterate over the results until most are complete, then submit some more tasks and so on. I'm struggling to see how to do this elegantly without a lot of messy code just there to do "bookkeeping". This can't be an uncommon scenario. Am I missing something, or is this just not a job suitable for futures? Regards, Andrew From rosuav at gmail.com Thu May 8 15:06:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 May 2014 05:06:55 +1000 Subject: Real-world use of concurrent.futures In-Reply-To: <536BD338.4070004@andros.org.uk> References: <536BD338.4070004@andros.org.uk> Message-ID: On Fri, May 9, 2014 at 4:55 AM, Andrew McLean wrote: > Because of latency in the DNS lookup this could > benefit from multithreading. Before you go too far down roads that are starting to look problematic: A DNS lookup is a UDP packet out and a UDP packet in (ignoring the possibility of TCP queries, which you probably won't be doing here). Maybe it would be easier to implement it as asynchronous networking? I don't know that Python makes it easy for you to construct DNS requests and parse DNS responses; that's something more in Pike's line of work. But it may be more possible to outright do the DNS query asynchronously. TBH I haven't looked into it; but it's another option to consider. Separately from your programming model, though, how are you handling timeouts? Any form of DNS error (NXDOMAIN being the most likely), and the sort-of-error-but-not-error state of getting a response with no answer, indicates that the address is invalid; but what if you just don't hear back from the server? Will that mark addresses off as dead? ChrisA From ben at benfinney.id.au Thu May 8 15:14:35 2014 From: ben at benfinney.id.au (Ben Finney) Date: Fri, 09 May 2014 05:14:35 +1000 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> Message-ID: <8538gkaxr8.fsf@benfinney.id.au> Marko Rauhamaa writes: > Ben Finney : > > > Who does that? I haven't seen anyone raising this topic with a > > beginner in a hostile manner (?flogging?? why the hyperbole?), and > > it's certainly not characteristic of how the topic is raised here. > > Flogging, spanking, admonishing, whatever. So, you just continue asserting that, without responding to a request to back it up. > > I don't know what your point is, but please don't prop up straw men to > > make it. > > Does that count as admonishing, at least? Yes, I admonished you. > Point being, shunning the term "variable" is counterproductive. Python > variables are nothing special and calling them "variables" doesn't > mislead anybody. Okay, that's your point. You haven't backed it up, so I'll ignore it for now. -- \ ?If you ever catch on fire, try to avoid seeing yourself in the | `\ mirror, because I bet that's what REALLY throws you into a | _o__) panic.? ?Jack Handey | Ben Finney From python.list at tim.thechases.com Thu May 8 14:48:30 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 8 May 2014 13:48:30 -0500 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: <536A4BF7.6040000@arskom.com.tr> <536B8AC7.3060103@stoneleaf.us> Message-ID: <20140508134830.75c8ec69@bigbox.christie.dr> On 2014-05-08 18:39, Grant Edwards wrote: > > Looks like a Zippy the Pinhead quote to me... > > Yep. I'm kinda disappointed having the curtain pulled back like that. I'd just assumed it was some nifty tool that turned a GPG/PGP signature into MadLibs?-style fill-in-the-blank and then flowed into various templates, allowing Grant to confirm/deny message authorship based on the unspoofability of the signature with any other message-body. Sounds like a fun weekend project ;-) -tkc From tjreedy at udel.edu Thu May 8 15:21:28 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 May 2014 15:21:28 -0400 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <536B3B2F.8060200@m4x.org> Message-ID: On 5/8/2014 4:14 AM, Chris Angelico wrote: > On Thu, May 8, 2014 at 6:07 PM, Joseph Martinot-Lagarde > wrote: >> For me, names bound to values is the same concept as pointer pointing to >> memory. You are missing a level of indirection. In CPython, a name (always in some namespace) represents a pointer to a pointer. The first pointer is calculated as an offset from the base pointer of the namespace. For a C array namespace (used for functions), the offset is constant (for that function and namespace). For a python dict namespace, the offset is calculated from the hash of the name, the size of the dict, and the previous contents of the hash table. This complication allows the namespace to grow and shrink. In either case, the second pointer if overwritten to 'rebind' the name. >> bar = foo copies the pointer and not the underlying memory. It copies the second pointer of foo, in the underlying memory pointed at by the foo's first pointer, to the memory pointed at by bar's first pointer. >> This is not a foreign concept to C programmers. Once one gets the indirection correct. > That is how it's implemented in CPython, after all... modulo the whole > refcounting thing, of course. But that's not strictly a part of the > definition of Python; it's just implementation. You could implement > Python on pencil-and-paper (aka a dry run), and as long as you have a > concept of names that reference objects, it's going to be fine. For paper-aided mental execution, most people would not bother to implement version and run dependent features, such as 'id()' and most of the possible uses of 'is' (other than 'is None', etc.). For code that also avoids such features, such shortcuts would indeed be fine. > "reference" might be done with a physical piece of string connecting a > Post-It note with a name to a box with the object's state, meaning > there's no way of copying any pointer, and it's still Python. -- Terry Jan Reedy From andrew at andros.org.uk Thu May 8 15:25:43 2014 From: andrew at andros.org.uk (Andrew McLean) Date: Thu, 08 May 2014 20:25:43 +0100 Subject: Real-world use of concurrent.futures In-Reply-To: References: <536BD338.4070004@andros.org.uk> Message-ID: <536BDA37.4030301@gmail.com> On 08/05/2014 20:06, Chris Angelico wrote: > On Fri, May 9, 2014 at 4:55 AM, Andrew McLean wrote: >> Because of latency in the DNS lookup this could >> benefit from multithreading. > Before you go too far down roads that are starting to look > problematic: A DNS lookup is a UDP packet out and a UDP packet in > (ignoring the possibility of TCP queries, which you probably won't be > doing here). Maybe it would be easier to implement it as asynchronous > networking? I don't know that Python makes it easy for you to > construct DNS requests and parse DNS responses; that's something more > in Pike's line of work. But it may be more possible to outright do the > DNS query asynchronously. TBH I haven't looked into it; but it's > another option to consider. > > Separately from your programming model, though, how are you handling > timeouts? Any form of DNS error (NXDOMAIN being the most likely), and > the sort-of-error-but-not-error state of getting a response with no > answer, indicates that the address is invalid; but what if you just > don't hear back from the server? Will that mark addresses off as dead? > > ChrisA I've done this on a very small scale in the past. I used http://www.dnspython.org/ to do the heavy lifting. The relevant bits of code looks like: > # Set up the default dns resolver and add a cache > dns.resolver.default_resolver = dns.resolver.Resolver() > dns.resolver.default_resolver.cache = dns.resolver.Cache() and > try: > result = dns.resolver.query(domain, 'MX') > return True > except dns.resolver.NXDOMAIN: > return False > except dns.resolver.NoAnswer: > return False > except dns.resolver.Timeout: > print "*** timeout looking for the MX record for the domain: > %s" % domain > return False You are right, I'll need to do something more sophisticated when I encounter a timeout, but I think that's a matter of detail. Andrew From marko at pacujo.net Thu May 8 15:45:03 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 08 May 2014 22:45:03 +0300 Subject: Real-world use of concurrent.futures References: <536BD338.4070004@andros.org.uk> Message-ID: <87tx90t5q8.fsf@elektro.pacujo.net> Chris Angelico : > Before you go too far down roads that are starting to look > problematic: A DNS lookup is a UDP packet out and a UDP packet in > (ignoring the possibility of TCP queries, which you probably won't be > doing here). Maybe it would be easier to implement it as asynchronous > networking? I don't know that Python makes it easy for you to > construct DNS requests and parse DNS responses; That's what I ended up doing when I wrote my home SMTP server. It's more tedious than difficult. You don't need to have a ready-made module for everything. An RFC and two hands take you far. Marko From marko at pacujo.net Thu May 8 15:56:02 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 08 May 2014 22:56:02 +0300 Subject: Real-world use of concurrent.futures References: Message-ID: <87ppjot57x.fsf@elektro.pacujo.net> Andrew McLean : > That's fine, but I suspect that isn't a helpful pattern if I have a > very large number of tasks. In my case I could run out of memory if I > tried submitting all of the tasks to the executor before processing > any of the results. This is related to flow control. You'll need an object for each flow (transaction). When new work comes in from the network, you'll have to see if you are hitting the maximum number of pending transactions, and not start another one before previous transactions have been processed. Whenever a transaction is completed, you pull in more work. Marko From a24061 at ducksburg.com Thu May 8 15:58:45 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 08 May 2014 20:58:45 +0100 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> Message-ID: On 2014-05-02, Dennis Lee Bieber wrote: > On Thu, 01 May 2014 21:55:20 +0100, Adam Funk > declaimed the following: > >>On 2014-05-01, Dennis Lee Bieber wrote: >>> Math teacher was selling them in my 10th grade... Actually I already >>> owned a Faber-Castell 57/22 "Business" ruler (which did NOT have the CF/DF >>> scales set for *PI) and a Pickett N-1010-ES Trig rule. >> >>What does a "business" slide-rule do? Depreciation? >> > > Special markers for: dozen, gross; a scale for "non-metric measures" to > metric equivalents -- US Bushel, UK ("brit") bushel, US gallon, UK gallon, > short and long tons, a few Russian units, "Pud" and "R.t." which appear to > map to cubic inch and cubic foot; markings for % (discount and mark-up) > > And a scheme for simple interest calculations (which may explain why > the CF/DF scales are longer than the C/D scales): "Move the main cursor > line over the principal on scale DF -- the principal must be taken only on > scale DF -- set the rate per cent on the scale CI, under the short cursor > line, and read the interest on the scale DF or D in line with the number of > days on the scale CF or C." {yes, just to the left of the normal cursor is > a short line only over the inverted C scale} Interesting, thanks. -- I used to be better at logic problems, before I just dumped them all into TeX and let Knuth pick out the survivors. -- plorkwort From marko at pacujo.net Thu May 8 16:06:27 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 08 May 2014 23:06:27 +0300 Subject: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <536B3B2F.8060200@m4x.org> Message-ID: <87lhuct4qk.fsf@elektro.pacujo.net> Terry Reedy : >> On Thu, May 8, 2014 at 6:07 PM, Joseph Martinot-Lagarde >> wrote: >>> For me, names bound to values is the same concept as pointer >>> pointing to memory. > > You are missing a level of indirection. In CPython, a name (always in > some namespace) represents a pointer to a pointer. The first pointer > is calculated as an offset from the base pointer of the namespace. For > a C array namespace (used for functions), the offset is constant (for > that function and namespace). For a python dict namespace, the offset > is calculated from the hash of the name, the size of the dict, and the > previous contents of the hash table. This complication allows the > namespace to grow and shrink. In either case, the second pointer if > overwritten to 'rebind' the name. Terry, you are talking about an implementation. Joseph is talking about the concept. You can tell a C programmer that a Python variable always holds a pointer to an object, and they get the idea right away ("Oh, so '.' in Python is the same as '->' in C") and start producing efficient, correct Python code. Marko From tjreedy at udel.edu Thu May 8 16:27:03 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 May 2014 16:27:03 -0400 Subject: Real-world use of concurrent.futures In-Reply-To: <536BD338.4070004@andros.org.uk> References: <536BD338.4070004@andros.org.uk> Message-ID: On 5/8/2014 2:55 PM, Andrew McLean wrote: > I have a problem that would benefit from a multithreaded implementation > and having trouble understanding how to approach it using > concurrent.futures. > > The details don't really matter, but it will probably help to be > explicit. I have a large CSV file that contains a lot of fields, amongst > them one containing email addresses. I want to write a program that > validates the email addresses by checking that the domain names have a > valid MX record. The output will be a copy of the file with any invalid > email addresses removed. Because of latency in the DNS lookup this could > benefit from multithreading. > > I have written similar code in the past using explicit threads > communicating via queues. For this example, I could have a thread that > read the file using csv.DictReader, putting dicts containing records > from the input file into a (finite length) queue. Then I would have a > number of worker threads reading the queue, performing the validation > and putting validated results in a second queue. A final thread would > read from the second queue writing the results to the output file. > > So far so good. However, I thought this would be an opportunity to > explore concurrent.futures and to see whether it offered any benefits > over the more explicit approach discussed above. The problem I am having > is that all the discussions I can find of the use of concurrent.futures > show use with toy problems involving just a few tasks. You might look as the new asyncio module in 3.4 (backport available on pypi, I believe). Among other things, it uses a variation on concurrent.futures. It includes timeouts. -- Terry Jan Reedy From ian.g.kelly at gmail.com Thu May 8 16:44:28 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 8 May 2014 14:44:28 -0600 Subject: Real-world use of concurrent.futures In-Reply-To: <536BD338.4070004@andros.org.uk> References: <536BD338.4070004@andros.org.uk> Message-ID: On May 8, 2014 12:57 PM, "Andrew McLean" wrote: > So far so good. However, I thought this would be an opportunity to > explore concurrent.futures and to see whether it offered any benefits > over the more explicit approach discussed above. The problem I am having > is that all the discussions I can find of the use of concurrent.futures > show use with toy problems involving just a few tasks. The url > downloader in the documentation is typical, it proceeds as follows: > > 1. Get an instance of concurrent.futuresThreadPoolExecutor > 2. Submit a few tasks to the executer > 3. Iterate over the results using concurrent.futures.as_completed > > That's fine, but I suspect that isn't a helpful pattern if I have a very > large number of tasks. In my case I could run out of memory if I tried > submitting all of the tasks to the executor before processing any of the > results. I thought that ThreadPoolExecutor.map would handle this transparently if you passed it a lazy iterable such as a generator. From my testing though, that seems not to be the case; with a generator of 100000 items and a pool of 2 workers, the entire generator was consumed before any results were returned. > I'm guessing what I want to do is, submit tasks in batches of perhaps a > few hundred, iterate over the results until most are complete, then > submit some more tasks and so on. I'm struggling to see how to do this > elegantly without a lot of messy code just there to do "bookkeeping". > This can't be an uncommon scenario. Am I missing something, or is this > just not a job suitable for futures? I don't think it needs to be "messy". Something like this should do the trick, I think: from concurrent.futures import * from itertools import islice def batched_pool_runner(f, iterable, pool, batch_size): it = iter(iterable) # Submit the first batch of tasks. futures = set(pool.submit(f, x) for x in islice(it, batch_size)) while futures: done, futures = wait(futures, return_when=FIRST_COMPLETED) # Replenish submitted tasks up to the number that completed. futures.update(pool.submit(f, x) for x in islice(it, len(done))) yield from done -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrew at andros.org.uk Thu May 8 17:18:51 2014 From: andrew at andros.org.uk (Andrew McLean) Date: Thu, 08 May 2014 22:18:51 +0100 Subject: Real-world use of concurrent.futures In-Reply-To: References: <536BD338.4070004@andros.org.uk> Message-ID: <536BF4BB.9060604@gmail.com> On 08/05/2014 21:44, Ian Kelly wrote: > I don't think it needs to be "messy". Something like this should do > the trick, I think: > > from concurrent.futures import * > from itertools import islice > > def batched_pool_runner(f, iterable, pool, batch_size): > it = iter(iterable) > # Submit the first batch of tasks. > futures = set(pool.submit(f, x) for x in islice(it, batch_size)) > while futures: > done, futures = wait(futures, return_when=FIRST_COMPLETED) > # Replenish submitted tasks up to the number that completed. > futures.update(pool.submit(f, x) for x in islice(it, len(done))) > yield from done > Thank you, that's very neat. It's just the sort of thing I was looking for. Nice use of itertools.islice and "yield from". I'll try this out in the next few days and report back. - Andrew From ethan at stoneleaf.us Thu May 8 17:50:08 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 May 2014 14:50:08 -0700 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: <8538gkaxr8.fsf@benfinney.id.au> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> Message-ID: <536BFC10.1070508@stoneleaf.us> On 05/08/2014 12:14 PM, Ben Finney wrote: > Marko Rauhamaa writes: > >> Point being, shunning the term "variable" is counterproductive. Python >> variables are nothing special and calling them "variables" doesn't >> mislead anybody. > > Okay, that's your point. You haven't backed it up, so I'll ignore it for now. I'll speak up as a data point: When I came to Python my only experience with variables was: it's a box that holds a value. So it took me a while, and a really, really good explanation with beautiful ascii art, to explain to me how Python variables work. The astute reader will notice I still called them variables. Had they been called something else I may have discovered sooner what the difference was, but I don't think it's worth mangling the (English) language. As a newcomer to Python I also didn't know that functions were first class objects, so it was a while before I realized the cool things you could do because of that -- yet we still call them functions, not, for example, callable objects. Python has variables -- they just work more like aliases. (Okay, who wants to make the graphic of a Python object in a mug shot? ;) I guess my point is, calling aliases variables wasn't the misleading part, it was my lack of knowledge that there was more than one kind of variable possible. Such ignorance is only solved by learning different languages, and isn't aided if every language has their own unique terminology. -- ~Ethan~ From simonhf at gmail.com Thu May 8 19:10:42 2014 From: simonhf at gmail.com (Simon) Date: Thu, 8 May 2014 16:10:42 -0700 (PDT) Subject: how to create an external string when binding C to Python? Message-ID: <3afe7539-e3e9-43d6-ab58-1f4aa7895b46@googlegroups.com> I'd like to make a C memory buffer available inside Python via the Python C/API without copying that memory into Python. How to do this? I've read [1] but it's not clear that this functionality exists. In javascript it's possible using String::NewExternal() [2]. "Creates a new external string using the ASCII data defined in the given resource. When the external string is no longer live on V8's heap the resource will be disposed by calling its Dispose method. The caller of this function should not otherwise delete or modify the resource. Neither should the underlying buffer be deallocated or modified except through the destructor of the external string resource." [1] https://docs.python.org/2/c-api/buffer.html [2] http://izs.me/v8-docs/classv8_1_1String.html#a07c47bf675b802c550984fa24511a589 From simonhf at gmail.com Thu May 8 19:12:32 2014 From: simonhf at gmail.com (Simon) Date: Thu, 8 May 2014 16:12:32 -0700 (PDT) Subject: how to create a zero copy external string when binding C to Python? Message-ID: I'd like to make a C memory buffer available inside Python via the Python C/API without copying that memory into Python. How to do this? I've read [1] but it's not clear that this functionality exists. In javascript it's possible using String::NewExternal() [2]. "Creates a new external string using the ASCII data defined in the given resource. When the external string is no longer live on V8's heap the resource will be disposed by calling its Dispose method. The caller of this function should not otherwise delete or modify the resource. Neither should the underlying buffer be deallocated or modified except through the destructor of the external string resource." [1] https://docs.python.org/2/c-api/buffer.html [2] http://izs.me/v8-docs/classv8_1_1String.html#a07c47bf675b802c550984fa24511a589 From ethan at stoneleaf.us Thu May 8 18:36:55 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 May 2014 15:36:55 -0700 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: <87lhuct4qk.fsf@elektro.pacujo.net> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <536B3B2F.8060200@m4x.org> <87lhuct4qk.fsf@elektro.pacujo.net> Message-ID: <536C0707.5070701@stoneleaf.us> On 05/08/2014 01:06 PM, Marko Rauhamaa wrote: > Terry Reedy : > >>> On Thu, May 8, 2014 at 6:07 PM, Joseph Martinot-Lagarde >>> wrote: >>>> For me, names bound to values is the same concept as pointer >>>> pointing to memory. >> >> You are missing a level of indirection. In CPython, a name (always in >> some namespace) represents a pointer to a pointer. The first pointer >> is calculated as an offset from the base pointer of the namespace. For >> a C array namespace (used for functions), the offset is constant (for >> that function and namespace). For a python dict namespace, the offset >> is calculated from the hash of the name, the size of the dict, and the >> previous contents of the hash table. This complication allows the >> namespace to grow and shrink. In either case, the second pointer if >> overwritten to 'rebind' the name. > > Terry, you are talking about an implementation. Joseph is talking about > the concept. > > You can tell a C programmer that a Python variable always holds a > pointer to an object, and they get the idea right away ("Oh, so '.' in > Python is the same as '->' in C") and start producing efficient, correct > Python code. Right up until they want to dereference. -- ~Ethan~ From ethan at stoneleaf.us Thu May 8 19:09:43 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 May 2014 16:09:43 -0700 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: <87y4ycfjuj.fsf@elektro.pacujo.net> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87y4ycfjuj.fsf@elektro.pacujo.net> Message-ID: <536C0EB7.2080501@stoneleaf.us> On 05/08/2014 07:03 AM, Marko Rauhamaa wrote: > Ethan Furman : >> On 05/08/2014 05:41 AM, Roy Smith wrote: >>> >>> For those people, talking about variables as a container to hold a >>> value is the right level of abstraction. >> >> Teaching someone that Python variables are containers is a massive fail. > > But that's what they are. No, it's not. > We are really debating on the suitability of a metaphor. Exactly. And the "a variable is a box that holds the value" is a great metaphor for languages that assign a name to a fixed location -- languages such as Pascal, Basic, FoxPro, and C. In these languages when you say `a = b` you now have *two* copies of the data (at least for the most part); in Python (and similar languages) you have two *names* for one copy of the data. > Or maybe we can think of Python's data model as a city with structures > of different sizes and shapes. A variable is a container that holds the > address of a structure... If that helps as a stepping stone to a true model, fine; but if that's the final destination of your understanding then you don't truly understand Python's data model. -- ~Ethan~ From breamoreboy at yahoo.co.uk Thu May 8 19:46:56 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 09 May 2014 00:46:56 +0100 Subject: how to create an external string when binding C to Python? In-Reply-To: <3afe7539-e3e9-43d6-ab58-1f4aa7895b46@googlegroups.com> References: <3afe7539-e3e9-43d6-ab58-1f4aa7895b46@googlegroups.com> Message-ID: On 09/05/2014 00:10, Simon wrote: > I'd like to make a C memory buffer available inside Python via the Python C/API without copying that memory into Python. How to do this? I've read [1] but it's not clear that this functionality exists. In javascript it's possible using String::NewExternal() [2]. > > "Creates a new external string using the ASCII data defined in the given resource. > > When the external string is no longer live on V8's heap the resource will be disposed by calling its Dispose method. The caller of this function should not otherwise delete or modify the resource. Neither should the underlying buffer be deallocated or modified except through the destructor of the external string resource." > > [1] https://docs.python.org/2/c-api/buffer.html > [2] http://izs.me/v8-docs/classv8_1_1String.html#a07c47bf675b802c550984fa24511a589 > Does this help http://jakevdp.github.io/blog/2014/05/05/introduction-to-the-python-buffer-protocol/ ? Also note that the Python 3 buffer protocol differs from that of Python 2, so make sure that you check out PEP 3118 that's referenced in the above link. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Thu May 8 20:02:55 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 May 2014 00:02:55 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> Message-ID: <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 08 May 2014 14:50:08 -0700, Ethan Furman wrote: > I guess my point is, calling aliases variables wasn't the misleading > part, it was my lack of knowledge that there was more than one kind of > variable possible. Such ignorance is only solved by learning different > languages, The *only* way? I'm feeling kind of ignored and unloved here... *wink* As I've said multiple times now, my personal experience is that "such ignorance" of different variable semantics can also be solved by explicitly rejecting the use of the term "variable". Let me put it this way: both horse-drawn carriages and cars are examples of the same general concept. "Horse-drawn carriage" is a back-formation from the time when people wished to distinguish carriages with horses from horseless carriages. Today we routinely call horseless carriages "cars", and nobody would blink if I pointed at a Prius or a Ford Explorer and said "that's not a carriage, it's a car" except to wonder why on earth I thought something so obvious needed to be said. And yet the majority view expressed on this thread is that somehow programmers are allegedly confused and distressed by the use of distinct terminology for different kinds of variable name-value bindings. Programmers tend to be more intelligent than average, they tend to know dozens or hundreds of very technical terms differing only in fine degrees of detail (I'm still not sure what the difference, if any, between *delegation* and *composition* is, or between the ever more specialist adaptor design patterns). We expect newbie programmers to learn all sorts of jargon: functions, factories, methods, class methods, static methods, types, decorators, descriptors, trampolines, threads, namespaces, mutable, immutable, properties... and yet distinguishing "variable" from "name binding" is supposed to cause more harm than good? I remain unconvinced. > and isn't aided if every language has their own unique terminology. Nobody is talking about giving every language their own unique terminology. There are, so far as I know, two general models of computational variables: the name binding in a dynamic namespace model and the static memory location model. Different languages may implement slight variations on these, for example CPython uses fixed memory locations for local variables of functions as an optimization, Java uses name binding except for unboxed native data types, traditionally Forth doesn't use fixed memory locations but a threaded list, but the basic dichotomy is very common. So to a first approximation, most languages fall fully or mostly within one of two categories: they have name bindings, or C-style variables. Name binding is even a standard computer science term: https://en.wikipedia.org/wiki/Name_binding The pedantic reader will notice that "name binding" equally applies to the C compiler associating a name with a fixed memory location at compile time ("early binding") as the Python virtual machine associating a value with a key in a namespace at run time ("late binding"). Nevertheless, for a generation of programmers raised on C, "variable" means what C does. The whole point is not that "name binding" somehow causes the reader to intuit the differences between early and late binding, or between boxes in fixed memory locations and name:value pairs in a namespace, but that it *opens their mind* to the possibility that they are using the wrong mental model. It is the start of the dialog, not the end. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ethan at stoneleaf.us Thu May 8 20:05:25 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 May 2014 17:05:25 -0700 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: <87tx91warf.fsf@elektro.pacujo.net> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> Message-ID: <536C1BC5.6000905@stoneleaf.us> Back when I was trying to learn the differences between Python's name-binding and C-like variables, a couple folks stepped up and provided great assistance. This first email, while delving into details that are not accessible in Python, still helped a great deal: https://mail.python.org/pipermail/python-list/2009-February/526880.html This next explained why the previous, while accurate from a CS standpoint, was not useful in Python as Python simply does not allow access to one of the layers, so trying to think about that layer when working with Python is not productive: https://mail.python.org/pipermail/python-list/2009-February/526909.html -- ~Ethan~ From breamoreboy at yahoo.co.uk Thu May 8 20:47:22 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 09 May 2014 01:47:22 +0100 Subject: The =?windows-1252?Q?=93does_Python_have_variables=3F=94?= =?windows-1252?Q?_debate?= In-Reply-To: <536C1BC5.6000905@stoneleaf.us> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <536C1BC5.6000905@stoneleaf.us> Message-ID: On 09/05/2014 01:05, Ethan Furman wrote: > Back when I was trying to learn the differences between Python's > name-binding and C-like variables, a couple folks stepped up and > provided great assistance. > > This first email, while delving into details that are not accessible in > Python, still helped a great deal: > > https://mail.python.org/pipermail/python-list/2009-February/526880.html > > > This next explained why the previous, while accurate from a CS > standpoint, was not useful in Python as Python simply does not allow > access to one of the layers, so trying to think about that layer when > working with Python is not productive: > > https://mail.python.org/pipermail/python-list/2009-February/526909.html > > -- > ~Ethan~ Please, please can the link directly above be regarded as the final, final say on this matter? Thank you in anticipation. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Thu May 8 20:54:25 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 May 2014 00:54:25 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> Message-ID: <536c2741$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 08 May 2014 09:26:57 +0200, Johannes Schneider wrote: > On 08.05.2014 02:35, Ben Finney wrote: >> Marko Rauhamaa writes: > [..] >> Python, on the other hand, has this behaviour:: >> >> foo = [1, 2, 3] >> bar = foo # ?bar? binds to the value ?[1, 2, 3]? assert >> foo == bar # succeeds >> foo[1] = "spam" # ?foo? *and* ?bar? now == [1, "spam", 3] > [..] > > IMHO this is the behavior of having a variable pointing to it's value; > foo to the list and bar to foo. You're almost right -- foo is a reference to the list, that is, foo "points to" the list. But the second part is completely wrong: bar does not point at *foo*, it points at the *same list* that foo points to. What's the difference? Consider this ASCII diagram (best viewed in a monospaced font): foo ------+ | V bar ---> [1, 2, 3] If you modify the list, both foo and bar see the same change, because they refer to the same list. But if you *assign* to either foo or bar, let's say foo: foo ---> 42 bar ---> [1, 2, 3] bar continues to refer to the list, while foo has been rebound to a new value. That's how Python works. Now, instead, let's suppose bar pointed to foo: bar ---> foo ---> [1, 2, 3] Both bar's and foo's value is the list, like before. (We suppose that, when looking up a name, Python follows the chain of pointers as far as needed until it reaches a value.) And now we reassign foo: bar ---> foo ---> [4, 5, 6, 7] But since bar still points to foo, bar's value *follows* foo even after rebinding foo. bar is an alias for foo. And that is *not* how Python works: using the word "alias" to describe foo = bar = [1, 2, 3] is misleading. > consider the following: > >>> def f(l): > ... l[1] = 'foo' > ... > >>> l1 = [1,2,3] > >>> f(l1) > >>> l1 > [1, 'foo', 3] > > this means, l1 consists of "pointers" to its values. That does not follow. It happens to be that CPython does implement lists as an array of pointers, but that is a coincidence and is not a consequence of what you see. For example, ll might have been a linked list of chained tuples (value, next) rather than a built-in list, and you would still see the same result. What you are seeing is that setting an item causes an in-place modification, not a rebinding of the name ll. l[1] = 'foo' calls l.__setitem__ which mutates the list, it doesn't rebind l. This confusion is a good demonstration of why the meme that Python variables is "just like C pointers" is harmful. > Otherwise, it's not calling by reference, But it isn't call by reference. If it were call by reference, you could write a swap procedure that swaps the contents of two variables: a = 1 b = 2 swap(a, b) print a, b => prints 2, 1 You cannot do this in Python! Python has no call by reference. Please read this for more information: http://import-that.dreamwidth.org/1130.html [...snip example...] > does not change l1. Once again, if I pass an object But lists ARE objects. All values in Python are objects. > it behaves like calling by reference: It certainly does not. The best you can say is that mutation operations can, under some circumstances, mimic some of the effects of call by reference. For example, instead of using call by reference to get an output parameter, like Pascal uses, you can pass an object and mutate the object in place so that the caller sees the mutation. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Thu May 8 21:12:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 May 2014 11:12:57 +1000 Subject: Real-world use of concurrent.futures In-Reply-To: <87tx90t5q8.fsf@elektro.pacujo.net> References: <536BD338.4070004@andros.org.uk> <87tx90t5q8.fsf@elektro.pacujo.net> Message-ID: On Fri, May 9, 2014 at 5:45 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> Before you go too far down roads that are starting to look >> problematic: A DNS lookup is a UDP packet out and a UDP packet in >> (ignoring the possibility of TCP queries, which you probably won't be >> doing here). Maybe it would be easier to implement it as asynchronous >> networking? I don't know that Python makes it easy for you to >> construct DNS requests and parse DNS responses; > > That's what I ended up doing when I wrote my home SMTP server. > > It's more tedious than difficult. You don't need to have a ready-made > module for everything. An RFC and two hands take you far. Be careful. A naive implementation can open you up to various security issues. In the case of DNS, source port randomization is important to the prevention of cache poisoning; if you don't know what I'm talking about, pick a language/library that does the work for you, rather than doing everything yourself :) ChrisA From greg.ewing at canterbury.ac.nz Thu May 8 21:10:41 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 09 May 2014 13:10:41 +1200 Subject: The =?UTF-8?B?77+9ICBkZWJhdGU=?= In-Reply-To: <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Today we routinely call horseless carriages > "cars", and nobody would blink if I pointed at a Prius or a Ford Explorer > and said "that's not a carriage, it's a car" except to wonder why on > earth I thought something so obvious needed to be said. That's only because the term "car" *is* well established. The situation with the word "variable" is more like if you pointed at a Prius and said "That's not a car, it's an electric vehicle". Most people would wonder why you refused to categorise it as a type of car. If you look at the way the word "variable" is used across a variety of language communities, the common meaning is more or less "something that can appear on the left hand side of an assignment statement". Nobody seems to complain about using the term "assigment" in relation to Python, despite it meaning something a bit different from what it means in some other languages, so I don't see anything wrong with using the term "variable" with the above definition. -- Greg From ian.g.kelly at gmail.com Thu May 8 21:25:35 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 8 May 2014 19:25:35 -0600 Subject: how to create an external string when binding C to Python? In-Reply-To: <3afe7539-e3e9-43d6-ab58-1f4aa7895b46@googlegroups.com> References: <3afe7539-e3e9-43d6-ab58-1f4aa7895b46@googlegroups.com> Message-ID: On Thu, May 8, 2014 at 5:10 PM, Simon wrote: > I'd like to make a C memory buffer available inside Python via the Python C/API without copying that memory into Python. How to do this? I've read [1] but it's not clear that this functionality exists. In javascript it's possible using String::NewExternal() [2]. > > "Creates a new external string using the ASCII data defined in the given resource. > > When the external string is no longer live on V8's heap the resource will be disposed by calling its Dispose method. The caller of this function should not otherwise delete or modify the resource. Neither should the underlying buffer be deallocated or modified except through the destructor of the external string resource." > > [1] https://docs.python.org/2/c-api/buffer.html > [2] http://izs.me/v8-docs/classv8_1_1String.html#a07c47bf675b802c550984fa24511a589 In 3.3 or greater you can create a memoryview directly from a char* using this this call: https://docs.python.org/3/c-api/memoryview.html#c.PyMemoryView_FromMemory Otherwise, you can do it using the buffer protocol but it takes a little more work than just a function call. You'll need to define in C an extension type that will wrap your C buffer and that implements the buffer protocol, and then objects of that type can be used as the basis for memoryviews (or other buffer consumers). From steve+comp.lang.python at pearwood.info Thu May 8 21:32:57 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 May 2014 01:32:57 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536c3049$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 08 May 2014 21:02:36 -0400, Dennis Lee Bieber wrote: > On 08 May 2014 16:04:51 GMT, Steven D'Aprano > declaimed the following: > >>Personally, I think that trying to be general and talk about "many other >>languages" is a failing strategy. Better to be concrete: C, Pascal, >>Algol, Fortran, VB (I think) are good examples of the "value in a box at >>a fixed location" model. Of those, Algol, Pascal and Fortran are either >>obsolete or legacy, and C is by far the most well-known by people here. >>(For some reason, few people seem to migrate from VB to Python.) Hence, >>"C-like". >> >> > Obsolete and Legacy? Fortran still receives regular standards updates > (currently 2008, with the next revision due in 2015). Although Fortran is still in use, and widely so, it is mostly used for accessing existing Fortran libraries rather than writing new applications. There may be niches where that does not hold, where people are actively writing new applications in Fortran, but they are niches. Today, Fortran is rarely used for general purpose computing, updated standards or no updated standards. Fortran appears at number 32 in the TIOBE index, with a rating of 0.419%: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html which puts it below ML, Logo, D and Ada, at least according to whatever measure of popularity TIOBE uses. One might reasonably argue about precisely how often Fortran is used today, but I don't think one could argue that it is used more than (say) Java or PHP or even Perl. There are common, mainstream languages in frequent use, like C, Javascript and Python; up-and-coming languages like Go and D which may or may not someday become mainstream; and long established (i.e. legacy) languages that once were in common use but today not so much, like COBOL, PL/I and, yes, Fortran. I don't think this should be controversial. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ethan at stoneleaf.us Thu May 8 20:00:43 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 May 2014 17:00:43 -0700 Subject: Add "Received:" header to email msg in correct position? In-Reply-To: References: <536A4BF7.6040000@arskom.com.tr> <536B8AC7.3060103@stoneleaf.us> Message-ID: <536C1AAB.2020702@stoneleaf.us> On 05/08/2014 11:39 AM, Grant Edwards wrote: > > Yep. I've removed a few of them from the file over the years because > some people were offended by them. And I'll continue to do so... Thanks, much appreciated. -- ~Ethan~ From roy at panix.com Thu May 8 22:21:25 2014 From: roy at panix.com (Roy Smith) Date: Thu, 08 May 2014 22:21:25 -0400 Subject: The “does Python have variables?” debate References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536c3049$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <536c3049$0$29965$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Although Fortran is still in use, and widely so, it is mostly used for > accessing existing Fortran libraries rather than writing new > applications. There may be niches where that does not hold, where people > are actively writing new applications in Fortran, but they are niches. > Today, Fortran is rarely used for general purpose computing, updated > standards or no updated standards. Oddly enough, my current use of Fortran is via Python. The scipy and statsmodels libraries use Fortran routines under the covers. From rosuav at gmail.com Thu May 8 22:31:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 May 2014 12:31:56 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDigJxkb2VzIFB5dGhvbiBoYXZlIHZhcmlhYmxlcz/igJ0gZGViYXRl?= In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536c3049$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 9, 2014 at 12:21 PM, Roy Smith wrote: > In article <536c3049$0$29965$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> Although Fortran is still in use, and widely so, it is mostly used for >> accessing existing Fortran libraries rather than writing new >> applications. There may be niches where that does not hold, where people >> are actively writing new applications in Fortran, but they are niches. >> Today, Fortran is rarely used for general purpose computing, updated >> standards or no updated standards. > > Oddly enough, my current use of Fortran is via Python. The scipy and > statsmodels libraries use Fortran routines under the covers. I'd like to argue that you're not using Fortran, then. You're making use of it in the same way that I might make use of Ruby, PHP, and Perl when I browse the web - the other end is running those languages, ergo I am depending on them for my information, but I'm not actually seeing, much less writing, any code in those languages. ChrisA From ben at benfinney.id.au Thu May 8 23:13:01 2014 From: ben at benfinney.id.au (Ben Finney) Date: Fri, 09 May 2014 13:13:01 +1000 Subject: The =?utf-8?Q?=EF=BF=BD?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85tx8zablu.fsf@benfinney.id.au> Gregory Ewing writes: > If you look at the way the word "variable" is used across a variety of > language communities, the common meaning is more or less "something > that can appear on the left hand side of an assignment statement". The clear experience from years in this and other Python forums is that newcomers frequently draw from the term ?variable? additional, specific, inferences that are *false* for Python. My position is that the responsibility for avoiding terms that are likely to encourage newcomers to draw false inferences falls to us, as existing knowledgeable community members teaching newcomers. > Nobody seems to complain about using the term "assigment" in relation > to Python, despite it meaning something a bit different from what it > means in some other languages, so I don't see anything wrong with > using the term "variable" with the above definition. To the extent that the term encourages or enables a mental model that is significantly likely to lead to false inferences, the term is harmful for a newcomer's learning. That extent varies with each newcomer, of course; I'm pointing out that the proportion of newcomers arriving here with a mental model of ?variable? which will produce false inferences is high enough that the term is best replaced by terms that imply more-accurate mental models. -- \ ?A computer once beat me at chess, but it was no match for me | `\ at kick boxing.? ?Emo Philips | _o__) | Ben Finney From metaliobovinus at gmail.com Thu May 8 23:28:07 2014 From: metaliobovinus at gmail.com (Metallicow) Date: Thu, 8 May 2014 20:28:07 -0700 (PDT) Subject: trailing underscores naming convention_ Message-ID: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> I seem to be comfortable with all the information out around the net dealing with python naming conventions. Occasionally I have to remind myself on some of this stuff. The PEP8 does a good job for most of it, but I am having a bit of trouble finding some more detailed information on the trailing half of the underscores convention. The PEP8 says that one_ underscore is basically for helping fix python keyword names. OK. fair enough on that point. But what is the standards for everything else... purely coders choice?... ...or other... It would be nice if fellow pythoneers chimed in on the one or two trailing underscores convention and how the use it in their code. Ok so the situation is I have made myself a subclass of AuiManager. In AuiManager there is a method named OnLeftDClick. In my subclass I am not wanting to override(or hence copy the code into mine) to get my same named method to work as normally with event.Skip(). What I am wanting to do is just add extra functionality to the event(it doesn't matter if the event comes before or after) without stomping on(overriding) the AuiManager method. ...so what would be proper here for my method name...? one trailing underscore or two? OnLeftDClick_(self, event): or OnLeftDClick__(self, event): What is the norm for trailing underscores naming convention overall? Mostly with func/meth/class naming, but attribute explanation would be nice also. From ian.g.kelly at gmail.com Fri May 9 00:24:00 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 8 May 2014 22:24:00 -0600 Subject: trailing underscores naming convention_ In-Reply-To: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> References: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> Message-ID: On Thu, May 8, 2014 at 9:28 PM, Metallicow wrote: > I seem to be comfortable with all the information out around the net dealing > with python naming conventions. Occasionally I have to remind myself on some > of this stuff. The PEP8 does a good job for most of it, but I am having a bit > of trouble finding some more detailed information on the trailing half of > the underscores convention. > > The PEP8 says that one_ underscore is basically for helping fix > python keyword names. > OK. fair enough on that point. > > But what is the standards for everything else... purely coders choice?... > ...or other... > It would be nice if fellow pythoneers chimed in on the one or two trailing > underscores convention and how the use it in their code. I'm not aware of any convention for trailing underscores other than the one described in PEP8. > > Ok so the situation is I have made myself a subclass of AuiManager. > In AuiManager there is a method named OnLeftDClick. > In my subclass I am not wanting to override(or hence copy the code into mine) > to get my same named method to work as normally with event.Skip(). > > What I am wanting to do is just add extra functionality to the > event(it doesn't matter if the event comes before or after) without > stomping on(overriding) the AuiManager method. If you use a different name in the subclass then whatever code calls the method will continue to call the base class version instead of your subclassed version. Is there a reason you don't just use super() to chain the call to the base method? def OnLeftDClick(self, event): event.Skip() super(MyClassName, self).OnLeftDClick(event) From metaliobovinus at gmail.com Fri May 9 01:03:04 2014 From: metaliobovinus at gmail.com (Metallicow) Date: Thu, 8 May 2014 22:03:04 -0700 (PDT) Subject: trailing underscores naming convention_ In-Reply-To: References: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> Message-ID: On Thursday, May 8, 2014 10:24:00 PM UTC-6, Ian wrote: > On Thu, May 8, 2014 at 9:28 PM, Metallicow wrote: > > I seem to be comfortable with all the information out around the net dealing > > with python naming conventions. Occasionally I have to remind myself on some > > of this stuff. The PEP8 does a good job for most of it, but I am having a bit > > of trouble finding some more detailed information on the trailing half of > > the underscores convention. > > > > The PEP8 says that one_ underscore is basically for helping fix > > python keyword names. > > OK. fair enough on that point. > > > > But what is the standards for everything else... purely coders choice?... > > ...or other... > > It would be nice if fellow pythoneers chimed in on the one or two trailing > > underscores convention and how the use it in their code. > > I'm not aware of any convention for trailing underscores other than > the one described in PEP8. > > > > > Ok so the situation is I have made myself a subclass of AuiManager. > > In AuiManager there is a method named OnLeftDClick. > > In my subclass I am not wanting to override(or hence copy the code into mine) > > to get my same named method to work as normally with event.Skip(). > > > > What I am wanting to do is just add extra functionality to the > > event(it doesn't matter if the event comes before or after) without > > stomping on(overriding) the AuiManager method. > > If you use a different name in the subclass then whatever code calls > the method will continue to call the base class version instead of > your subclassed version. Is there a reason you don't just use super() > to chain the call to the base method? > > def OnLeftDClick(self, event): > event.Skip() > super(MyClassName, self).OnLeftDClick(event) I often see in other folks code methods/funcs/classes, etc with trailing underscores in them and and not sure if that was a convention thing or not. ...So basically you are telling me it is coders preference/naming style? I tried the super thing, but in this instance what you posted calls my method twice, which isn't desired. The renaming comes from the fact that I am only targeting this particular subclass for this event extension, otherwise I would have made a mixin out of it. But for something as simple as a standard event like this, unless the mixin could be used elsewhere, outside of this subclass, then making one is basically a waste of time overall. Anyway, my code works as expected with the _ appended on the method name. The class method is called, and event.Skip() allows my method to be called also without missing anything. I might look at toying with the super way more(it probably just needs tweaked a bit). I don't use super in the class __init__ anyway for readability and conciseness reasons BTW, just if that super coding style was an assumption. I just was not sure if there was common rules for that type of stuff. From rustompmody at gmail.com Fri May 9 01:40:05 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 8 May 2014 22:40:05 -0700 (PDT) Subject: The "does Python have variables?" debate In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536c3049$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, May 9, 2014 8:01:56 AM UTC+5:30, Chris Angelico wrote: > On Fri, May 9, 2014 at 12:21 PM, Roy Smith wrote: > > > > Steven D'Aprano wrote: > > > > > >> Although Fortran is still in use, and widely so, it is mostly used for > >> accessing existing Fortran libraries rather than writing new > >> applications. There may be niches where that does not hold, where people > >> are actively writing new applications in Fortran, but they are niches. > >> Today, Fortran is rarely used for general purpose computing, updated > >> standards or no updated standards. > > > > > Oddly enough, my current use of Fortran is via Python. The scipy and > > statsmodels libraries use Fortran routines under the covers. > > > I'd like to argue that you're not using Fortran, then. You're making > use of it in the same way that I might make use of Ruby, PHP, and Perl > when I browse the web Yes one can argue so But one can also argue that this is a 1990s viewpoint http://oreillynet.com/pub/a/oreilly/tim/articles/paradigmshift_0504.html From metaliobovinus at gmail.com Fri May 9 01:49:53 2014 From: metaliobovinus at gmail.com (Metallicow) Date: Thu, 8 May 2014 22:49:53 -0700 (PDT) Subject: trailing underscores naming convention_ In-Reply-To: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> References: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> Message-ID: <57b0d9ec-b8a4-4021-b25f-422a9fe11529@googlegroups.com> I guess to be more clear here is a small code snippet that shows what is happening more readably. Hence the underscores question. class MainAuiManager(aui.AuiManager): def __init__(self, managed_window=None, agwFlags=0) aui.AuiManager.__init__(self, managed_window, agwFlags) ## self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick) self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick_) self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick__) self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick___) # etc... ## def OnLeftDClick(self, event): ## """This will override the aui.AuiManager.OnLeftDClick event method.""" ## event.Skip() ## print('OnLeftDClick') def OnLeftDClick_(self, event): """This will extend the aui.AuiManager.OnLeftDClick event method.""" event.Skip() print('OnLeftDClick_') def OnLeftDClick__(self, event): """This will extend the aui.AuiManager.OnLeftDClick event method.""" event.Skip() print('OnLeftDClick__') def OnLeftDClick___(self, event): """This will extend the aui.AuiManager.OnLeftDClick event method.""" event.Skip() print('OnLeftDClick___') From rosuav at gmail.com Fri May 9 01:51:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 May 2014 15:51:37 +1000 Subject: The "does Python have variables?" debate In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536c3049$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 9, 2014 at 3:40 PM, Rustom Mody wrote: >> I'd like to argue that you're not using Fortran, then. You're making >> use of it in the same way that I might make use of Ruby, PHP, and Perl >> when I browse the web > > Yes one can argue so > But one can also argue that this is a 1990s viewpoint > http://oreillynet.com/pub/a/oreilly/tim/articles/paradigmshift_0504.html Okay, so at what point do you stop using Fortran? Suppose the original Fortran code was all compiled to binary years and years ago, and nobody touches it. Nobody even knows that it was ever written in Fortran; the existing binaries need no changes, or if they do, they get edited directly in the binary. You're writing a Python program that interacts with this. Sure, your success depends on someone, some time in the past, having written Fortran (or FORTRAN) code, but you're not yourself using that language at all. Or can I put on my resume that I use, on a regular basis, FreeBSD, OpenBSD, Mac OS, and Solaris, and I make extensive use of Hadoop, map/reduce across petabytes of data, massively parallel processing, and special relativity? I'm sure an employer would *love* to hear from someone with all of that experience! ChrisA From breamoreboy at yahoo.co.uk Fri May 9 04:13:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 09 May 2014 09:13:17 +0100 Subject: The =?windows-1252?Q?=93does_Python_have_variables=3F=94?= =?windows-1252?Q?_debate?= In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/05/2014 02:02, Dennis Lee Bieber wrote: > On 08 May 2014 16:04:51 GMT, Steven D'Aprano > declaimed the following: > >> Personally, I think that trying to be general and talk about "many other >> languages" is a failing strategy. Better to be concrete: C, Pascal, >> Algol, Fortran, VB (I think) are good examples of the "value in a box at >> a fixed location" model. Of those, Algol, Pascal and Fortran are either >> obsolete or legacy, and C is by far the most well-known by people here. >> (For some reason, few people seem to migrate from VB to Python.) Hence, >> "C-like". >> > > Obsolete and Legacy? Fortran still receives regular standards updates > (currently 2008, with the next revision due in 2015). > http://arstechnica.com/science/2014/05/scientific-computings-future-can-any-coding-language-top-a-1950s-behemoth/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From percy.tambunan at gmail.com Fri May 9 04:59:45 2014 From: percy.tambunan at gmail.com (Percy Tambunan) Date: Fri, 9 May 2014 01:59:45 -0700 (PDT) Subject: parsing multiple root element XML into text Message-ID: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> Hai, I would like to parse this multiple root element XML 343741014 nu 343741015 nu into this create enumdnsched 4.1.0.1.4.7.3.4.3.2.6.e164.arpa -set naptrFlags=nu create enumdnsched 5.1.0.1.4.7.3.4.3.2.6.e164.arpa -set naptrFlags=nu Anyone can great example how to do that, I would really appreciate it. Thanks, Percy From rosuav at gmail.com Fri May 9 05:02:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 May 2014 19:02:42 +1000 Subject: parsing multiple root element XML into text In-Reply-To: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> Message-ID: On Fri, May 9, 2014 at 6:59 PM, Percy Tambunan wrote: > Hai, I would like to parse this multiple root element XML Easy fix might be to wrap it in and , which will give you a new root. Would that help? ChrisA From marko at pacujo.net Fri May 9 05:01:39 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 09 May 2014 12:01:39 +0300 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> Message-ID: <87fvkjfhqk.fsf@elektro.pacujo.net> Percy Tambunan : > Hai, I would like to parse this multiple root element XML How about creating a file-like object that wraps the multi-root file into a single-root document? Marko From stefan_ml at behnel.de Fri May 9 05:13:51 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 09 May 2014 11:13:51 +0200 Subject: parsing multiple root element XML into text In-Reply-To: References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> Message-ID: Chris Angelico, 09.05.2014 11:02: > On Fri, May 9, 2014 at 6:59 PM, Percy Tambunan wrote: >> Hai, I would like to parse this multiple root element XML > > Easy fix might be to wrap it in and , which will give > you a new root. ElementTree's XMLParser() can be use efficiently for this. Something like this should work: from xml.etree.ElementTree import XMLParser parser = XMLParser() parser.feed(b'') parser.feed(real_input_data) parser.feed(b'') root = parser.close() for subtree in root: ... Stefan From rosuav at gmail.com Fri May 9 05:15:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 May 2014 19:15:49 +1000 Subject: parsing multiple root element XML into text In-Reply-To: References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> Message-ID: On Fri, May 9, 2014 at 7:13 PM, Stefan Behnel wrote: > Chris Angelico, 09.05.2014 11:02: >> On Fri, May 9, 2014 at 6:59 PM, Percy Tambunan wrote: >>> Hai, I would like to parse this multiple root element XML >> >> Easy fix might be to wrap it in and , which will give >> you a new root. > > ElementTree's XMLParser() can be use efficiently for this. Something like > this should work: > > from xml.etree.ElementTree import XMLParser > > parser = XMLParser() > parser.feed(b'') > parser.feed(real_input_data) > parser.feed(b'') > root = parser.close() > > for subtree in root: > ... That looks good to me :) ChrisA From __peter__ at web.de Fri May 9 05:10:26 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 09 May 2014 11:10:26 +0200 Subject: trailing underscores naming convention_ References: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> <57b0d9ec-b8a4-4021-b25f-422a9fe11529@googlegroups.com> Message-ID: Metallicow wrote: > I guess to be more clear here is a small code snippet that shows what is > happening more readably. Hence the underscores question. Working with multiple names with small differences is error-prone. You should give a method a name that describes what it does rather than when it's invoked: > class MainAuiManager(aui.AuiManager): > def __init__(self, managed_window=None, agwFlags=0) > aui.AuiManager.__init__(self, managed_window, agwFlags) self.Bind(wx.EVT_LEFT_DCLICK, self.EatMagicMushroom) self.Bind(wx.EVT_LEFT_DCLICK, self.KillBlueMonster) self.Bind(wx.EVT_LEFT_DCLICK, self.SingDitty) From alain at dpt-info.u-strasbg.fr Fri May 9 05:51:39 2014 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 09 May 2014 11:51:39 +0200 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> Message-ID: <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> Percy Tambunan writes: > Hai, I would like to parse this multiple root element XML > > [...] > > [...] > Technically speaking, this is not a well-formed XML document (it is a well-formed external general parsed entity, though). If you have other XML processors in your workflow, they will/should reject it. The easiest fix is to wrap this inside a root element (see other messages in this thread), or use a DTD-declared entity to include this fragment in a document. -- Alain. From metaliobovinus at gmail.com Fri May 9 06:22:56 2014 From: metaliobovinus at gmail.com (Metallicow) Date: Fri, 9 May 2014 03:22:56 -0700 (PDT) Subject: trailing underscores naming convention_ In-Reply-To: References: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> <57b0d9ec-b8a4-4021-b25f-422a9fe11529@googlegroups.com> Message-ID: <8b8daad1-0e84-4c2f-a91c-696487df2819@googlegroups.com> On Friday, May 9, 2014 3:10:26 AM UTC-6, Peter Otten wrote: > Metallicow wrote: > > > I guess to be more clear here is a small code snippet that shows what is > > happening more readably. Hence the underscores question. > > Working with multiple names with small differences is error-prone. > You should give a method a name that describes what it does rather than when > it's invoked: > > > class MainAuiManager(aui.AuiManager): > > def __init__(self, managed_window=None, agwFlags=0) > > aui.AuiManager.__init__(self, managed_window, agwFlags) > > self.Bind(wx.EVT_LEFT_DCLICK, self.EatMagicMushroom) > self.Bind(wx.EVT_LEFT_DCLICK, self.KillBlueMonster) > self.Bind(wx.EVT_LEFT_DCLICK, self.SingDitty) While readabily counts, in this case it is pretty readable already. Actions speak loader than words. In this case action(as with QT) is an event(in wxPython). My actual code would only(realisticly or sanely) extend this event once per subclass if at all... ...Unless there happens to be some crazy need for more(multiple) event methods to fire off when 1 event happens. Especially for a class bound intended for a top level window such as a frame or dialog. Anyway, the small snippet just shows that this can be done, but the actual question you replied to you left unanswered. It is about the trailing underscores. Now would KillBlueMonsterA vs KillBlueMonsterB vs KillBlueMonster_ be any more descriptive than OnLeftDClick_ which describes the event happening itself and the code that extends it by 1, in this case the call order. I could see the underscore as an extension thereof. ...so maybe OnLeftDClick_Extension_Description_ might be better... but why the trailing underscores? Maybe others that do this normally can chime in as to why they for example would put the underscores on the end, if it isn't a common convention. Maybe it is like I see it, as an extextion of some special meaning or reason therof, but isn't always obvious as most like the name not only desciptive, but short also. From marko at pacujo.net Fri May 9 06:33:37 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 09 May 2014 13:33:37 +0300 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> Message-ID: <87a9arfdha.fsf@elektro.pacujo.net> Alain Ketterlin : > Technically speaking, this is not a well-formed XML document (it is a > well-formed external general parsed entity, though). If you have other > XML processors in your workflow, they will/should reject it. Sometimes the XML elements come through a pipe as an endless sequence. You can still use the wrapping technique and a SAX parser. However, the other option is to write a tiny XML scanner that identifies the end of each element. Then, you can cut out the complete XML element and hand it over to a DOM parser. Such a scanner can be really small and nonrecursive because of the welformedness rules of XML. Marko From __peter__ at web.de Fri May 9 07:49:11 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 09 May 2014 13:49:11 +0200 Subject: trailing underscores naming convention_ References: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> <57b0d9ec-b8a4-4021-b25f-422a9fe11529@googlegroups.com> <8b8daad1-0e84-4c2f-a91c-696487df2819@googlegroups.com> Message-ID: Metallicow wrote: > On Friday, May 9, 2014 3:10:26 AM UTC-6, Peter Otten wrote: >> Metallicow wrote: >> >> > I guess to be more clear here is a small code snippet that shows what >> > is happening more readably. Hence the underscores question. >> >> Working with multiple names with small differences is error-prone. >> You should give a method a name that describes what it does rather than >> when it's invoked: >> >> > class MainAuiManager(aui.AuiManager): >> > def __init__(self, managed_window=None, agwFlags=0) >> > aui.AuiManager.__init__(self, managed_window, agwFlags) >> >> self.Bind(wx.EVT_LEFT_DCLICK, self.EatMagicMushroom) >> self.Bind(wx.EVT_LEFT_DCLICK, self.KillBlueMonster) >> self.Bind(wx.EVT_LEFT_DCLICK, self.SingDitty) > > While readabily counts, in this case it is pretty readable already. > Actions speak loader than words. In this case action(as with QT) is an > event(in wxPython). My actual code would only(realisticly or sanely) > extend this event once per subclass if at all... You should reconsider Ian's advice to override the method then. [in another post] > I tried the super thing, but in this instance what you posted calls my method twice, which isn't desired. Note that if you have self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick) in the base class initialiser you must not repeat it in the subclass -- perhaps that is what caused OnLeftDClick() to be invoked twice. > ...Unless there happens > to be some crazy need for more(multiple) event methods to fire off when 1 > event happens. Especially for a class bound intended for a top level > window such as a frame or dialog. > > Anyway, the small snippet just shows that this can be done, but the actual > question you replied to you left unanswered. It is about the trailing > underscores. My implicit answer was that you are asking for the best hammer to drive a screw... > Now would KillBlueMonsterA vs KillBlueMonsterB vs KillBlueMonster_ be any > more descriptive than OnLeftDClick_ which describes the event happening > itself and the code that extends it by 1, in this case the call order. > I could see the underscore as an extension thereof. > ...so maybe OnLeftDClick_Extension_Description_ might be better... > but why the trailing underscores? I do not remember having seen these trailing underscores. Who is using them where? Someone misapplying the (questionable) C++ convention to mark members? > Maybe others that do this normally can chime in as to > why they for example would put the underscores on the end, > if it isn't a common convention. Maybe it is like I see it, as an > extextion of some special meaning or reason therof, but isn't always > obvious as most like the name not only desciptive, but short also. From alain at dpt-info.u-strasbg.fr Fri May 9 08:01:43 2014 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 09 May 2014 14:01:43 +0200 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> Message-ID: <87k39vupnc.fsf@dpt-info.u-strasbg.fr> Marko Rauhamaa writes: > Alain Ketterlin : > >> Technically speaking, this is not a well-formed XML document (it is a >> well-formed external general parsed entity, though). If you have other >> XML processors in your workflow, they will/should reject it. > > Sometimes the XML elements come through a pipe as an endless sequence. > You can still use the wrapping technique and a SAX parser. However, the > other option is to write a tiny XML scanner that identifies the end of > each element. Then, you can cut out the complete XML element and hand it > over to a DOM parser. Well maybe, even though I see no point in doing so. If the whole transaction is a single document and you need to get sub-elements on the fly, just use the SAX parser: there is no need to use a "tiny XML scanner" (whatever that is), and building a DOM for a part of the document in your SAX handler is easy if needed (for the OP's case a simple state machine would be enough, probably). -- Alain. From marko at pacujo.net Fri May 9 08:31:20 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 09 May 2014 15:31:20 +0300 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> <87k39vupnc.fsf@dpt-info.u-strasbg.fr> Message-ID: <8738gjf813.fsf@elektro.pacujo.net> Alain Ketterlin : > Marko Rauhamaa writes: >> Sometimes the XML elements come through a pipe as an endless >> sequence. You can still use the wrapping technique and a SAX parser. >> However, the other option is to write a tiny XML scanner that >> identifies the end of each element. Then, you can cut out the >> complete XML element and hand it over to a DOM parser. > > Well maybe, even though I see no point in doing so. If the whole > transaction is a single document and you need to get sub-elements on > the fly, just use the SAX parser: there is no need to use a "tiny XML > scanner" (whatever that is), and building a DOM for a part of the > document in your SAX handler is easy if needed (for the OP's case a > simple state machine would be enough, probably). An example is . The "document" is potentially infinitely long. The elements are messages. The programmer would rather process the elements as DOM trees than follow the meandering SAX parser. Marko From marko at pacujo.net Fri May 9 08:38:49 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 09 May 2014 15:38:49 +0300 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> <87k39vupnc.fsf@dpt-info.u-strasbg.fr> <8738gjf813.fsf@elektro.pacujo.net> Message-ID: <87y4ybdt46.fsf@elektro.pacujo.net> Marko Rauhamaa : > Alain Ketterlin : > >> Marko Rauhamaa writes: >>> Sometimes the XML elements come through a pipe as an endless >>> sequence. You can still use the wrapping technique and a SAX parser. >>> However, the other option is to write a tiny XML scanner that >>> identifies the end of each element. Then, you can cut out the >>> complete XML element and hand it over to a DOM parser. >> >> Well maybe, even though I see no point in doing so. If the whole >> transaction is a single document and you need to get sub-elements on >> the fly, just use the SAX parser: there is no need to use a "tiny XML >> scanner" (whatever that is), and building a DOM for a part of the >> document in your SAX handler is easy if needed (for the OP's case a >> simple state machine would be enough, probably). > > An example is http://en.wikipedia.org/wiki/XMPP#XMPP_via_HTTP_and_WebSocket_transports>. > > The "document" is potentially infinitely long. The elements are > messages. > > The programmer would rather process the elements as DOM trees than > follow the meandering SAX parser. In fact, the best thing would be if the DOM parser supported the use case out of the box: give the partial, whole or oversize document to the parser. If the document isn't complete, the parser should indicate the need for more input. If there are bytes after the document is successfully finished, the parser should leave the excess bytes in the pipeline. IOW, if the DOM parser knows full well where the document ends, why must the application tell it to it? Marko From breamoreboy at yahoo.co.uk Fri May 9 09:48:11 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 09 May 2014 14:48:11 +0100 Subject: PyPy updated Message-ID: Might interest some of you fine folk out there :- http://morepypy.blogspot.co.uk/2014/05/pypy-23-terrestrial-arthropod-trap.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From stefan_ml at behnel.de Fri May 9 09:55:41 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 09 May 2014 15:55:41 +0200 Subject: parsing multiple root element XML into text In-Reply-To: <87y4ybdt46.fsf@elektro.pacujo.net> References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> <87k39vupnc.fsf@dpt-info.u-strasbg.fr> <8738gjf813.fsf@elektro.pacujo.net> <87y4ybdt46.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa, 09.05.2014 14:38: > Marko Rauhamaa: >> Alain Ketterlin: >>> Marko Rauhamaa writes: >>>> Sometimes the XML elements come through a pipe as an endless >>>> sequence. You can still use the wrapping technique and a SAX parser. >>>> However, the other option is to write a tiny XML scanner that >>>> identifies the end of each element. Then, you can cut out the >>>> complete XML element and hand it over to a DOM parser. >>> >>> Well maybe, even though I see no point in doing so. If the whole >>> transaction is a single document and you need to get sub-elements on >>> the fly, just use the SAX parser: there is no need to use a "tiny XML >>> scanner" (whatever that is), and building a DOM for a part of the >>> document in your SAX handler is easy if needed (for the OP's case a >>> simple state machine would be enough, probably). >> >> An example is > http://en.wikipedia.org/wiki/XMPP#XMPP_via_HTTP_and_WebSocket_transports>. >> >> The "document" is potentially infinitely long. The elements are >> messages. >> >> The programmer would rather process the elements as DOM trees than >> follow the meandering SAX parser. > > In fact, the best thing would be if the DOM parser supported the use > case out of the box: give the partial, whole or oversize document to the > parser. If the document isn't complete, the parser should indicate the > need for more input. If there are bytes after the document is > successfully finished, the parser should leave the excess bytes in the > pipeline. > > IOW, if the DOM parser knows full well where the document ends, why > must the application tell it to it? In fact, XMPP traffic has a root element. And I agree that a tree is much easier to handle than SAX events. ElementTree has gained a nice API in Py3.4 that supports this in a much saner way than SAX, using iterators. Basically, you just dump in some data that you received and get back an iterator over the elements (and their subtrees) that it generated from it. Intercept on the right top elements and you get your next subtree as soon as it's ready. https://docs.python.org/3.4/library/xml.etree.elementtree.html#pull-api-for-non-blocking-parsing It's also supported by recent versions of lxml, which additionally has easy to use support for the sending side with its xmlfile() tool. http://lxml.de/parsing.html#incremental-event-parsing http://lxml.de/api.html#incremental-xml-generation Stefan From rustompmody at gmail.com Fri May 9 10:09:07 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 9 May 2014 07:09:07 -0700 (PDT) Subject: The "does Python have variables?" debate In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536c3049$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0de35224-9fbd-4e43-b62e-f247d0812a94@googlegroups.com> On Friday, May 9, 2014 11:21:37 AM UTC+5:30, Chris Angelico wrote: > On Fri, May 9, 2014 at 3:40 PM, Rustom Mody wrote: > > >> I'd like to argue that you're not using Fortran, then. You're making > >> use of it in the same way that I might make use of Ruby, PHP, and Perl > >> when I browse the web > > > > Yes one can argue so > > But one can also argue that this is a 1990s viewpoint > > http://oreillynet.com/pub/a/oreilly/tim/articles/paradigmshift_0504.html > > > Okay, so at what point do you stop using Fortran? Yes thats the point -- its a real valued spectrum, not a yes/no. eg. You write an app with Tkinter. Are you not using Tcl/Tk? You said earlier to Mark that the relation between python and C variables is irrelevant. Lets take that as true. Will it continue to be irrelevant when you need to write an extension in C? From albert.visser at gmail.com Fri May 9 10:24:17 2014 From: albert.visser at gmail.com (Albert Visser) Date: Fri, 09 May 2014 16:24:17 +0200 Subject: trailing underscores naming convention_ In-Reply-To: <8b8daad1-0e84-4c2f-a91c-696487df2819@googlegroups.com> References: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> <57b0d9ec-b8a4-4021-b25f-422a9fe11529@googlegroups.com> <8b8daad1-0e84-4c2f-a91c-696487df2819@googlegroups.com> Message-ID: On Fri, 09 May 2014 12:22:56 +0200, Metallicow wrote: > On Friday, May 9, 2014 3:10:26 AM UTC-6, Peter Otten wrote: >> Metallicow wrote: >> >> > I guess to be more clear here is a small code snippet that shows what >> is >> > happening more readably. Hence the underscores question. >> >> Working with multiple names with small differences is error-prone. Definitely. > > Anyway, the small snippet just shows that this can be done, but the > actual > question you replied to you left unanswered. It is about the trailing > underscores. > It's not an "official" convention I think, but a (single) trailing underscore is mainly meant to create something that is close to an original definition without shadowing it. If you subclass an object and bind a thusly underscored method to an event to which the original is already bound in the superclass's __init__ method, they are both getting called on the event unless you do not call the superclass's __init__() in your own __init__(). -- Vriendelijk groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ From rosuav at gmail.com Fri May 9 10:29:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 10 May 2014 00:29:14 +1000 Subject: The "does Python have variables?" debate In-Reply-To: <0de35224-9fbd-4e43-b62e-f247d0812a94@googlegroups.com> References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536c3049$0$29965$c3e8da3$5496439d@news.astraweb.com> <0de35224-9fbd-4e43-b62e-f247d0812a94@googlegroups.com> Message-ID: On Sat, May 10, 2014 at 12:09 AM, Rustom Mody wrote: > Yes thats the point -- its a real valued spectrum, not a yes/no. eg. > > You write an app with Tkinter. Are you not using Tcl/Tk? I'm not familiar enough with Tkinter to be sure, but I think you'd be using Tk but not Tcl. There are a few leaks, though, so it may be necessary to grok Tcl to use Tkinter (or at least, there may be times when grokking Tcl will make it easier to debug Tkinter issues). > You said earlier to Mark that the relation between python and C variables is irrelevant. Lets take that as true. Will it continue to be irrelevant when > you need to write an extension in C? The similarities and differences between the variable models are no more relevant. What becomes relevant are the PyObject* pointer (the C interface to a Python object (not variable)) and the various functions for manipulating namespaces, mainly dictionaries. If anything, you need to be more aware that Python and C variables are completely different beasts. CPython's C API [1] is fairly manual; you INCREF and DECREF objects, there's no concept of "automatic variables", etc etc etc. For comparison, the V8 JavaScript engine tries to make it easy to work with automatic variables - you create scope levels, and then a whole lot of magic happens and things are really easy. At least, they're easy so long as your code model perfectly follows what the designers had in mind; if your code works in any other way, it becomes a lot harder, as you end up either fighting against the scope system, or just declaring a global scope object and using that everywhere. In both cases, the relationship to C's variable model is coincidental at best. The fact that you can go "x = 1;" in all three languages and expect it to do the same thing is quite useless if you're trying to write C++ code [2] that does "x = 1;" in Python and JavaScript. ChrisA [1] I'm not sure whether this is CPython's API or if it's part of the Python language spec, as I've never written C extensions for any other Python. [2] The V8 API is actually a C++ API, not that the difference matters to this discussion From invalid at invalid.invalid Fri May 9 10:28:35 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 9 May 2014 14:28:35 +0000 (UTC) Subject: Add "Received:" header to email msg in correct position? References: <536A4BF7.6040000@arskom.com.tr> <536B8AC7.3060103@stoneleaf.us> Message-ID: On 2014-05-08, Tim Chase wrote: > On 2014-05-08 18:39, Grant Edwards wrote: >> > Looks like a Zippy the Pinhead quote to me... >> >> Yep. > > I'm kinda disappointed having the curtain pulled back like that. I'd > just assumed it was some nifty tool that turned a GPG/PGP signature > into MadLibs?-style fill-in-the-blank and then flowed into various > templates, allowing Grant to confirm/deny message authorship based on > the unspoofability of the signature with any other message-body. That would be cool... -- Grant Edwards grant.b.edwards Yow! Boy, am I glad it's at only 1971... gmail.com From marko at pacujo.net Fri May 9 11:29:41 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 09 May 2014 18:29:41 +0300 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> <87k39vupnc.fsf@dpt-info.u-strasbg.fr> <8738gjf813.fsf@elektro.pacujo.net> <87y4ybdt46.fsf@elektro.pacujo.net> Message-ID: <87tx8zdl7e.fsf@elektro.pacujo.net> Stefan Behnel : > ElementTree has gained a nice API in Py3.4 that supports this in a > much saner way than SAX, using iterators. Good to know. Marko From alain at dpt-info.u-strasbg.fr Fri May 9 11:50:19 2014 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 09 May 2014 17:50:19 +0200 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> <87k39vupnc.fsf@dpt-info.u-strasbg.fr> <8738gjf813.fsf@elektro.pacujo.net> Message-ID: <87fvkjuf2c.fsf@dpt-info.u-strasbg.fr> Marko Rauhamaa writes: > Alain Ketterlin : > >> Marko Rauhamaa writes: >>> Sometimes the XML elements come through a pipe as an endless >>> sequence. You can still use the wrapping technique and a SAX parser. >>> However, the other option is to write a tiny XML scanner that >>> identifies the end of each element. Then, you can cut out the >>> complete XML element and hand it over to a DOM parser. >> >> Well maybe, even though I see no point in doing so. If the whole >> transaction is a single document and you need to get sub-elements on >> the fly, just use the SAX parser: there is no need to use a "tiny XML >> scanner" (whatever that is), and building a DOM for a part of the >> document in your SAX handler is easy if needed (for the OP's case a >> simple state machine would be enough, probably). > > An example is http://en.wikipedia.org/wiki/XMPP#XMPP_via_HTTP_and_WebSocket_transports>. > > The "document" is potentially infinitely long. The elements are > messages. > > The programmer would rather process the elements as DOM trees than > follow the meandering SAX parser. which does an exact traversal of potential the DOM tree... (assuming a DOM is even defined on a non well-formed XML document). Anyway, my point was only to warn the OP that he is not doing XML. -- Alain. From rustompmody at gmail.com Fri May 9 12:07:46 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 9 May 2014 09:07:46 -0700 (PDT) Subject: The "does Python have variables?" debate In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536c3049$0$29965$c3e8da3$5496439d@news.astraweb.com> <0de35224-9fbd-4e43-b62e-f247d0812a94@googlegroups.com> Message-ID: <04105c09-fa4d-4d63-99be-88f3edbc8632@googlegroups.com> On Friday, May 9, 2014 7:59:14 PM UTC+5:30, Chris Angelico wrote: > The similarities and differences between the variable models are no > more relevant. What becomes relevant are the PyObject* pointer (the C > interface to a Python object (not variable)) and the various functions > for manipulating namespaces, mainly dictionaries. If anything, you > need to be more aware that Python and C variables are completely > different beasts. CPython's C API [1] is fairly manual; you INCREF and > DECREF objects, there's no concept of "automatic variables", etc etc > etc. On the contrary, you need to respect the C system to get past the C compiler. And you need to uphold the expected python invariants to get code that works. So the variables inside the C functions are (as always in C) automatic But they dont become easily and naturally such in python Hence all the INCREF/ownership etc headaches IOW one needs to have both worlds under one's belt Of course one can use swig or boost or ctype and replace one headache with other(s) From marko at pacujo.net Fri May 9 12:15:48 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 09 May 2014 19:15:48 +0300 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> <87k39vupnc.fsf@dpt-info.u-strasbg.fr> <8738gjf813.fsf@elektro.pacujo.net> <87fvkjuf2c.fsf@dpt-info.u-strasbg.fr> Message-ID: <87lhubdj2j.fsf@elektro.pacujo.net> Alain Ketterlin : > which does an exact traversal of potential the DOM tree... (assuming a > DOM is even defined on a non well-formed XML document). > > Anyway, my point was only to warn the OP that he is not doing XML. I consider that one of the multitude of flaws in XML. Compare that with the close analogue: S expressions. Every lisp/scheme command interface takes in a sequence of unframed S expressions and interprets them in sequence. I have built similar interfaces using XML: the command interface accepts a sequence of XML elements and acts on them upon reaching the end of a complete element. Marko From torriem at gmail.com Fri May 9 12:35:09 2014 From: torriem at gmail.com (Michael Torrie) Date: Fri, 09 May 2014 10:35:09 -0600 Subject: trailing underscores naming convention_ In-Reply-To: <57b0d9ec-b8a4-4021-b25f-422a9fe11529@googlegroups.com> References: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> <57b0d9ec-b8a4-4021-b25f-422a9fe11529@googlegroups.com> Message-ID: <536D03BD.6020501@gmail.com> On 05/08/2014 11:49 PM, Metallicow wrote: > I guess to be more clear here is a small code snippet that shows what > is happening more readably. Hence the underscores question. In a case like this I'd probably prefer to number the methods rather than add underscores to the end of the names. My current font, for example, connects the underscores together, so it's a bit hard from a glance to tell if it's just two underscores or three. I'd prefer OnLeftDClick1, OnLeftDClick2, OnLeftDClick3, for example. And I also prefer pep8 method names as well, on_left_dclick1, etc. But when the underlying library doesn't follow pep8, then I guess it does not matter (self.Bind is from the library I presume). > class MainAuiManager(aui.AuiManager): def __init__(self, > managed_window=None, agwFlags=0) aui.AuiManager.__init__(self, > managed_window, agwFlags) > > ## self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick) > self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick_) > self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick__) > self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick___) # etc... > > ## def OnLeftDClick(self, event): ## """This will override the > aui.AuiManager.OnLeftDClick event method.""" ## event.Skip() ## > print('OnLeftDClick') > > def OnLeftDClick_(self, event): """This will extend the > aui.AuiManager.OnLeftDClick event method.""" event.Skip() > print('OnLeftDClick_') > > def OnLeftDClick__(self, event): """This will extend the > aui.AuiManager.OnLeftDClick event method.""" event.Skip() > print('OnLeftDClick__') > > def OnLeftDClick___(self, event): """This will extend the > aui.AuiManager.OnLeftDClick event method.""" event.Skip() > print('OnLeftDClick___') > From burak.arslan at arskom.com.tr Fri May 9 12:52:47 2014 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Fri, 09 May 2014 19:52:47 +0300 Subject: parsing multiple root element XML into text In-Reply-To: References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> <87k39vupnc.fsf@dpt-info.u-strasbg.fr> <8738gjf813.fsf@elektro.pacujo.net> <87y4ybdt46.fsf@elektro.pacujo.net> Message-ID: <536D07DF.1080800@arskom.com.tr> On 05/09/14 16:55, Stefan Behnel wrote: > ElementTree has gained a nice API in > Py3.4 that supports this in a much saner way than SAX, using iterators. > Basically, you just dump in some data that you received and get back an > iterator over the elements (and their subtrees) that it generated from it. > Intercept on the right top elements and you get your next subtree as soon > as it's ready. Hi Stefan, Here's a small script: events = etree.iterparse(istr, events=("start", "end")) stack = deque() for event, element in events: if event == "start": stack.append(element) elif event == "end": stack.pop() if len(stack) == 0: break print(istr.tell(), "%5s, %4s, %s" % (event, element.tag, element.text)) where istr is an input-stream. (Fully working example: https://gist.github.com/plq/025005a71e8135c46800) I was expecting to have istr.tell() return the position where the first root element ends, which would make it possible to continue parsing with another call to etree.iterparse(). But istr.tell() returns the position of EOF after the first call to next() on the iterator it returns. Without the stack check, the loop eventually throws an exception and the offset value in that exception is None. So I'm lost here, how it'd possible to parse OP's document with lxml? Best, Burak -------------- next part -------------- An HTML attachment was scrubbed... URL: From alain at dpt-info.u-strasbg.fr Fri May 9 13:16:35 2014 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 09 May 2014 19:16:35 +0200 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> <87k39vupnc.fsf@dpt-info.u-strasbg.fr> <8738gjf813.fsf@elektro.pacujo.net> <87fvkjuf2c.fsf@dpt-info.u-strasbg.fr> <87lhubdj2j.fsf@elektro.pacujo.net> Message-ID: <87bnv6vpn0.fsf@dpt-info.u-strasbg.fr> Marko Rauhamaa writes: > Alain Ketterlin : > >> which does an exact traversal of potential the DOM tree... (assuming a >> DOM is even defined on a non well-formed XML document). >> >> Anyway, my point was only to warn the OP that he is not doing XML. > > I consider that one of the multitude of flaws in XML. I consider such use cases one of the multitude misuses of XML. > Compare that with the close analogue: S expressions. [...] How do you specify the encoding of sexprs? How can you require that an attribute value must match the value of an id-attribute? or whatever insanely complex integrity rule that XML Schemas lets you express? And so on. If all you need to do is parse properly bracketed input, go with sexprs, or json, or yaml, or pickle if both ends are python programs. Using XML for such a trivial task is looking for trouble. -- Alain. From marko at pacujo.net Fri May 9 14:04:24 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 09 May 2014 21:04:24 +0300 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> <87k39vupnc.fsf@dpt-info.u-strasbg.fr> <8738gjf813.fsf@elektro.pacujo.net> <87fvkjuf2c.fsf@dpt-info.u-strasbg.fr> <87lhubdj2j.fsf@elektro.pacujo.net> <87bnv6vpn0.fsf@dpt-info.u-strasbg.fr> Message-ID: <87bnv6de1j.fsf@elektro.pacujo.net> Alain Ketterlin : > How do you specify the encoding of sexprs? How can you require that an > attribute value must match the value of an id-attribute? or whatever > insanely complex integrity rule that XML Schemas lets you express? And > so on. I don't suppose there is a universal schema language available for S expressions, nor do I suppose many people want such a thing. You specify S expression encoding the way you specify Python library functions. I think the worst part of XML is that you can't parse it without a DTD or schema. > If all you need to do is parse properly bracketed input, go with > sexprs, or json, or yaml, or pickle if both ends are python programs. I was very hopeful about json until I discovered they require the parser to dynamically support five different character encodings. XML at least standardized on UTF-8. I have found ast.literal_eval() to be highly usable. Pickle I would advise you to stay away from: . Marko From stefan_ml at behnel.de Fri May 9 15:46:04 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 09 May 2014 21:46:04 +0200 Subject: parsing multiple root element XML into text In-Reply-To: <87bnv6de1j.fsf@elektro.pacujo.net> References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> <87k39vupnc.fsf@dpt-info.u-strasbg.fr> <8738gjf813.fsf@elektro.pacujo.net> <87fvkjuf2c.fsf@dpt-info.u-strasbg.fr> <87lhubdj2j.fsf@elektro.pacujo.net> <87bnv6vpn0.fsf@dpt-info.u-strasbg.fr> <87bnv6de1j.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa, 09.05.2014 20:04: > I think the worst part of XML is that you can't parse it without a DTD > or schema. Nonsense. > I was very hopeful about json until I discovered they require the parser > to dynamically support five different character encodings. > > XML at least standardized on UTF-8. Not really. Definitely not "standardized". It's just the default if there is no explicit encoding or BOM. That doesn't keep you from passing around XML in EBCDIC, if you feel like it. > I have found ast.literal_eval() to be highly usable. Well, there's json.loads(), which is more commonly used for this task. Stefan From stefan_ml at behnel.de Fri May 9 15:51:56 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 09 May 2014 21:51:56 +0200 Subject: parsing multiple root element XML into text In-Reply-To: <536D07DF.1080800@arskom.com.tr> References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> <87oaz7uvo4.fsf@dpt-info.u-strasbg.fr> <87a9arfdha.fsf@elektro.pacujo.net> <87k39vupnc.fsf@dpt-info.u-strasbg.fr> <8738gjf813.fsf@elektro.pacujo.net> <87y4ybdt46.fsf@elektro.pacujo.net> <536D07DF.1080800@arskom.com.tr> Message-ID: Burak Arslan, 09.05.2014 18:52: > On 05/09/14 16:55, Stefan Behnel wrote: >> ElementTree has gained a nice API in >> Py3.4 that supports this in a much saner way than SAX, using iterators. >> Basically, you just dump in some data that you received and get back an >> iterator over the elements (and their subtrees) that it generated from it. >> Intercept on the right top elements and you get your next subtree as soon >> as it's ready. > > Here's a small script: A bit hard to read, though. > events = etree.iterparse(istr, events=("start", "end")) > stack = deque() > for event, element in events: > if event == "start": > stack.append(element) > elif event == "end": > stack.pop() > > if len(stack) == 0: > break > > print(istr.tell(), "%5s, %4s, %s" % (event, element.tag, element.text)) > > where istr is an input-stream. (Fully working example: > https://gist.github.com/plq/025005a71e8135c46800) > > I was expecting to have istr.tell() return the position where the first > root element ends, which would make it possible to continue parsing with > another call to etree.iterparse(). But istr.tell() returns the position > of EOF after the first call to next() on the iterator it returns. Correct, because it finished parsing. It controls the reading process and reads ahead, that's how iterparse() works. > Without the stack check, the loop eventually throws an exception and the > offset value in that exception is None. > > So I'm lost here, how it'd possible to parse OP's document with lxml? See my earlier post. Instead of XMLParser, just use the XMLPullParser for incremental (non-blocking) parsing and processing. To make this clear, though: to use an XML parser, you need well formed XML, and that means exactly one root element. Stefan From scottcabit at gmail.com Fri May 9 15:51:04 2014 From: scottcabit at gmail.com (scottcabit at gmail.com) Date: Fri, 9 May 2014 12:51:04 -0700 (PDT) Subject: Why isn't my re.sub replacing the contents of my MS Word file? Message-ID: Hi, here is a snippet of code that opens a file (fn contains the path\name) and first tried to replace all endash, emdash etc characters with simple dash characters, before doing a search. But the replaces are not having any effect. Obviously a syntax problem....wwhat silly thing am I doing wrong? Thanks! fn = 'z:\Documentation\Software' def processdoc(fn,outfile): fStr = open(fn, 'rb').read() re.sub(b'‒','-',fStr) re.sub(b'–','-',fStr) re.sub(b'—','-',fStr) re.sub(b'―','-',fStr) re.sub(b'⸺','-',fStr) re.sub(b'⸻','-',fStr) re.sub(b'-','-',fStr) re.sub(b'­','-',fStr) From python at mrabarnett.plus.com Fri May 9 16:03:40 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 09 May 2014 21:03:40 +0100 Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: References: Message-ID: <536D349C.5000802@mrabarnett.plus.com> On 2014-05-09 20:51, scottcabit at gmail.com wrote: > Hi, > > here is a snippet of code that opens a file (fn contains the path\name) and first tried to replace all endash, emdash etc characters with simple dash characters, before doing a search. > But the replaces are not having any effect. Obviously a syntax problem....wwhat silly thing am I doing wrong? > > Thanks! > > fn = 'z:\Documentation\Software' > def processdoc(fn,outfile): > fStr = open(fn, 'rb').read() > re.sub(b'‒','-',fStr) > re.sub(b'–','-',fStr) > re.sub(b'—','-',fStr) > re.sub(b'―','-',fStr) > re.sub(b'⸺','-',fStr) > re.sub(b'⸻','-',fStr) > re.sub(b'-','-',fStr) > re.sub(b'­','-',fStr) > re.sub _returns_ its result (strings are immutable). From rosuav at gmail.com Fri May 9 16:08:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 10 May 2014 06:08:01 +1000 Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: References: Message-ID: On Sat, May 10, 2014 at 5:51 AM, wrote: > But the replaces are not having any effect. Obviously a syntax problem....wwhat silly thing am I doing wrong? > > Thanks! > > fn = 'z:\Documentation\Software' > def processdoc(fn,outfile): > fStr = open(fn, 'rb').read() > re.sub(b'‒','-',fStr) > re.sub(b'–','-',fStr) > re.sub(b'—','-',fStr) > re.sub(b'―','-',fStr) > re.sub(b'⸺','-',fStr) > re.sub(b'⸻','-',fStr) > re.sub(b'-','-',fStr) > re.sub(b'­','-',fStr) I can see several things that might be wrong, but it's hard to say what *is* wrong without trying it. 1) Is the file close enough to text that you can even do this sort of parsing? You say it's an MS Word file; that, unfortunately, could mean a lot of things. Some of the newer formats are basically zipped XML, so translations like this won't work. Other forms of Word document may be closer to text, but you majorly risk corrupting the binary content. 2) How are characters represented? Are they actually stored in the file with ampersands, hashes, etc? Your source strings are all seven bytes long, and will look for exactly those bytes. There must be some form of character encoding used; possibly, instead of the &#x notation, you need to UTF-8 or UTF-16LE encode the characters to look for. 3) You're doing simple string replacements using regular expressions. I don't think any of your symbols here is a metacharacter, but I might be wrong. If you're simply replacing one stream of bytes with another, don't use regex at all, just use string replacement. 4) There's nothing in your current code to actually write the contents anywhere. You do all the changes and then do nothing with it. Or is this just part of the code? 5) Similarly, there's nothing in this fragment that actually calls processdoc(). Did you elide that? The fragment you wrote will do a whole lot of nothing, on its own. 6) There's no file extension on your input file name; be sure you really have the file you want, and not (for instance) a directory. Or if you need to iterate over all the files in a directory, you'll need to do that explicitly. 7) This one isn't technically a problem, but it's a risk. The string 'z:\Documentation\Software' has two backslash escapes \D and \S, which the parser fails to recognize, and therefore passes through literally. So it works, currently. However, if you were to change the path to, say, 'z:\Documentation\backups', then it would suddenly fail. There are several solutions to this: 7a) fn = r'z:\Documentation\Software' 7b) fn = 'z:\\Documentation\\Software' 7c) fn = 'z:/Documentation/Software' Hope that helps some, at least! A more full program would be easier to work with. ChrisA From python.list at tim.thechases.com Fri May 9 16:09:58 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 9 May 2014 15:09:58 -0500 Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: References: Message-ID: <20140509150958.22340d7a@bigbox.christie.dr> On 2014-05-09 12:51, scottcabit at gmail.com wrote: > here is a snippet of code that opens a file (fn contains the > path\name) and first tried to replace all endash, emdash etc > characters with simple dash characters, before doing a search. But > the replaces are not having any effect. Obviously a syntax > problem....wwhat silly thing am I doing wrong? > > fn = 'z:\Documentation\Software' > def processdoc(fn,outfile): > fStr = open(fn, 'rb').read() > re.sub(b'‒','-',fStr) > re.sub(b'–','-',fStr) > re.sub(b'—','-',fStr) > re.sub(b'―','-',fStr) > re.sub(b'⸺','-',fStr) > re.sub(b'⸻','-',fStr) > re.sub(b'-','-',fStr) > re.sub(b'­','-',fStr) A Word doc (as your subject mentions) is a binary format. There's the older .doc and the newer .docx (which is actually a .zip file with a particular content-structure renamed to .docx). Your example doesn't show the extension, so it's hard to tell whether you're working with the old format or the new format. That said, a simple replacement *certainly* won't work for a .docx file, as you'd have to uncompress the contents, open up the various files inside, perform the replacements, then zip everything back up, and save the result back out. For the older .doc file, it's a binary format, so even if you can successfully find & swap out sequences of 7 chars for a single char, it might screw up the internal offsets, breaking your file. Additionally, I vaguely remember sparring with them using some 16-bit wide characters in .doc files so you might have to search for atrocious things like b"\x00&\x00#\x00x\x002\x000\x001\x002" (each character being prefixed with "\x00". -tkc From junnia at gmail.com Fri May 9 16:45:54 2014 From: junnia at gmail.com (junnia at gmail.com) Date: Fri, 9 May 2014 13:45:54 -0700 (PDT) Subject: Python Internet Database Message-ID: I am writing a PhD thesis comparing computer languages, and Python and Ruby is among the languages I am working with. I am using the Rasch Model to measure latent traits and like productivity, expressivity, referential transparency and efficiency. If a member of this list wants to read a short tutorial about the Rasch Model, here is the address: http://strues.org/languages To keep with my work, I need an Internet Data Base from where a person writing a program in Python could fetch libraries, applications, compilers, etc. One of the things I need to measure is how complete and easy to use is such a data base. I will give a concrete example. Suppose that a person is writing programs in sbcl, an implementation of Common Lisp. That person needs a compiler for Python. All he needs to do is add the following line to the REPL (Read Eval Print Loop) line: (ql:quickload :cl-python) In a few seconds, Lisp will access a Internet Data Base and will download and install a Python compiler written in Common Lisp. This Python compiler will be completely integrated with Common Lisp, in the sense that one can mix Python and Common Lisp programs. The Common Lisp compiler will pass the Pystone, etc. Suppose now that this same Common Lisp programmer needs to add a few routines written in Fortran. He can fetch a Fortran compiler written in Common Lisp as easily as he did with CL-Python: (ql:quick load :f2cl) will do the magic. If he needs to generate beautiful pdf, he can download cl-pdf. If he needs an efficient Internet server, he can use Hunchentoot. Everything can be fetched by the ql:quickload command. Of course Common Lisp is not the only language with this kind of facility. Racket has its own database: PLaneT. Again, one can get many applications and libraries from PLantet repository. I wonder if Python has a similar repository. Suppose I want a Fortran to Python converter; then I would type: > sys f2py If I want an emacs like editor, I would type > sys pyemacs, and so on. By the way, although emacs itself is largely written in elisp, there are many emacs clones that one can find in Lisp repositories; for instance, hemlock is the most famous of these clones. Racket has its own environment, that is drracket, that accept even images mixed to the text. I made a list of 9 things that I would like to see in such a repository. By the way, I heard that Ruby has an Internet repository too. If people from this list know about the Ruby repository, I would appreciate information on how to use it. In any case, information about the Python repository will be very useful. People who are funding my thesis would like to check for the following applications. I mean, I will check whether the repository offers the applications and libraries listed below. 1 - Internet servers. In Lisp, one has hunchentoot. In Racket, one has the Racket Web Framework. Bigloo has hiphop. 2 - Jit compiler for using from a web server. I mean, one has a web server running under Apache in a hosting service like Hostgator, Daddy Host or another inexpensive service. I decide to run a few applications in Racket, but the application requires number crunching. I install the Jit Racket in the hosting service, and call it from my dynamic generated page. My programs will run almost at the speed of optimised C. 3 - Music generation. I would like generation of musical scores and midi files. 4 - Text editor that mimics emacs. In Common Lisp, one has hemlock. I would like something in the lines of hemlock. 5 - CAD and electronic CAD. Something in the lines of PTC. 6 - The repository service is the other thing that I want to check. I mean, I want the address of the Python equivalent of quicklisp and PLaneT. 7 - Image generation. pdf generation. Something in the lines of cl-pdf and cl-png, fl-vector, etc. Of course, I need programs written in Python itself, not call to C libraries. 8 - Usable compilers for other languages. For example, a JIT compiler for Python itself written in Python. Compilers for Fortran, compilers for Common Lisp, for Javascript, etc. BTW, the compiler generator of Common Lisp has the same name as the Python language. In other words, the language in which the Common Lisp compiler is written is called Python too. Therefore, when I ask for a compiler generator in Python, many people send me a link to this Common Lisp Python compiler generator. What I want is a compiler generator in Python, the scripting language. 9 - Computer algebra. Something in the lines of Maxima will do. I don't hope to find all these nine things in a single repository. Even if you tell me that there is nothing in Python similar to Maxima or to the Common Lisp Python compiler generator or even to hemlock, your information will be very useful. The list is tough, so that no language is able to offer all items. From scottcabit at gmail.com Fri May 9 16:46:35 2014 From: scottcabit at gmail.com (scottcabit at gmail.com) Date: Fri, 9 May 2014 13:46:35 -0700 (PDT) Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: References: Message-ID: <8126fa0d-7480-41dd-a4bf-60e2a02ec272@googlegroups.com> > > re.sub _returns_ its result (strings are immutable). Ahh....so I tried this for each re.sub fStr = re.sub(b'‒','-',fStr) No errors running it, but it still does nothing..... From scottcabit at gmail.com Fri May 9 16:49:56 2014 From: scottcabit at gmail.com (scottcabit at gmail.com) Date: Fri, 9 May 2014 13:49:56 -0700 (PDT) Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: References: Message-ID: On Friday, May 9, 2014 4:09:58 PM UTC-4, Tim Chase wrote: > A Word doc (as your subject mentions) is a binary format. There's > the older .doc and the newer .docx (which is actually a .zip file > with a particular content-structure renamed to .docx). > I am using .doc files only...... > > For the older .doc file, it's a binary format, so even if you can > successfully find & swap out sequences of 7 chars for a single char, > it might screw up the internal offsets, breaking your file. I do not save the file out again, only try to change all en-dash and em-dash to dashes, then search and print things to another file, closing the searched file without writing it. > > Additionally, I vaguely remember sparring with them using some 16-bit > wide characters in .doc files so you might have to search for > atrocious things like b"\x00&\x00#\x00x\x002\x000\x001\x002" (each > character being prefixed with "\x00". Hmmm..thought that was what I was doing. Can anyone figure out why the syntax is wrong for Word 2007 document binary file data? From rosuav at gmail.com Fri May 9 17:06:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 10 May 2014 07:06:34 +1000 Subject: Python Internet Database In-Reply-To: References: Message-ID: On Sat, May 10, 2014 at 6:45 AM, wrote: > To keep with my work, I need an Internet Data Base from where a person writing a program in Python could fetch libraries, applications, compilers, etc. One of the things I need to measure is how complete and easy to use is such a data base. I will give a concrete example. > I'm not entirely sure, but I think PyPI (the Python Package Index) might be what you're looking for. It has all sorts of things that aren't in the Python standard library (and, for various reasons, some things which are). > 1 - Internet servers. In Lisp, one has hunchentoot. In Racket, one has the Racket Web Framework. Bigloo has hiphop. > Python has some of this built in; not sure what you mean by "internet servers", but you can easily write some of the more common services in Python (eg web (HTTP), mail (SMTP), etc). I don't know of a way to conveniently write a Python DNS server, for instance, short of working with sockets manually, but most of what people commonly use is there. > 2 - Jit compiler for using from a web server. I mean, one has a web server running under Apache in a hosting service like Hostgator, Daddy Host or another inexpensive service. I decide to run a few applications in Racket, but the application requires number crunching. I install the Jit Racket in the hosting service, and call it from my dynamic generated page. My programs will run almost at the speed of optimised C. > For number crunching, you can use the numpy library, which is highly efficient. For general JIT compilation of actual Python code, PyPy will do that. AFAIK there's no standard module for that, though. > 3 - Music generation. I would like generation of musical scores and midi files. I'm not aware of anything in particular, but a GNU LilyPond input file is simple text, so I'd just write a program that produces a .ly file and then run it through LilyPond to generate both score and MIDI. But if you don't need printable score, the MIDI file itself is pretty simple; there may be a module that will help, but even without, it's pretty straight-forward in any language. I don't know about your other requests, but check out PyPI and see what you can find - and do also check the standard library, if you haven't already. Each new version adds even more cool stuff; we've recently gained a dedicated statistics module, for instance, and a new asynchronous I/O structure. ChrisA From ian.g.kelly at gmail.com Fri May 9 17:07:23 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 9 May 2014 15:07:23 -0600 Subject: Python Internet Database In-Reply-To: References: Message-ID: On Fri, May 9, 2014 at 2:45 PM, wrote: > I am writing a PhD thesis comparing computer languages, and Python and Ruby is among the languages I am working with. I am using the Rasch Model to measure latent traits and like productivity, expressivity, referential transparency and efficiency. If a member of this list wants to read a short tutorial about the Rasch Model, here is the address: > > http://strues.org/languages > > To keep with my work, I need an Internet Data Base from where a person writing a program in Python could fetch libraries, applications, compilers, etc. One of the things I need to measure is how complete and easy to use is such a data base. I will give a concrete example. It sounds to me like you're looking for PyPI: https://pypi.python.org/pypi The official way to install packages from PyPI is using the pip package manager, e.g.: > pip install numpy pip is included with sufficiently recent Python releases, or can be installed separately. From tjreedy at udel.edu Fri May 9 17:15:50 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 May 2014 17:15:50 -0400 Subject: Python Internet Database In-Reply-To: References: Message-ID: On 5/9/2014 4:45 PM, junnia at gmail.com wrote: > I am writing a PhD thesis comparing computer languages, and Python > and Ruby is among the languages I am working with. I am using the > Rasch Model to measure latent traits and like productivity, > expressivity, referential transparency and efficiency. If a member of > this list wants to read a short tutorial about the Rasch Model, here > is the address: > > http://strues.org/languages > > To keep with my work, I need an Internet Data Base from where a > person writing a program in Python could fetch libraries, > applications, compilers, etc. One of the things I need to measure is > how complete and easy to use is such a data base. I will give a > concrete example. https://pypi.python.org/pypi > Suppose that a person is writing programs in sbcl, an implementation > of Common Lisp. That person needs a compiler for Python. All he needs > to do is add the following line to the REPL (Read Eval Print Loop) > line: > > (ql:quickload :cl-python) > > In a few seconds, Lisp will access a Internet Data Base and will > download and install a Python compiler written in Common Lisp. This > Python compiler will be completely integrated with Common Lisp, in > the sense that one can mix Python and Common Lisp programs. The > Common Lisp compiler will pass the Pystone, etc. Suppose now that > this same Common Lisp programmer needs to add a few routines written > in Fortran. He can fetch a Fortran compiler written in Common Lisp as > easily as he did with CL-Python: (ql:quick load :f2cl) will do the > magic. If he needs to generate beautiful pdf, he can download cl-pdf. > If he needs an efficient Internet server, he can use Hunchentoot. > Everything can be fetched by the ql:quickload command. > > Of course Common Lisp is not the only language with this kind of > facility. Racket has its own database: PLaneT. Again, one can get > many applications and libraries from PLantet repository. I wonder if > Python has a similar repository. Suppose I want a Fortran to Python > converter; then I would type: > sys f2py If I want an emacs like > editor, I would type > sys pyemacs, and so on. By the way, although > emacs itself is largely written in elisp, there are many emacs clones > that one can find in Lisp repositories; for instance, hemlock is the > most famous of these clones. Racket has its own environment, that is > drracket, that accept even images mixed to the text. > > I made a list of 9 things that I would like to see in such a > repository. By the way, I heard that Ruby has an Internet repository > too. If people from this list know about the Ruby repository, I would > appreciate information on how to use it. In any case, information > about the Python repository will be very useful. > > People who are funding my thesis would like to check for the > following applications. I mean, I will check whether the repository > offers the applications and libraries listed below. > > 1 - Internet servers. In Lisp, one has hunchentoot. In Racket, one > has the Racket Web Framework. Bigloo has hiphop. multiple available. > 2 - Jit compiler pypy is an implementation of python in python, with jit compiler. > for using from a web server. This is really specialized. It seems that your requirements list is based on, and therefore biased toward, what is available for lisp/racket. Webservers are typically not computation bound, so jit compiler is not too relevant. However, you can run Python-coded webservers on pypy if you want to and see a benefit. However, pypu really shines on integer math. > I mean, one has a web server running under Apache There is a mod-python for running Python on Apache. > in a hosting service like Hostgator, > Daddy Host or another inexpensive service. I decide to run a few > applications in Racket, but the application requires number > crunching. I install the Jit Racket in the hosting service, and call > it from my dynamic generated page. My programs will run almost at the > speed of optimised C. > 3 - Music generation. I would like generation of musical scores and > midi files. Search pypi. > 4 - Text editor that mimics emacs. In Common Lisp, one has hemlock. I > would like something in the lines of hemlock. Python people who want emacs use emacs with Python extension, not a mimic. > 5 - CAD and electronic CAD. Something in the lines of PTC. > > 6 - The repository service is the other thing that I want to check. I > mean, I want the address of the Python equivalent of quicklisp and > PLaneT. see above > 7 - Image generation. pdf generation. Something in the lines of > cl-pdf and cl-png, fl-vector, etc. Of course, I need programs written > in Python itself, not call to C libraries. This is a stupid requirement. CPython, written in Python, is designed to make interfacing to C libraries easy. It also interfaces to Fortran (see numpy), and interactively calling Fortran functions was perhaps the first killer application of Python in the mid 1959s. > 8 - Usable compilers for other languages. For example, a JIT compiler > for Python itself written in Python. See pypy. > Compilers for Fortran, compilers > for Common Lisp, for Javascript, etc. BTW, the compiler generator of > Common Lisp has the same name as the Python language. In other words, > the language in which the Common Lisp compiler is written is called > Python too. Therefore, when I ask for a compiler generator in Python, > many people send me a link to this Common Lisp Python compiler > generator. What I want is a compiler generator in Python, the > scripting language. > > 9 - Computer algebra. Something in the lines of Maxima will do. > > I don't hope to find all these nine things in a single repository. Well, there is lots of Python projects on SourceForge, Bitbucket, Github, ... . Why expect all in one place? > Even if you tell me that there is nothing in Python similar to Maxima > or to the Common Lisp Python compiler generator or even to hemlock, > your information will be very useful. The list is tough, so that no > language is able to offer all items. -- Terry Jan Reedy From ian.g.kelly at gmail.com Fri May 9 17:30:57 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 9 May 2014 15:30:57 -0600 Subject: Python Internet Database In-Reply-To: References: Message-ID: On Fri, May 9, 2014 at 2:45 PM, wrote: > 1 - Internet servers. In Lisp, one has hunchentoot. In Racket, one has the Racket Web Framework. Bigloo has hiphop. twisted, tornado, Django, pylons, turbogears, bottle, flask among many others. > 2 - Jit compiler for using from a web server. I mean, one has a web server running under Apache in a hosting service like Hostgator, Daddy Host or another inexpensive service. I decide to run a few applications in Racket, but the application requires number crunching. I install the Jit Racket in the hosting service, and call it from my dynamic generated page. My programs will run almost at the speed of optimised C. PyPy is an alternate implementation of Python written in Python with JIT compilation. It is compatible with various web frameworks. You'll find it at pypy.org. > 4 - Text editor that mimics emacs. In Common Lisp, one has hemlock. I would like something in the lines of hemlock. Why not just use emacs? It has a python mode. > 7 - Image generation. pdf generation. Something in the lines of cl-pdf and cl-png, fl-vector, etc. Of course, I need programs written in Python itself, not call to C libraries. The pillow library (successor to the defunct Python Imaging Library) is probably the best known. It's not a C library, but it is an extension library, meaning it is a Python library written in C. > 9 - Computer algebra. Something in the lines of Maxima will do. Try SymPy. From harrismh777 at gmail.com Fri May 9 17:56:07 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 09 May 2014 16:56:07 -0500 Subject: Values and objects [was Re: Pass variable by reference] References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/7/14 8:08 PM, Steven D'Aprano wrote: > In Python, all values *are* objects. It isn't a matter of choosing one or > the other. The value 1 is an object, not a native (low-level, unboxed) 32 > or 64 bit int. > > Unlike C# or Java, there is no direct language facility to box native > values into objects or unbox objects to native values. > Yes. In the context of the rest of this discussion, this one point is just one of the many reasons why it is not helpful to think of Python's {name: object} relationship as 'variable -- value'. Typically when I think about variables (particularly from the past, say Pascal, Basic, C, Fortran, Cobol &c) I am thinking about modeling memory is some way where the variable (some naming convention) is a value handle or value pointer of some chunk of memory (by type | length) --- where I am creating a 'box' into which I may place something (usually some native type). When I think of Python's 'variables' (and I don't believe Python has variables) I am now thinking of a naming convention (for handling objects) where I am not the least interested in modeling memory for native types. I am instead interested in modeling the real world (or subset) with object abstractions. I am no longer interested in creating a 'box' into which I may place some type. I don't need variables any longer for that purpose. What I want is some very efficient naming convention whereby I can handle the objects I am constructing (for whatever abstract purpose). If a programmer new to Python thinks in terms of 'variables' from C or Pascal, or Fortran or Basic, they will run into surprises when it comes to handling the {name: object} idea in Python. In fact, most of the time this debate comes up it is precisely that the new user is finding Python's 'variables' aren't behaving correctly or finding that they are not able to 'do' what they used to do (say) with C's variables. It really comes down to the definition of 'variable' and whether the language in question is modeling memory, or modeling object abstractions. marcus From harrismh777 at gmail.com Fri May 9 18:30:10 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 09 May 2014 17:30:10 -0500 Subject: Pass variable by reference References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: On 5/7/14 8:31 PM, Chris Angelico wrote: > On Thu, May 8, 2014 at 4:11 AM, Mark H Harris wrote: >> And we must never forget that CPython's underpinnings, uhm C, uses >> variables, C ones... (never mind) > > Be careful of this one. It's utterly irrelevant to your point, and may > be distracting. I could implement Ook in Python; does that mean that > Ook has a socket library? Clearly not. Probably. Although, its turtles all the way down. C is a better way to write asm code (more efficient, less lines of code, better abstraction, way more readable). wow, use C to build Python. Python is requires way less lines of code than C, better abstraction, more efficient, and way more readable. Now, down under the stack of turtles, we are still placing values into memory boxes (variables) although we are getting there from a very abstract and indirect way; but its turtles all the way down from a certain point of view. On the other hand, if we are coming at this from the highest level (strictly pure Python coding) all we care about is abstracting the real world by constructing objects which interact with the rest of the world and with themselves. We are no longer interested in modeling memory (although that does happen somewhere) --- what we are interested in is modeling life and the objects of life. The mechanism of {name: object} is so far above the simple name -- value pair mechanism we used to call 'variables' (boxes holding native types) that we really need some new name for the concept... is a Python 'name' a variable. No. Then what is it? If we call it a variable (what ever we mean by that) someone is going to be confused as they try to write Python code. What should it be referred to? Someone said it is silly to say that Python has no variables. I disagree. We need a way to speak about Python variables that highlights the distinctions which create for new coders (and some old ones too) the misunderstandings and surprises which spark a debate like this one. As someone else pointed out its a both|and. I suppose I agree. OTOH: A = 7 Seven is not a C integer native type, and A is not a static int variable. 7 is an object, and the name A is bound to it. What shall we call A ? object nomenclature : A is objname, objhandle, OBH. or just handle. I think we need to stop calling it a variable. marcus From harrismh777 at gmail.com Fri May 9 18:34:17 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 09 May 2014 17:34:17 -0500 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <536add6b$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536D57E9.5080801@gmail.com> On 5/7/14 8:27 PM, Steven D'Aprano wrote: >> In almost every other language you know A and B each "contain" by >> reference (and almost always by static type) macTruck. But NOT python. > > Nor Javascript, Ruby, Perl, PHP, Lua, or (I think) Lisp or Java. To > mention only a few. > > I think it is easy to exaggerate the difference between Python and > "almost every other language". Python's name binding model is very common > amongst dynamically typed languages, and there are many dynamically typed > languages. Then we don't need a discussion. Why are new Python coders 'always' confused by this question of variable (name value) vs. {name: object} model of Python? The reason I suggest is that the person has a preconceived idea of what 'variable' means, and they then attempt to apply their conception of variable on to Python in some way ending in a surprise. We need a way to speak about Pythons name object model to avoid this confusion. marcus From marko at pacujo.net Fri May 9 18:34:58 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 10 May 2014 01:34:58 +0300 Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zjiqbmy5.fsf@elektro.pacujo.net> Mark H Harris : > Typically when I think about variables (particularly from the > past, say Pascal, Basic, C, Fortran, Cobol &c) I am thinking about > modeling memory is some way where the variable (some naming > convention) is a value handle or value pointer of some chunk of memory > (by type | length) --- where I am creating a 'box' into which I may > place something (usually some native type). > > When I think of Python's 'variables' (and I don't believe Python > has variables) I am now thinking of a naming convention (for handling > objects) where I am not the least interested in modeling memory for > native types. I am instead interested in modeling the real world (or > subset) with object abstractions. I am no longer interested in > creating a 'box' into which I may place some type. I don't need > variables any longer for that purpose. What I want is some very > efficient naming convention whereby I can handle the objects I am > constructing (for whatever abstract purpose). Right, Python's variables aren't like variables in C. Rather, Python's variables are like CPU registers. They cannot hold typed or structured objects and you can't pass references to them. Marko From steve+comp.lang.python at pearwood.info Fri May 9 20:00:00 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 00:00:00 GMT Subject: trailing underscores naming convention_ References: <57d21b4f-10db-4fbf-82f4-d33250b14456@googlegroups.com> <57b0d9ec-b8a4-4021-b25f-422a9fe11529@googlegroups.com> Message-ID: <536d6bff$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 09 May 2014 10:35:09 -0600, Michael Torrie wrote: > On 05/08/2014 11:49 PM, Metallicow wrote: >> I guess to be more clear here is a small code snippet that shows what >> is happening more readably. Hence the underscores question. > > In a case like this I'd probably prefer to number the methods rather > than add underscores to the end of the names. My current font, for > example, connects the underscores together, so it's a bit hard from a > glance to tell if it's just two underscores or three. > > I'd prefer OnLeftDClick1, OnLeftDClick2, OnLeftDClick3, for example. Yes, this. I wouldn't say that underscore suffixes are *reserved* only for avoiding name clashes with keywords and built-ins, e.g. in_ type_ etc., but I can't think of any other reason why you would want to end an identifier with an underscore. As for multiple underscores like in__ in___ in____ that's just too hideous for words. > And I also prefer pep8 method names as well, on_left_dclick1, etc. But > when the underlying library doesn't follow pep8, then I guess it does > not matter (self.Bind is from the library I presume). And again, this. -- Steven D'Aprano http://import-that.dreamwidth.org/ From breamoreboy at yahoo.co.uk Fri May 9 20:03:00 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 10 May 2014 01:03:00 +0100 Subject: The =?UTF-8?B?w6LigqzFk2RvZXMgUHl0aG9uIGhhdmUgdmFyaWFibGVzP8Oi?= =?UTF-8?B?4oKs55GpIGRlYmF0ZQ==?= In-Reply-To: References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536c3049$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/05/2014 00:51, Dennis Lee Bieber wrote: > On Thu, 08 May 2014 22:21:25 -0400, Roy Smith declaimed the > following: > >> In article <536c3049$0$29965$c3e8da3$5496439d at news.astraweb.com>, >> Steven D'Aprano wrote: >> >>> Although Fortran is still in use, and widely so, it is mostly used for >>> accessing existing Fortran libraries rather than writing new >>> applications. There may be niches where that does not hold, where people >>> are actively writing new applications in Fortran, but they are niches. >>> Today, Fortran is rarely used for general purpose computing, updated >>> standards or no updated standards. >> >> Oddly enough, my current use of Fortran is via Python. The scipy and >> statsmodels libraries use Fortran routines under the covers. > > To me, that is NOT "use of Fortran"... It is nothing more than the use > of a /library with a documented calling spec (API)/. > > That the library was written in Fortran is irrelevant. Especially if > one is working a VMS system where all the languages had features for > calling functions written on others (in effect, the equivalent of Python's > ctypes module, as a general commonality on the system) > Oh the joy, a tedious, repetative thread is made infinitely better by the mention of three wonderful letters, V, M and S. What bliss :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Fri May 9 20:12:57 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 00:12:57 GMT Subject: Why isn't my re.sub replacing the contents of my MS Word file? References: Message-ID: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 09 May 2014 12:51:04 -0700, scottcabit wrote: > Hi, > > here is a snippet of code that opens a file (fn contains the path\name) > and first tried to replace all endash, emdash etc characters with > simple dash characters, before doing a search. > But the replaces are not having any effect. Obviously a syntax > problem....wwhat silly thing am I doing wrong? You're making the substitution, then throwing the result away. And you're using a nuclear-powered bulldozer to crack a peanut. This is not a job for regexes, this is a job for normal string replacement. > fn = 'z:\Documentation\Software' > def processdoc(fn,outfile): > fStr = open(fn, 'rb').read() > re.sub(b'‒','-',fStr) Good: fStr = re.sub(b'‒', b'-', fStr) Better: fStr = fStr.replace(b'‒', b'-') But having said that, you actually can make use of the nuclear-powered bulldozer, and do all the replacements in one go: Best: # Untested fStr = re.sub(b'&#x(201[2-5])|(2E3[AB])|(00[2A]D)', b'-', fStr) If you're going to unload the power of regexes, unload them on something that makes it worthwhile. Replacing a constant, fixed string with another constant, fixed string does not require a regex. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ben at benfinney.id.au Fri May 9 20:24:18 2014 From: ben at benfinney.id.au (Ben Finney) Date: Sat, 10 May 2014 10:24:18 +1000 Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> Message-ID: <85ppjma3bh.fsf@benfinney.id.au> Marko Rauhamaa writes: > Right, Python's variables aren't like variables in C. Rather, Python's > variables are like CPU registers. What is the salient difference between those two? I don't see the point of the distinction. Why have you chosen an analogy ? CPU registers ? that still uses the misleading ?copies in containers? model, rather than the ?sticky-notes on objects? model? The latter more accurately describes Python's references. > They cannot hold typed or structured objects This is quite false. Every object in Python is typed and structured, and to the extent that Python has ?variables?, they always refer to a typed and structured object. -- \ ?Do unto others twenty-five percent better than you expect them | `\ to do unto you. (The twenty-five percent is [to correct] for | _o__) error.)? ?Linus Pauling's Golden Rule | Ben Finney From steve+comp.lang.python at pearwood.info Fri May 9 20:31:39 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 00:31:39 GMT Subject: Why isn't my re.sub replacing the contents of my MS Word file? References: Message-ID: <536d736b$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 09 May 2014 13:49:56 -0700, scottcabit wrote: > On Friday, May 9, 2014 4:09:58 PM UTC-4, Tim Chase wrote: > >> A Word doc (as your subject mentions) is a binary format. There's the >> older .doc and the newer .docx (which is actually a .zip file with a >> particular content-structure renamed to .docx). >> > I am using .doc files only...... Ah, my previous email missed the fact that you are operating on Word docs. >> For the older .doc file, it's a binary format, so even if you can >> successfully find & swap out sequences of 7 chars for a single char, it >> might screw up the internal offsets, breaking your file. > > I do not save the file out again, only try to change all en-dash and > em-dash to dashes, then search and print things to another file, > closing the searched file without writing it. > > >> Additionally, I vaguely remember sparring with them using some 16-bit >> wide characters in .doc files so you might have to search for atrocious >> things like b"\x00&\x00#\x00x\x002\x000\x001\x002" (each character >> being prefixed with "\x00". > > Hmmm..thought that was what I was doing. Can anyone figure out why the > syntax is wrong for Word 2007 document binary file data? You are searching for the literal "‒", in other words: ampersand hash x two zero one two *not* a FIGURE DASH. Compare: py> import re py> source = b'aaaa�' py> print(source) b'aaaa�' py> re.sub(b'‒', b'Z', source) b'aaaaZaaaa' But if the source contains an *actual* FIGURE DASH: py> source = u'aaaa\u2012aaaa'.encode('utf-8') py> print(source) b'aaaa\xe2\x80\x92aaaa' py> re.sub(b'‒', b'Z', source) b'aaaa\xe2\x80\x92aaaa' You're dealing with a binary file format, and I believe it is an undocumented binary file format. You don't know which parts of the file represent text, metadata, formatting and layout information, or images. Even if you identify which parts are text, you don't know what encoding is used internally: py> u'aaaa\u2012aaaa'.encode('utf-8') b'aaaa\xe2\x80\x92aaaa' py> u'aaaa\u2012aaaa'.encode('utf-16be') b'\x00a\x00a\x00a\x00a \x12\x00a\x00a\x00a\x00a' py> u'aaaa\u2012aaaa'.encode('utf-16le') b'a\x00a\x00a\x00a\x00\x12 a\x00a\x00a\x00a\x00' or something else. You're on *extremely* thin ice here. If you *must* do this, then you'll need to identify how Word stores various dashes in the file. If you're lucky, the textual parts of the doc file will be obvious to the eye, so open a few sample files using a hex editor and you might be able to identify what Word is using to store the various forms of dash. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri May 9 20:58:58 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 00:58:58 GMT Subject: Abstractions [was Re: Pass variable by reference] References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> Message-ID: <536d79d1$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 09 May 2014 17:30:10 -0500, Mark H Harris wrote: > On 5/7/14 8:31 PM, Chris Angelico wrote: >> On Thu, May 8, 2014 at 4:11 AM, Mark H Harris >> wrote: >>> And we must never forget that CPython's underpinnings, uhm C, uses >>> variables, C ones... (never mind) >> >> Be careful of this one. It's utterly irrelevant to your point, and may >> be distracting. I could implement Ook in Python; does that mean that >> Ook has a socket library? Clearly not. > > Probably. Although, its turtles all the way down. C is a better way > to write asm code (more efficient, less lines of code, better > abstraction, way more readable). wow, use C to build Python. Python is > requires way less lines of code than C, better abstraction, more > efficient, and way more readable. Now, down under the stack of turtles, > we are still placing values into memory boxes (variables) although we > are getting there from a very abstract and indirect way; but its turtles > all the way down from a certain point of view. I think you have missed the point that "turtles all the way down" means an *infinite* chain of abstractions, not a finite one. But when running code, eventually you reach hardware, and the chain of abstractions ends. No more turtles. Suppose I run some code in a BASIC interpreter written in Prolog, which I run in an emulator written in Python, running on PyPy. Then we have the following levels of explanation of what's going on, from the most high level to the lowest level: BASIC Prolog Python RPython C Machine code Micro code and we reach the actual hardware layer and the abstractions are over. (If you want to nit-pic about whether micro code is an abstraction, that's fine, you can add a layer or two if you wish. But we're not far from *actual electric currents in an actual physical device*, at which point we're now talking about a concrete, physical description of the process, not an abstraction. There really is a bottom-most turtle that holds up all the rest.) -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri May 9 21:01:49 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 01:01:49 GMT Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> Message-ID: <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 May 2014 01:34:58 +0300, Marko Rauhamaa wrote: > Right, Python's variables aren't like variables in C. Rather, Python's > variables are like CPU registers. They cannot hold typed or structured > objects Surely you cannot mean that? It is *trivially simple* to disprove that statement: py> x = [1, 2, 3] # A structured object py> type(x) # that has a type > and you can't pass references to them. That at least you have got right. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri May 9 21:11:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 01:11:59 GMT Subject: The =?iso-8859-13?q?=B4does_Python_have_variables=3F=A1?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <536add6b$0$29965$c3e8da3$5496439d@news.astraweb.com> <536D57E9.5080801@gmail.com> Message-ID: <536d7cdf$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 09 May 2014 17:34:17 -0500, Mark H Harris wrote: > On 5/7/14 8:27 PM, Steven D'Aprano wrote: >>> In almost every other language you know A and B each "contain" by >>> reference (and almost always by static type) macTruck. But NOT python. >> >> Nor Javascript, Ruby, Perl, PHP, Lua, or (I think) Lisp or Java. To >> mention only a few. >> >> I think it is easy to exaggerate the difference between Python and >> "almost every other language". Python's name binding model is very >> common amongst dynamically typed languages, and there are many >> dynamically typed languages. > > Then we don't need a discussion. > > Why are new Python coders 'always' confused by this question of > variable (name value) vs. {name: object} model of Python? "Always"? I don't think anyone, not even Ben, claims that new Python coders are "always" confused about Python's variable semantics. That would be a straw man, easy to disprove by just finding a single person who wasn't confused. Perhaps someone who had never learned C and didn't know C variable semantics? > The reason I suggest is that the person has a preconceived idea of > what 'variable' means, and they then attempt to apply their conception > of variable on to Python in some way ending in a surprise. That's the problem as some of us see it. > We need a way to speak about Pythons name object model to avoid > this confusion. And that would be the "name binding" part. -- Steven D'Aprano http://import-that.dreamwidth.org/ From eckhleung at gmail.com Fri May 9 21:22:43 2014 From: eckhleung at gmail.com (eckhleung at gmail.com) Date: Fri, 9 May 2014 18:22:43 -0700 (PDT) Subject: How to implement key of key in python? Message-ID: <1ba8744e-943b-4c71-abd7-9dea12db8780@googlegroups.com> I'm migrating from Perl to Python and unable to identify the equivalent of key of key concept. The following codes run well, import csv attr = {} with open('test.txt','rb') as tsvin: tsvin = csv.reader(tsvin, delimiter='\t') for row in tsvin: ID = row[1] until: attr[ID]['adm3'] = row[2] I then try: attr[ID].adm3 = row[2] still doesn't work. Some posts suggest using module dict but some do not. I'm a bit confused now. Any suggestions? From steve+comp.lang.python at pearwood.info Fri May 9 21:34:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 01:34:01 GMT Subject: The =?UTF-8?b?77+9?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 09 May 2014 13:10:41 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> Today we routinely call horseless carriages "cars", and nobody would >> blink if I pointed at a Prius or a Ford Explorer and said "that's not a >> carriage, it's a car" except to wonder why on earth I thought something >> so obvious needed to be said. > > That's only because the term "car" *is* well established. The situation > with the word "variable" is more like if you pointed at a Prius and said > "That's not a car, it's an electric vehicle". Most people would wonder > why you refused to categorise it as a type of car. And of there was an ongoing problem with people getting seriously confused by the differences between electric vehicles and internal combustion engine cars -- say, a steady stream of Prius owners filling the windshield washer reservoir with petrol (gasoline for Americans), or car mechanics accidentally blowing the batteries up -- then there might be a good reason to use a different name. In the absence of such confusion, why should we care? I don't object to Python using "print" to mean "display on the screen" instead of "make paper come out of the printer", because with the exception of the most naive beginners, there is no confusion caused by using that term. Nor am I terrible upset that "static method" means something very different in Java to Python, because that represents a fairly trivial misunderstanding about a single function rather than a fundamental misunderstanding about language semantics. > If you look at the way the word "variable" is used across a variety of > language communities, the common meaning is more or less "something that > can appear on the left hand side of an assignment statement". I really don't think so. some_function(x, y+1)[key].attribute[num](arg)[spam or eggs] = 42 I'm pretty sure that it isn't common to call the LHS of that assignment a variable. > Nobody seems to complain about using the term "assigment" in relation to > Python, despite it meaning something a bit different from what it means > in some other languages, so I don't see anything wrong with using the > term "variable" with the above definition. What differences in assignment are you referring to? In any case, the issue is whether or not the misunderstanding leads to confusion or not. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri May 9 21:58:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 10 May 2014 11:58:46 +1000 Subject: Values and objects In-Reply-To: <87zjiqbmy5.fsf@elektro.pacujo.net> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> Message-ID: On Sat, May 10, 2014 at 8:34 AM, Marko Rauhamaa wrote: > Right, Python's variables aren't like variables in C. Rather, Python's > variables are like CPU registers. They cannot hold typed or structured > objects and you can't pass references to them. Are you thinking that a Python variable is neither more nor less than what CPython implements them as? Because I can design you a 100% compliant Python implementation in which: * Objects are represented with pieces of paper * Object types are represented with 150GSM paper so it's easier to find (note that an object type, being itself an object, must be represented with paper) * Named attributes and numeric indices (__[gs]etitem__) are recorded with ink on the paper * References, including from an object to its type, are pieces of string linking an attribute to another object * None is, in the interests of performance, represented by a piece of string that dangles * Functions get compiled down to a byte-code stored on eighty-column punched card * Integers and strings are always interned * The image processing library is stored inside an actual pillowcase * The 'print' function results in a human being speaking, and 'input' waits for another human to speak, and constructs a string with what was said As far as I know, this could be done, and it would be perfectly compliant with all of Python. It'd be horrendously slow, but Python's specs never demand performance. It wouldn't have C-like variables, it wouldn't have pointers (assigning "a = b" means looking up b, finding which object the string connects to, gluing another string to that same object, and severing any previous connection from a), and it certainly wouldn't have 32-bit or 64-bit integers, or anything like that. (Not that CPython has anything of the sort, as of 3.0, but it's perfectly conceivable for a compliant Python to have an optimization whereby "small" integers are handled more efficiently. Again, the Python specs don't say either way.) So what is a "variable" in this Python? Well... exactly what it is in any other Python, because this is just as much Python as CPython, Jython, PyPy, or any other. ChrisA From harrismh777 at gmail.com Fri May 9 22:17:44 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 09 May 2014 21:17:44 -0500 Subject: Abstractions [was Re: Pass variable by reference] References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <536d79d1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/9/14 7:58 PM, Steven D'Aprano wrote: > {snip} at which > point we're now talking about a concrete, physical description of the > process, not an abstraction. There really is a bottom-most turtle that > holds up all the rest.) > hi Steven, heh... yup, there really is a bottom-most turtle (and who created him?) Intel (often copied, never exceeded) :)) From rustompmody at gmail.com Fri May 9 22:19:54 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 9 May 2014 19:19:54 -0700 (PDT) Subject: Values and objects In-Reply-To: <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> On Saturday, May 10, 2014 6:31:49 AM UTC+5:30, Steven D'Aprano wrote: > On Sat, 10 May 2014 01:34:58 +0300, Marko Rauhamaa wrote: > > > and you can't pass references to them. > > > That at least you have got right. > And that's Marko's main point > > > > Right, Python's variables aren't like variables in C. Rather, Python's > > variables are like CPU registers. They cannot hold typed or structured > > objects > > > Surely you cannot mean that? It is *trivially simple* to disprove that > statement: > > > py> x = [1, 2, 3] # A structured object > py> type(x) # that has a type > You missed the 'hold' For me, Marko's comment that variables in python are not first-class whereas in C they are is for me the most important distinction Ive seen (in a long time of seeing these discussions). In C a pointer is a 'pre-variable' in this sense: int i, *p; p = &i after this i and *p are completely interchangeable However p can also refer to -- (contain?hold?) depends on which side of this debate you are -- an element of an array or struct p = &some_array[some_index] p = &some_struct.some_field And all the way to anonymity with p = malloc(sizeof(*p)) This is what makes p a kind of meta-variable: - it can 'contain' other variables - it can contain variale-ish things like array elements - it can contain new variables on the fly via malloc These possibilities dont exist in python From dihedral88888 at gmail.com Fri May 9 22:21:34 2014 From: dihedral88888 at gmail.com (CHIN Dihedral) Date: Fri, 9 May 2014 19:21:34 -0700 (PDT) Subject: How to implement key of key in python? In-Reply-To: <1ba8744e-943b-4c71-abd7-9dea12db8780@googlegroups.com> References: <1ba8744e-943b-4c71-abd7-9dea12db8780@googlegroups.com> Message-ID: <4f659d7a-1175-4348-a097-41efc33d13c8@googlegroups.com> On Saturday, May 10, 2014 9:22:43 AM UTC+8, eckh... at gmail.com wrote: > I'm migrating from Perl to Python and unable to identify the equivalent of key of key concept. The following codes run well, > > > > import csv > > > > attr = {} > > > > with open('test.txt','rb') as tsvin: > > tsvin = csv.reader(tsvin, delimiter='\t') > > > > for row in tsvin: > > ID = row[1] > > > > > > until: > > attr[ID]['adm3'] = row[2] > > > > I then try: > > attr[ID].adm3 = row[2] > > > > still doesn't work. Some posts suggest using module dict but some do not. I'm a bit confused now. Any suggestions? Please check your attr as an empty dictionary or so-called a hash in perl. The syntax of adding a (K,V) pair is different between python and perl. From python at mrabarnett.plus.com Fri May 9 22:30:06 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 10 May 2014 03:30:06 +0100 Subject: How to implement key of key in python? In-Reply-To: <1ba8744e-943b-4c71-abd7-9dea12db8780@googlegroups.com> References: <1ba8744e-943b-4c71-abd7-9dea12db8780@googlegroups.com> Message-ID: <536D8F2E.2060804@mrabarnett.plus.com> On 2014-05-10 02:22, eckhleung at gmail.com wrote: > I'm migrating from Perl to Python and unable to identify the equivalent of key of key concept. The following codes run well, > > import csv > > attr = {} > > with open('test.txt','rb') as tsvin: > tsvin = csv.reader(tsvin, delimiter='\t') > > for row in tsvin: > ID = row[1] > > > until: > attr[ID]['adm3'] = row[2] > > I then try: > attr[ID].adm3 = row[2] > > still doesn't work. Some posts suggest using module dict but some do not. I'm a bit confused now. Any suggestions? > Python doesn't have Perl's autovivication feature. If you want the value to be a dict then you need to create that dict first: attr[ID] = {} attr[ID]['adm3'] = row[2] You could also have a look at the 'defaultdict' class in the 'collections' module. From rosuav at gmail.com Fri May 9 22:33:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 10 May 2014 12:33:28 +1000 Subject: Values and objects In-Reply-To: <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> Message-ID: On Sat, May 10, 2014 at 12:19 PM, Rustom Mody wrote: > For me, Marko's comment that variables in python are not first-class > whereas in C they are is for me the most important distinction Ive seen > (in a long time of seeing these discussions). > https://en.wikipedia.org/wiki/First-class_citizen For variables in C to be considered first-class, they must, by most definitions, be able to be passed around as parameters and return values. Some definitions also require that they be able to be constructed at run-time. How do C variables shape up? 1) Passing them as parameters. You can pass a pointer to a variable, which is effectively the same as passing a variable to a function. The callee can mutate your variable through the pointer. 2) Returning them. This is a lot more dodgy, owing to the dangling-pointer issue, but as long as you accept that the reference to a variable doesn't ensure its continued life, I suppose this might be acceptable. Maybe. But it's pushing it. 3) Constructing at run-time. Really REALLY pushing it. You can malloc and call that a "variable", but it's not a variable any more, it's just a patch of memory. In fact, all this proves is that variables represent patches of memory, and patches of memory are first-class. Not liking the results here. You might just as well define that all Python variables must be backed by a dictionary (it's just as true as "all C variables must be backed by memory") and then define the first-class-variable as a combination of a dict and a key. ChrisA From harrismh777 at gmail.com Fri May 9 22:34:41 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 09 May 2014 21:34:41 -0500 Subject: The =?UTF-8?B?77+9ICBkZWJhdGU=?= References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/9/14 8:34 PM, Steven D'Aprano wrote: >> Nobody seems to complain about using the term "assigment" in relation to >> Python, despite it meaning something a bit different from what it means >> in some other languages, so I don't see anything wrong with using the >> term "variable" with the above definition. > > What differences in assignment are you referring to? > > In any case, the issue is whether or not the misunderstanding leads to > confusion or not. > That's really the question --- regarding the issue of 'variable' and assignment. The term 'variable' (assignment) typically means: the LHS (name) of an assignment where the coder is placing some 'type' (RHS) into a chunk of memory statically defined, or dynamically malloc'd. With Python the assignment term 'variable' means: the LHS (name) is now associated with (bound to) an object (RHS), regardless whether the object already exists or whether the object is being constructed, nor what kind or type the object may be. The coder is not concerned with the memory model, nor address, nor reference. So for Python variable names are object handles. I've been reading through the python docs today (the FAQ mostly) and noting that python has variables BIG TIME as far as the docs go. marcus From rustompmody at gmail.com Fri May 9 23:05:13 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 9 May 2014 20:05:13 -0700 (PDT) Subject: Values and objects In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> Message-ID: <46d2a154-f534-4794-ada3-5954ad626ff3@googlegroups.com> On Saturday, May 10, 2014 8:03:28 AM UTC+5:30, Chris Angelico wrote: > > 2) Returning them. This is a lot more dodgy, owing to the > dangling-pointer issue, but as long as you accept that the reference > to a variable doesn't ensure its continued life, I suppose this might > be acceptable. Maybe. But it's pushing it. > > 3) Constructing at run-time. Really REALLY pushing it. You can malloc > and call that a "variable", but it's not a variable any more, it's > just a patch of memory. In fact, all this proves is that variables > represent patches of memory, and patches of memory are first-class. > Not sure what the 'just' is emphasizing/delimiting. Consider: int i; int *pi; char *pc; pi = &i; pc = pi; If your 'just' were just (excuse pun!) then *pi would be identical to *pc -- just the same patch of memory > > Not liking the results here. You might just as well define that all > Python variables must be backed by a dictionary (it's just as true as > "all C variables must be backed by memory") and then define the > first-class-variable as a combination of a dict and a key. Yes this is the rub. C pointers are first-class but half-assed due to dangling pointers -- (Function returning address of an automatic variale etc) Likewise python's name-spaces go almost all the way to first-classing variables but not quite as Marko discovered when locals() looks like a dict, waddles like a dict but does not quack like a dict. From eckhleung at gmail.com Fri May 9 23:28:29 2014 From: eckhleung at gmail.com (eckhleung at gmail.com) Date: Fri, 9 May 2014 20:28:29 -0700 (PDT) Subject: How to implement key of key in python? In-Reply-To: References: <1ba8744e-943b-4c71-abd7-9dea12db8780@googlegroups.com> Message-ID: <85c11614-b1a3-4021-b071-ffa1e0e5d3a7@googlegroups.com> On Saturday, May 10, 2014 10:30:06 AM UTC+8, MRAB wrote: > On 2014-05-10 02:22, I wrote: > > > I'm migrating from Perl to Python and unable to identify the equivalent of key of key concept. The following codes run well, > > > import csv > > > attr = {} > > > with open('test.txt','rb') as tsvin: > > > tsvin = csv.reader(tsvin, delimiter='\t') > > > for row in tsvin: > > > ID = row[1] > > > until: > > > attr[ID]['adm3'] = row[2] > > > I then try: > > > attr[ID].adm3 = row[2] > > > still doesn't work. Some posts suggest using module dict but some do not. I'm a bit confused now. Any suggestions? > > Python doesn't have Perl's autovivication feature. If you want the > > value to be a dict then you need to create that dict first: > > attr[ID] = {} > > attr[ID]['adm3'] = row[2] > > You could also have a look at the 'defaultdict' class in the > > 'collections' module. I identify the information below: s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)] d = defaultdict(list) for k, v in s: d[k].append(v) While it is fine for a small dataset, I need a more generic way to do so. Indeed the "test.txt" in my example contains more columns of attributes like: ID address age gender phone-number race education ... ABC123 Ohio, USA 18 F 800-123-456 european university ACC499 London 33 M 800-111-400 african university ... so later I can retrieve the information in python by: attr['ABC123'].address (containing 'Ohio, USA') attr['ABC123'].race (containing 'european') attr['ACC499'].age (containing '33') The following links mention something similar, http://courses.cs.washington.edu/courses/cse140/13wi/csv-parsing.html http://stackoverflow.com/questions/8800111/parse-csv-file-and-aggregate-the-values http://stackoverflow.com/questions/17763642/reading-tab-separated-file-into-a-defaultdict-python http://semanticbible.com/blogos/2009/06/12/reading-tab-delimited-data-in-python-with-csv/ unfortunately none of them illustrates how to store the values and access them later. Moreover, they bring some new terms, e.g. combined, [], etc. Is there any better reference? Thanks again! From harrismh777 at gmail.com Sat May 10 00:15:23 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 09 May 2014 23:15:23 -0500 Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <46d2a154-f534-4794-ada3-5954ad626ff3@googlegroups.com> Message-ID: On 5/9/14 10:05 PM, Rustom Mody wrote: > Likewise python's name-spaces go almost all the way to first-classing variables > but not quite as Marko discovered when locals() looks like a dict, waddles like > a dict but does not quack like a dict. > QOTWeekEnd From rustompmody at gmail.com Sat May 10 00:22:00 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 9 May 2014 21:22:00 -0700 (PDT) Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: References: Message-ID: <9a340516-5720-4341-8089-8bfab978287f@googlegroups.com> On Saturday, May 10, 2014 1:21:04 AM UTC+5:30, scott... at gmail.com wrote: > Hi, > > > > here is a snippet of code that opens a file (fn contains the path\name) and first tried to replace all endash, emdash etc characters with simple dash characters, before doing a search. > > But the replaces are not having any effect. Obviously a syntax problem....wwhat silly thing am I doing wrong? If you are using MS-Word use that, not python. Yeah it is possible to script MS with something like this http://timgolden.me.uk/pywin32-docs/ [no experience myself!] but its probably not worth the headache for such a simple job. The VBA (or whatever is the modern equivalent) will be about as short and simple as your attempted python and making it work will be far easier. I way I used to do it with Windows-98 Word. Start a macro Do a simple single search and replace by hand Close the macro Edit the macro (VBA version) Replace the single search-n-replace with all the many you require From greg.ewing at canterbury.ac.nz Sat May 10 01:58:56 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 10 May 2014 17:58:56 +1200 Subject: The =?UTF-8?B?77+9ICBkZWJhdGU=?= In-Reply-To: <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > some_function(x, y+1)[key].attribute[num](arg)[spam or eggs] = 42 > > I'm pretty sure that it isn't common to call the LHS of that assignment a > variable. A better way of putting it might be "something in the data model that can be assigned to". -- Greg From steve+comp.lang.python at pearwood.info Sat May 10 02:15:20 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 06:15:20 GMT Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> Message-ID: <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 May 2014 12:33:28 +1000, Chris Angelico wrote: > On Sat, May 10, 2014 at 12:19 PM, Rustom Mody > wrote: >> For me, Marko's comment that variables in python are not first-class >> whereas in C they are is for me the most important distinction Ive seen >> (in a long time of seeing these discussions). >> >> > https://en.wikipedia.org/wiki/First-class_citizen > > For variables in C to be considered first-class, they must, by most > definitions, be able to be passed around as parameters and return > values. Some definitions also require that they be able to be > constructed at run-time. How do C variables shape up? > > 1) Passing them as parameters. You can pass a pointer to a variable, > which is effectively the same as passing a variable to a function. No it is not. It is nothing like passing a variable to a function. You are passing a pointer, which is itself a value. True, it is a value which you, the author, gives meaning as a pointer to a variable, but that need not be the case. It might be a pointer to a part of an array, or a record, or to some random address in memory, or a dangling pointer. C allows you to perform arithmetic on pointers, which means you can construct pointers to nothing in particular. In C, pointers are first-class values, since you can: - construct pointers at runtime; - pass them to functions; - return them from functions; - assign them to variables; - stuff them in structs or arrays. But variables are not. You cannot create new variables, nor treat variables themselves as function arguments, or return them from functions. The closest you can do is *manually* use a pointer to a variable to simulate the same effect, but this is both too much and too little: - too much, because you aren't limited to passing pointers to a variable, you can pass pointers to anything you like, or nothing at all; - too little, because you are responsible for managing the pointers, instead of having the compiler do so. In Pascal, like C, you can't create new variables, or return them from functions, or embed them in records. But unlike C, you can pass them to functions, using a var parameter to use pass-by-reference. Algol is similar, except pass-by-name instead. I guess that makes Pascal variables second-and-a-half class values. Given: procedure foo(var inside: integer); begin {...} end; begin foo(outside); end. the global variable "outside" is passed to foo where it effectively becomes the local variable "inside". Notice that we don't manually have to concern ourselves with pointers, in fact whether Pascal uses pointers to implement this or not is entirely invisible to the coder using the feature. It could be using magic fairy dust for all we know. We simply write the most direct, natural code we possibly can: foo(outside); and the compiler does whatever magic is needed to ensure the variable outside, rather than the value of outside, is passed to the procedure foo. There is nothing like that in C. You can only manually simulate it by passing a pointer to a variable, not by passing the variable itself. To argue that C pointers are "pass by reference" is like arguing that C has a garbage collector, because you can write one yourself. > The > callee can mutate your variable through the pointer. 2) Returning them. > This is a lot more dodgy, owing to the dangling-pointer issue, but as > long as you accept that the reference to a variable doesn't ensure its > continued life, I suppose this might be acceptable. Maybe. But it's > pushing it. 3) Constructing at run-time. Really REALLY pushing it. You > can malloc and call that a "variable", but it's not a variable any more, > it's just a patch of memory. In fact, all this proves is that variables > represent patches of memory, and patches of memory are first-class. It proves that pointers are first class (well, duh!). The C compiler makes very little effort to ensure that pointers actually point to anything. Nor can you create patches of memory ("I'll like an extra couple of terrabytes please"), or return them from functions, or insert them in arrays. Rather than *creating* patches of memory, malloc merely allocates it from pre-existing memory. > Not liking the results here. You might just as well define that all > Python variables must be backed by a dictionary (it's just as true as > "all C variables must be backed by memory") and then define the > first-class-variable as a combination of a dict and a key. Python variables aren't first-class either, but in fact we can get a bit closer to first-class than either C or Pascal. Creating new variables is trivial. Since they don't need to be declared, you create a new variable just by assigning to it: try: spam except NameError: spam = 23 There are at least two other ways: globals()['spam'] = 23 exec('spam = 23') You can also delete variables: del spam Now this really shows first-class-ness. We don't have to give the name of the variable as a string, as in del("spam"), we just use the variable's name. But there's no way to pass variables to functions, embed them in lists, etc. The closest we can do is pass a string, the name of the variable, and a namespace: foo('spam', namespace) To be truly first class, we ought to be able to write something like this: x = 23 alist = [1, 2, x] alist[2] = 42 assert x == 42 but we cannot. -- Steven D'Aprano http://import-that.dreamwidth.org/ From anddamNOALPASTICCIODICARNE+gruppi at brapi.net Sat May 10 03:07:10 2014 From: anddamNOALPASTICCIODICARNE+gruppi at brapi.net (Andrea D'Amore) Date: Sat, 10 May 2014 09:07:10 +0200 Subject: How to implement key of key in python? References: <1ba8744e-943b-4c71-abd7-9dea12db8780@googlegroups.com> <85c11614-b1a3-4021-b071-ffa1e0e5d3a7@googlegroups.com> Message-ID: On 2014-05-10 03:28:29 +0000, eckhleung at gmail.com said: > While it is fine for a small dataset, I need a more generic way to do so. I don't get how the dataset size affects the generality of the solution here. >From your first message: > attr = {} > with open('test.txt','rb') as tsvin: > tsvin = csv.reader(tsvin, delimiter='\t') > for row in tsvin: > ID = row[1] so your is solved by adding a simple attr[ID] = {} after the ID assignment. It seems simple to implement and generic enough to me. > unfortunately none of them illustrates how to store the values and > access them later. You access the stored value by using the variable name that holds it, but here you should probabily make more clear what your actual issue is. > Moreover, they bring some new terms, e.g. combined, [], etc. The "[]" syntax is used in Python for lists. The term "combined" hasn't a specific pythonic meaning there and is just used as a meaningful variable name as the author is combining, i.e. adding, numerical values. -- Andrea From rosuav at gmail.com Sat May 10 03:10:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 10 May 2014 17:10:29 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDvv70gZGViYXRl?= In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 10, 2014 at 3:58 PM, Gregory Ewing wrote: > Steven D'Aprano wrote: >> >> some_function(x, y+1)[key].attribute[num](arg)[spam or eggs] = 42 >> >> I'm pretty sure that it isn't common to call the LHS of that assignment a >> variable. > > > A better way of putting it might be "something in the data > model that can be assigned to". https://en.wikipedia.org/wiki/Assignment_(computer_science) Go ahead, start an edit war at that page over its use of "variable". :) Right there it talks about copying values into variables. So if Python has no variables, then either that article is inappropriate, or Python has no assignment either. ChrisA From wxjmfauth at gmail.com Sat May 10 03:11:22 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 10 May 2014 00:11:22 -0700 (PDT) Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: <9a340516-5720-4341-8089-8bfab978287f@googlegroups.com> References: <9a340516-5720-4341-8089-8bfab978287f@googlegroups.com> Message-ID: Le samedi 10 mai 2014 06:22:00 UTC+2, Rustom Mody a ?crit?: > On Saturday, May 10, 2014 1:21:04 AM UTC+5:30, scott... at gmail.com wrote: > > > Hi, > > > > > > > > > > > > here is a snippet of code that opens a file (fn contains the path\name) and first tried to replace all endash, emdash etc characters with simple dash characters, before doing a search. > > > > > > But the replaces are not having any effect. Obviously a syntax problem....wwhat silly thing am I doing wrong? > > > > If you are using MS-Word use that, not python. > > > > Yeah it is possible to script MS with something like this > > http://timgolden.me.uk/pywin32-docs/ > > [no experience myself!] > > but its probably not worth the headache for such a simple job. > > > > The VBA (or whatever is the modern equivalent) will be about as short and simple > > as your attempted python and making it work will be far easier. > > > > I way I used to do it with Windows-98 Word. > > Start a macro > > Do a simple single search and replace by hand > > Close the macro > > Edit the macro (VBA version) > > Replace the single search-n-replace with all the many you require ========= That's a wise reommendation. Anyway, as Python may fail as soon as one uses an EM DASH or an EM DASH, I think it's not worth the effort to spend to much time with it. LibreOffice could be a solution. jmf From rosuav at gmail.com Sat May 10 03:21:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 10 May 2014 17:21:56 +1000 Subject: Values and objects In-Reply-To: <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 10, 2014 at 4:15 PM, Steven D'Aprano wrote: > On Sat, 10 May 2014 12:33:28 +1000, Chris Angelico wrote: >> 1) Passing them as parameters. You can pass a pointer to a variable, >> which is effectively the same as passing a variable to a function. > > No it is not. It is nothing like passing a variable to a function. You > are passing a pointer, which is itself a value. True, it is a value which > you, the author, gives meaning as a pointer to a variable, but that need > not be the case. It might be a pointer to a part of an array, or a > record, or to some random address in memory, or a dangling pointer. C > allows you to perform arithmetic on pointers, which means you can > construct pointers to nothing in particular. I think at this point it's arguable, in that you can get so close to "passing a variable to a function" that it doesn't really matter about the distinction. But as I explained further down, it really just shows that "patch of memory" can be passed around, and that a variable can be backed by such a patch of memory. > Rather than *creating* patches of memory, malloc merely allocates it from > pre-existing memory. I disagree. On a modern system with memory management, malloc can grab memory from the system, thus making it available to your process. Sure, physical memory will normally have to have been installed in the system, but conceptually you could have a malloc function that actually freezes the program, asks the user to build a new computer and turn it on, connects to a new service on that computer, and allocates memory from there. As far as your program's concerned, malloc actually does (attempt to) give you more room than you had. > Python variables aren't first-class either, but in fact we can get a bit > closer to first-class than either C or Pascal. > > Creating new variables is trivial. Since they don't need to be declared, > you create a new variable just by assigning to it: > > try: > spam > except NameError: > spam = 23 No no no, this is really creating them at compile time. If you do this inside a function, the name has to be created as a local name before the function begins execution. > There are at least two other ways: > > globals()['spam'] = 23 > exec('spam = 23') With exec, you can do anything "at run time". Does that mean that, in languages with an exec action, absolutely everything is first-class? I'm not sure that that counts. Maybe I'm wrong. Subscript-assigning to globals() is actually creating new (module-level) variables, though. And if Python allowed you to assign to locals() inside a function, then I would accept that local function variables can be created and destroyed at run time, but you can't, so local variables aren't first-class. ChrisA From orgnut at yahoo.com Sat May 10 03:46:45 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Sat, 10 May 2014 00:46:45 -0700 Subject: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= In-Reply-To: <536d7cdf$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <536add6b$0$29965$c3e8da3$5496439d@news.astraweb.com> <536D57E9.5080801@gmail.com> <536d7cdf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/09/2014 06:11 PM, Steven D'Aprano wrote: > On Fri, 09 May 2014 17:34:17 -0500, Mark H Harris wrote: > >> On 5/7/14 8:27 PM, Steven D'Aprano wrote: >> Why are new Python coders 'always' confused by this question of >> variable (name value) vs. {name: object} model of Python? > > "Always"? I don't think anyone, not even Ben, claims that new Python > coders are "always" confused about Python's variable semantics. That > would be a straw man, easy to disprove by just finding a single person > who wasn't confused. Perhaps someone who had never learned C and didn't > know C variable semantics? > Well, here is that one person. ;-) I'm an entirely self-taught amateur/hobbyist programmer, coming to Python from a C background. Very early in my reading of books/tutorials on Python I learned that Python variables are different, and how they are different from C variables. Essentially I said, "Okay, they're different. What's next?" There was no confusion at all. All I had to do was accept that they _are_ different. (BTW, I'm now quite hooked on Python -- and still learning it.) >> The reason I suggest is that the person has a preconceived idea of >> what 'variable' means, and they then attempt to apply their conception >> of variable on to Python in some way ending in a surprise. > > That's the problem as some of us see it. > As I said above, not a problem. I already accepted the fact that all programming languages are different -- often with similarities, but more often quite different, especially in the details. So when programming in C I think in C-style variables, in Python I think in Python-style variables. And uv course, I nefer make mmistakes... Yeah, right! ;-) > >> We need a way to speak about Pythons name object model to avoid >> this confusion. > > And that would be the "name binding" part. > This is something I absolutely disagree with. I still think it's only necessary to teach that variables in different languages are handled differently. Insisting on a different name is NOT helpful. And insisting that Python does not have variables is ludicrous! -=- Larry -=- From steve+comp.lang.python at pearwood.info Sat May 10 03:48:27 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 07:48:27 GMT Subject: The =?UTF-8?b?77+9?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536dd9cb$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 May 2014 17:10:29 +1000, Chris Angelico wrote: > On Sat, May 10, 2014 at 3:58 PM, Gregory Ewing > wrote: >> Steven D'Aprano wrote: >>> >>> some_function(x, y+1)[key].attribute[num](arg)[spam or eggs] = 42 >>> >>> I'm pretty sure that it isn't common to call the LHS of that >>> assignment a variable. >> >> >> A better way of putting it might be "something in the data model that >> can be assigned to". > > https://en.wikipedia.org/wiki/Assignment_(computer_science) > > Go ahead, start an edit war at that page over its use of "variable". :) > Right there it talks about copying values into variables. So if Python > has no variables, then either that article is inappropriate, or Python > has no assignment either. Python assignment doesn't copy values. -- Steven D'Aprano http://import-that.dreamwidth.org/ From marko at pacujo.net Sat May 10 03:57:21 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 10 May 2014 10:57:21 +0300 Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> Message-ID: <874n0yt6am.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, May 10, 2014 at 8:34 AM, Marko Rauhamaa wrote: >> Right, Python's variables aren't like variables in C. Rather, >> Python's variables are like CPU registers. They cannot hold typed or >> structured objects and you can't pass references to them. > > Are you thinking that a Python variable is neither more nor less than > what CPython implements them as? I was just being more Catholic than the Pope. To me, a variable is a variable is a variable. Marko From edd.cowan at gmail.com Sat May 10 04:02:06 2014 From: edd.cowan at gmail.com (edd.cowan at gmail.com) Date: Sat, 10 May 2014 01:02:06 -0700 (PDT) Subject: dynamic form application Message-ID: <7636aca3-3e37-49ed-a31a-ac27c6da8a36@googlegroups.com> hello guys. i tryng to create a form builder application with a database backend. like wufoo.com im stuck,how do i use jquery to create dynamic forms,and how is the database designed for the actual forms and the data gathered using those forms i'd like to use rdbms preferebly postgres. regards eddy From rosuav at gmail.com Sat May 10 04:01:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 10 May 2014 18:01:32 +1000 Subject: =?UTF-8?B?UmU6IFRoZSDvv70gZGViYXRl?= In-Reply-To: <536dd9cb$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> <536dd9cb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 10, 2014 at 5:48 PM, Steven D'Aprano wrote: >> https://en.wikipedia.org/wiki/Assignment_(computer_science) >> >> Go ahead, start an edit war at that page over its use of "variable". :) >> Right there it talks about copying values into variables. So if Python >> has no variables, then either that article is inappropriate, or Python >> has no assignment either. > > Python assignment doesn't copy values. So either the article is wrong, or Python doesn't have assignment. Which is it? ChrisA From jpiitula at ling.helsinki.fi Sat May 10 04:06:36 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 10 May 2014 11:06:36 +0300 Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <874n0yt6am.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > To me, a variable is a variable is a variable. That works only in Python. Elsewhere, the sentence would be interpreted either as "a variable is True" or as "a variable is False" depending on whether a distinction without a difference is deemed helpful. From marko at pacujo.net Sat May 10 04:18:59 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 10 May 2014 11:18:59 +0300 Subject: The =?utf-8?Q?=EF=BF=BD?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zjiqrqq4.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, May 10, 2014 at 3:58 PM, Gregory Ewing > wrote: >> Steven D'Aprano wrote: >>> >>> some_function(x, y+1)[key].attribute[num](arg)[spam or eggs] = 42 >>> >>> I'm pretty sure that it isn't common to call the LHS of that assignment a >>> variable. > > [...] > https://en.wikipedia.org/wiki/Assignment_(computer_science) > > [...] > > So if Python has no variables, then either that article is > inappropriate, or Python has no assignment either. Many complaints against Python's variables are really comments on Python's object model. Steven's example points out a different angle: many complaints against Python's variables are really comments on Python's assignment statement (including argument passing). In Python, x is a variable, a memory slot that can be assigned to, a[3] is a list element, a memory slot that can be assigned to, d['y'] is a dict entry, a memory slot that can be assigned to, o.f is a field, a memory slot that can be assigned to Now, Python (together with a host of other programming languages) lacks a way to pass memory slots by reference (although the list/dict+key comes close). However, the fact that you can't get a reference to a variable/list element/dict entry/field doesn't mean Python doesn't have variables/list elements/dict entries/fields. Marko PS I have mentioned before that Python 3 *does* allow you to pass a reference to any LHS by constructing an ad-hoc accessor object: x, y = 2, 3 class X: def get(self): return x def set(self, v): nonlocal x; x = v class Y: def get(self): return y def set(self, v): nonlocal y; y = v swap(X(), Y()) print(x, y) => 3, 2 Such ad-hoc accessor classes are required for nonglobal variables only. Generic accessor classes can be written for global variables, list elements, dict entries and fields. From __peter__ at web.de Sat May 10 04:21:54 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 10 May 2014 10:21:54 +0200 Subject: How to implement key of key in python? References: <1ba8744e-943b-4c71-abd7-9dea12db8780@googlegroups.com> <85c11614-b1a3-4021-b071-ffa1e0e5d3a7@googlegroups.com> Message-ID: eckhleung at gmail.com wrote: > On Saturday, May 10, 2014 10:30:06 AM UTC+8, MRAB wrote: >> On 2014-05-10 02:22, I wrote: >> >> > I'm migrating from Perl to Python and unable to identify the equivalent >> > of key of key concept. The following codes run well, >> >> > import csv >> >> > attr = {} >> >> > with open('test.txt','rb') as tsvin: >> >> > tsvin = csv.reader(tsvin, delimiter='\t') >> >> > for row in tsvin: >> >> > ID = row[1] >> >> > until: >> >> > attr[ID]['adm3'] = row[2] >> >> > I then try: >> >> > attr[ID].adm3 = row[2] >> >> > still doesn't work. Some posts suggest using module dict but some do >> > not. I'm a bit confused now. Any suggestions? >> >> Python doesn't have Perl's autovivication feature. If you want the >> >> value to be a dict then you need to create that dict first: >> >> attr[ID] = {} >> >> attr[ID]['adm3'] = row[2] >> >> You could also have a look at the 'defaultdict' class in the >> >> 'collections' module. > > I identify the information below: > s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)] > d = defaultdict(list) > for k, v in s: > d[k].append(v) > > While it is fine for a small dataset, I need a more generic way to do so. > Indeed the "test.txt" in my example contains more columns of attributes > like: > > ID address age gender phone-number race education ... > ABC123 Ohio, USA 18 F 800-123-456 european university > ACC499 London 33 M 800-111-400 african university > ... > > so later I can retrieve the information in python by: > > attr['ABC123'].address (containing 'Ohio, USA') > attr['ABC123'].race (containing 'european') > attr['ACC499'].age (containing '33') Using a csv.DictReader comes close with minimal effort: # write demo data to make the example self-contained with open("tmp.csv", "w") as f: f.write("""\ ID,address,age,gender,phone-number,race,education ABC123,"Ohio, USA",18,F,800-123-456,european,university ACC499,London,33,M,800-111-400,african,university """) import csv import pprint with open("tmp.csv") as f: attr = {row["ID"]: row for row in csv.DictReader(f)} pprint.pprint(attr) print(attr["ACC499"]["age"]) The "dict comprehension" attr = {row["ID"]: row for row in csv.DictReader(f)} is a shortcut for attr = {} for row in csv.DictReader(f): attr[row["ID"]] = row If you insist on attribute access (row.age instead of row["age"]) you can use a namedtuple. This is a bit more involved: import csv import pprint from collections import namedtuple with open("tmp.csv") as f: rows = csv.reader(f) header = next(rows) # make sure column names are valid Python identifiers header = [column.replace("-", "_") for column in header] RowType = namedtuple("RowType", header) key_index = header.index("ID") attr = {row[key_index]: RowType(*row) for row in rows} pprint.pprint(attr) print(attr["ABC123"].race) > The following links mention something similar, Too many, so I checked none of them ;) From marko at pacujo.net Sat May 10 04:21:54 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 10 May 2014 11:21:54 +0300 Subject: The =?utf-8?Q?=EF=BF=BD?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> <536dd9cb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vbterql9.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, May 10, 2014 at 5:48 PM, Steven D'Aprano > wrote: >>> https://en.wikipedia.org/wiki/Assignment_(computer_science) >>> >>> Go ahead, start an edit war at that page over its use of "variable". :) >>> Right there it talks about copying values into variables. So if Python >>> has no variables, then either that article is inappropriate, or Python >>> has no assignment either. >> >> Python assignment doesn't copy values. > > So either the article is wrong, or Python doesn't have assignment. > Which is it? You can understand copying more liberally: assignment -- 0-level copy shallow copy -- 1-level copy deep copy -- infinite-level copy Real programs occasionally need 2-level or n-level copies. Marko From mail at timgolden.me.uk Sat May 10 04:49:31 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 10 May 2014 09:49:31 +0100 Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: References: <9a340516-5720-4341-8089-8bfab978287f@googlegroups.com> Message-ID: <536DE81B.9040002@timgolden.me.uk> On 10/05/2014 08:11, wxjmfauth at gmail.com wrote: > Anyway, as Python may fail as soon as one uses an > EM DASH or an EM DASH, I think it's not worth the > effort to spend to much time with it. Nope -- seems all right to me. (Hopefully helping the OP out as well as rebutting a rather foolish assertion). #!python3.4 import win32com.client import unicodedata word = win32com.client.gencache.EnsureDispatch("Word.Application") try: doc1 = word.Documents.Add() doc1.Range().Text += "Hello \u2014 World" doc1.SaveAs(r"c:\temp\em_dash.docx") doc1.Close() doc2 = win32com.client.GetObject(r"c:\temp\em_dash.docx") for uchar in doc2.Range().Text.strip(): print(unicodedata.name(uchar)) finally: word.Quit() TJG From rustompmody at gmail.com Sat May 10 05:05:06 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 10 May 2014 02:05:06 -0700 (PDT) Subject: =?UTF-8?B?UmU6IFRoZSDvv70gZGViYXRl?= In-Reply-To: <536dd9cb$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> <536dd9cb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <717336ca-387c-4ca4-ba56-7d0f9f083036@googlegroups.com> On Saturday, May 10, 2014 1:18:27 PM UTC+5:30, Steven D'Aprano wrote: > Python assignment doesn't copy values. Maybe our values differ ? From steve+comp.lang.python at pearwood.info Sat May 10 05:09:31 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 09:09:31 GMT Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 May 2014 17:21:56 +1000, Chris Angelico wrote: > On Sat, May 10, 2014 at 4:15 PM, Steven D'Aprano > wrote: >> On Sat, 10 May 2014 12:33:28 +1000, Chris Angelico wrote: >>> 1) Passing them as parameters. You can pass a pointer to a variable, >>> which is effectively the same as passing a variable to a function. >> >> No it is not. It is nothing like passing a variable to a function. You >> are passing a pointer, which is itself a value. True, it is a value >> which you, the author, gives meaning as a pointer to a variable, but >> that need not be the case. It might be a pointer to a part of an array, >> or a record, or to some random address in memory, or a dangling >> pointer. C allows you to perform arithmetic on pointers, which means >> you can construct pointers to nothing in particular. > > I think at this point it's arguable, in that you can get so close to > "passing a variable to a function" that it doesn't really matter about > the distinction. But as I explained further down, it really just shows > that "patch of memory" can be passed around, and that a variable can be > backed by such a patch of memory. No offence Chris, but I think this demonstrates that learning C causes brain damage and prevents clear logical thinking :-P You're not passing a variable to a function. You're passing a pointer, which is itself a first-class value. It could be a pointer to ANYTHING, or NOTHING at all -- C doesn't even promise to ensure that it is a valid pointer, although more modern languages may. There's certainly no guarantee that it's a pointer to a variable. And you cannot create new variables -- C only allows variables to be created at compile time. The question is not, "Can I implement some aspects of first-class behaviour for variables by hand?" The question is, "Are variables treated as first class values in C?" If you asked, "Does Pascal have an exponentiation or power operator?", and I answered "Sure it does! If you want to calculate x squared, you just write x*x, if you want x cubed, write x*x*x, and if you want x to the power of twelve, x*x*x*x*x*x*x*x*x*x*x*x" you would rightfully slap me with a halibut. Being able to manually perform repeated multiplication is not the same as having the language support exponentiation. To say nothing of fractional exponents. "How about x to the power of one third?" Being able to manually pass pointers to variables about is not the same as having first class variables. It fails on the very first hurdle, "Are variables treated the same as other values?" How do I pass an int to a function? func(some_int) How do I pass a double to a function? func(some_double) How do I pass a bool to a function? func(some_bool) How do I pass a variable to a function? ptr = &some_variable; func(ptr) Does that look the same to you? The fact that you can do it at all is not sufficient to make it first class. It just makes it a work-around for the lack of first class variables in the language. Personally, I don't imagine that there ever could be a language where variables were first class values *exactly* the same as ints, strings, floats etc. Otherwise, how could you tell the difference between a function which operated on the variable itself, and one which operated on the value contained by the value? The best you can do is for variables to be "second class" -- you can do these things to them, but you need special syntax or declarations to tell the compiler you're operating on the variable rather than the variable's value. E.g. Pascal and Algol have syntax for instructing the compiler when to pass a variable as a value, and when to pass the value. C gives you nothing. I would say that C variables are *third class*. There's no compiler support for variables-as-values at all, but you can manually fake it a bit by using pointers. There is no way to tell whether the pointer actually points to a variable, and since arrays aren't first class neither are pointer-to-arrays. Algol and Pascal are *second class*, since the compiler does allow you to pass variables as arguments (var parameters in Pascal, I forget what they are called in Algol). Likewise, Python let's you create new variables at runtime, or delete them, but you can't pass them around. But still, you're quite limited in what the language does for you, compared to what you have to do yourself: x = 23 function("x", globals()) # See, I can pass a variable! Not. >> Rather than *creating* patches of memory, malloc merely allocates it >> from pre-existing memory. > > I disagree. On a modern system with memory management, malloc can grab > memory from the system, thus making it available to your process. Sure, > physical memory will normally have to have been installed in the system, > but conceptually you could have a malloc function that actually freezes > the program, asks the user to build a new computer and turn it on, > connects to a new service on that computer, and allocates memory from > there. As far as your program's concerned, malloc actually does (attempt > to) give you more room than you had. Ha, well I guess you got me there. Perhaps a less over the top example is that you're running in a VM, and malloc can request more information from the host (which presumably has unlimited memory). Still impractical, but theoretically possible. Nevertheless, blocks of memory are not *first class* because you don't handle blocks of memory like other values. To make a new int variable, you declare it: "int foo". To make a new block of memory, there is no declaration "block foo". Rather, you call malloc() at runtime. And it might fail. "int foo" can never fail. >> Python variables aren't first-class either, but in fact we can get a >> bit closer to first-class than either C or Pascal. >> >> Creating new variables is trivial. Since they don't need to be >> declared, you create a new variable just by assigning to it: >> >> try: >> spam >> except NameError: >> spam = 23 > > No no no, this is really creating them at compile time. It certainly isn't. Here's a slightly different demonstration of the same principle, this time inside a function to prove that there's nothing special about the global namespace: py> def demo(): ... print('spam' in locals()) ... spam = 23 ... print('spam' in locals()) ... py> demo() False True > If you do this > inside a function, the name has to be created as a local name before the > function begins execution. An implementation detail. CPython -- but not necessarily other Pythons -- use pre-allocated slots for local variables, but tries to hide this fact from you (it *almost* succeeds too). But those pre-allocated slots can represent unbound variables, i.e. variables which from the perspective of Python code don't exist: py> def demo2(): ... spam = 23 ... print('spam' in locals()) ... del spam ... print('spam' in locals()) ... py> demo2() True False If you peer under the hood of the CPython implementation, the slot still exists, but that's invisible from Python, and just an implementation detail. Other implementations may not even have slots at all. >> There are at least two other ways: >> >> globals()['spam'] = 23 >> exec('spam = 23') > > With exec, you can do anything "at run time". Does that mean that, in > languages with an exec action, absolutely everything is first-class? I'm > not sure that that counts. Maybe I'm wrong. No, you're right. That's why I said "Python variables aren't first-class either". But they're less second class than C or Pascal. > Subscript-assigning to globals() is actually creating new (module-level) > variables, though. And if Python allowed you to assign to locals() > inside a function, then I would accept that local function variables can > be created and destroyed at run time, but you can't, so local variables > aren't first-class. See above. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sat May 10 05:32:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 10 May 2014 19:32:03 +1000 Subject: Values and objects In-Reply-To: <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 10, 2014 at 7:09 PM, Steven D'Aprano wrote: > On Sat, 10 May 2014 17:21:56 +1000, Chris Angelico wrote: > > No offence Chris, but I think this demonstrates that learning C causes > brain damage and prevents clear logical thinking :-P > > You're not passing a variable to a function. You're passing a pointer, > which is itself a first-class value. It could be a pointer to ANYTHING, > or NOTHING at all -- C doesn't even promise to ensure that it is a valid > pointer, although more modern languages may. There's certainly no > guarantee that it's a pointer to a variable. And you cannot create new > variables -- C only allows variables to be created at compile time. > > The question is not, "Can I implement some aspects of first-class > behaviour for variables by hand?" The question is, "Are variables treated > as first class values in C?" Ehh... good point. I admit my brain damage - which, I have to say, has earned me a good portion of my life's salaries, so it's not useless :) Okay. So variables are not first-class in C. I still think memory blocks are pretty much first class, though; you can declare them at compile time (usually as an array of char or pointers) or at run time (with malloc or equivalent), and they can be passed to functions, returned from functions, etc. The only limitation is that a generic memory block doesn't maintain its size, so you can't distinguish between a char[10] and a char[1024]. > Being able to manually pass pointers to variables about is not the same > as having first class variables. It fails on the very first hurdle, "Are > variables treated the same as other values?" > > How do I pass an int to a function? func(some_int) > > How do I pass a double to a function? func(some_double) > > How do I pass a bool to a function? func(some_bool) > > How do I pass a variable to a function? ptr = &some_variable; func(ptr) > > Does that look the same to you? The fact that you can do it at all is not > sufficient to make it first class. It just makes it a work-around for the > lack of first class variables in the language. You can simply say func(&some_variable), but yes, there is that difference. (This is how "out" parameters usually look in C. You stick ampersands in front of things.) And that's still passing memory blocks around, not variables. >>> Rather than *creating* patches of memory, malloc merely allocates it >>> from pre-existing memory. >> >> I disagree. On a modern system with memory management, malloc can grab >> memory from the system, thus making it available to your process. Sure, >> physical memory will normally have to have been installed in the system, >> but conceptually you could have a malloc function that actually freezes >> the program, asks the user to build a new computer and turn it on, >> connects to a new service on that computer, and allocates memory from >> there. As far as your program's concerned, malloc actually does (attempt >> to) give you more room than you had. > > Ha, well I guess you got me there. Perhaps a less over the top example is > that you're running in a VM, and malloc can request more information from > the host (which presumably has unlimited memory). Still impractical, but > theoretically possible. Yeah. Completely impractical, but so is "Post-It Note Python" where everything's done with physical strings and sheets of paper. Thought experiments don't have to be performant :) > Nevertheless, blocks of memory are not *first class* because you don't > handle blocks of memory like other values. To make a new int variable, > you declare it: "int foo". To make a new block of memory, there is no > declaration "block foo". Rather, you call malloc() at runtime. And it > might fail. "int foo" can never fail. As I mentioned above, you can make a new block of memory with "char foo[1234]". And that's where a lot of buffer overruns come from, because someone thinks "1234 is *heaps* of space"... but sometimes you really can know in advance how long something can be. (Maybe you're about to ask a file to give you the next 1233 bytes of content.) In this form, it's as safe as "int foo" - that is to say, safe unless your stack overflows, in which case all bets are off anyway. >>> Python variables aren't first-class either, but in fact we can get a >>> bit closer to first-class than either C or Pascal. >>> >>> Creating new variables is trivial. Since they don't need to be >>> declared, you create a new variable just by assigning to it: >>> >>> try: >>> spam >>> except NameError: >>> spam = 23 >> >> No no no, this is really creating them at compile time. > > It certainly isn't. Here's a slightly different demonstration of the same > principle, this time inside a function to prove that there's nothing > special about the global namespace: > > > py> def demo(): > ... print('spam' in locals()) > ... spam = 23 > ... print('spam' in locals()) > ... > py> demo() > False > True Tell me, what may this function do in a compliant Python? def demo(): ret = spam spam = 23 return ret In CPython, that'll raise UnboundLocalError, because the local variable 'spam' does already exist, and currently has no value (no object bound to it). If a compliant Python implementation is allowed to have this return the value of a global or builtin spam, then I would agree that you can create variables at run time. Is demo.__code__.co_varnames a CPython implementation detail or part of the language spec? Ultimately, a variable name must be looked up somehow. If you can create and destroy them inside an inner scope that shadows an outer scope, then you should be able to shadow and unshadow them. Is there a way to do this with exec? I tried this and it failed: def demo(): print("spam =",spam) exec("spam = 23") print("spam =",spam) exec("del spam") print("spam =",spam) CPython 3.4, each lookup of spam becomes a LOAD_GLOBAL, so each print outputs the global value of spam. Is there a way to fiddle with this? ChrisA From steve+comp.lang.python at pearwood.info Sat May 10 05:31:48 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 09:31:48 GMT Subject: The =?UTF-8?b?77+9?= debate References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> <87zjiqrqq4.fsf@elektro.pacujo.net> Message-ID: <536df204$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 May 2014 11:18:59 +0300, Marko Rauhamaa wrote: > In Python, > > x is a variable, a memory slot that can be assigned to, If your intention was to prove Ben Finney right, then you've done a masterful job of it. Python variables ARE NOT MEMORY SLOTS. (Not even local variables, since that's an implementation detail which the language takes pains to hide from the caller. The abstraction leaks a bit, but not much.) -- Steven D'Aprano http://import-that.dreamwidth.org/ From flebber.crue at gmail.com Sat May 10 07:17:33 2014 From: flebber.crue at gmail.com (flebber) Date: Sat, 10 May 2014 04:17:33 -0700 (PDT) Subject: xmltodict - TypeError: list indices must be integers, not str Message-ID: I am using xmltodict. This is how I have accessed and loaded my file. import xmltodict document = open("/home/sayth/Scripts/va_benefits/20140508GOSF0.xml", "r") read_doc = document.read() xml_doc = xmltodict.parse(read_doc) The start of the file I am trying to get data out of is. So thought I had it figured. Can access the elements of meeting and the elements of club such as by doing this. In [5]: xml_doc['meeting']['club']['@abbrevname'] Out[5]: u'Gosford Race Club' However whenever I try and access race in the same manner I get errors. In [11]: xml_doc['meeting']['club']['race']['@id'] --------------------------------------------------------------------------- KeyError Traceback (most recent call last) in () ----> 1 xml_doc['meeting']['club']['race']['@id'] KeyError: 'race' In [12]: xml_doc['meeting']['race']['@id'] --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () ----> 1 xml_doc['meeting']['race']['@id'] TypeError: list indices must be integers, not str why is accessing race @id any different to the access of club @abbrevname and how do I get it for race? Thanks Sayth From preethidasa at gmail.com Sat May 10 07:39:05 2014 From: preethidasa at gmail.com (Preethi) Date: Sat, 10 May 2014 04:39:05 -0700 (PDT) Subject: Error while calling round() from future.builtins Message-ID: <591c2939-7648-47f5-854e-ad254a8a732f@googlegroups.com> Hi, I am new to python. I am getting an error "AttributeError: type object 'Decimal' has no attribute 'from_float'" when I run the following in python prompt: >>> from future.builtins import int, round >>> int(round(5)) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/site-packages/future/builtins/backports/newround.py", line 32, in newround d = Decimal.from_float(number).quantize(exponent, AttributeError: type object 'Decimal' has no attribute 'from_float' I am running this on Centos 6.5 which has python version 2.6.6 This is the output of 'pip freeze': Django==1.6.4 Mezzanine==3.1.4 Pillow==2.4.0 South==0.8.4 bleach==1.4 django-appconf==0.6 django-compressor==1.3 filebrowser-safe==0.3.3 future==0.9.0 grappelli-safe==0.3.10 html5lib==0.999 iniparse==0.3.1 oauthlib==0.6.1 psycopg2==2.5.2 pycurl==7.19.0 pygpgme==0.1 pytz==2014.2 requests==2.2.1 requests-oauthlib==0.4.0 six==1.6.1 tzlocal==1.0 urlgrabber==3.9.1 yum-metadata-parser==1.1.2 This is the order in which I installed the above packages. (The box initially had python 2.6.6 installed) yum install gcc python python-setuptools python-devel yum install libjpeg-turbo-devel python get-pip.py pip install -U pip pip install South django-compressor pip install mezzanine yum install postgresql93-server.x86_64 yum install postgresql-devel sudo pip install psycopg2 What am I missing? Any help is greatly appreciated. Thanks, Preethi From steve+comp.lang.python at pearwood.info Sat May 10 07:56:56 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2014 11:56:56 GMT Subject: Error while calling round() from future.builtins References: <591c2939-7648-47f5-854e-ad254a8a732f@googlegroups.com> Message-ID: <536e1408$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 May 2014 04:39:05 -0700, Preethi wrote: > Hi, > > I am new to python. I am getting an error "AttributeError: type object > 'Decimal' has no attribute 'from_float'" when I run the following in > python prompt: > >>>> from future.builtins import int, round I get an error when I try that: py> from future.builtins import int, round Traceback (most recent call last): File "", line 1, in ImportError: No module named future.builtins Perhaps you are using the third-party library "future"? https://pypi.python.org/pypi/future If so, then I believe the library is buggy and you should report it to the Centos package maintainer. You might also manually install a more recent version of future. Decimal.from_float was only added in 2.7, it is not available in 2.6. https://docs.python.org/2/library/decimal.html#decimal.Decimal.from_float -- Steven D'Aprano http://import-that.dreamwidth.org/ From __peter__ at web.de Sat May 10 08:10:14 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 10 May 2014 14:10:14 +0200 Subject: xmltodict - TypeError: list indices must be integers, not str References: Message-ID: flebber wrote: > I am using xmltodict. > > This is how I have accessed and loaded my file. > > import xmltodict > document = open("/home/sayth/Scripts/va_benefits/20140508GOSF0.xml", "r") > read_doc = document.read() > xml_doc = xmltodict.parse(read_doc) > > The start of the file I am trying to get data out of is. > > date="2014-05-08T00:00:00" gearchanges="-1" stewardsreport="-1" > gearlist="-1" racebook="0" postracestewards="0" meetingtype="TAB" > rail="True" weather="Fine " trackcondition="Dead " > nomsdeadline="2014-05-02T11:00:00" weightsdeadline="2014-05-05T16:00:00" > acceptdeadline="2014-05-06T09:00:00" jockeydeadline="2014-05-06T12:00:00"> > website="http://" /> > stage="Acceptances" distance="1600" minweight="55" raisedweight="0" > class="MDN " age="~ " grade="0" weightcondition="HCP > " trophy="0" owner="0" trainer="0" jockey="0" strapper="0" > totalprize="22000" first="12250" second="4250" third="2100" > fourth="1000" fifth="525" time="2014-05-08T12:30:00" bonustype="BX02 > " nomsfee="0" acceptfee="0" trackcondition=" " timingmethod=" > " fastesttime=" " sectionaltime=" " > formavailable="0" racebookprize="Of $22000. First $12250, second $4250, > third $2100, fourth $1000, fifth $525, sixth $375, seventh $375, eighth > $375, ninth $375, tenth $375"> > > > So thought I had it figured. Can access the elements of meeting and the > elements of club such as by doing this. > > In [5]: xml_doc['meeting']['club']['@abbrevname'] > Out[5]: u'Gosford Race Club' > > However whenever I try and access race in the same manner I get errors. > > In [11]: xml_doc['meeting']['club']['race']['@id'] > --------------------------------------------------------------------------- > KeyError Traceback (most recent call > last) in () > ----> 1 xml_doc['meeting']['club']['race']['@id'] > > KeyError: 'race' > > In [12]: xml_doc['meeting']['race']['@id'] > --------------------------------------------------------------------------- > TypeError Traceback (most recent call > last) in () > ----> 1 xml_doc['meeting']['race']['@id'] > > TypeError: list indices must be integers, not str > > why is accessing race @id any different to the access of club @abbrevname > and how do I get it for race? If I were to guess: there are multiple races per meeting, xmltodict puts them into a list under the "race" key, and you have to pick one: >>> doc = xmltodict.parse("""\ ... ... ... ... ... ... ... """) >>> type(doc["meeting"]["race"]) >>> doc["meeting"]["race"][0]["@id"] 'first race' >>> doc["meeting"]["race"][1]["@id"] 'second race' So xml_doc['meeting']['race'][0]['@id'] or for race in xml_doc["meeting"]["race"]: print(race["@id"]) might work for you. From roy at panix.com Sat May 10 09:42:37 2014 From: roy at panix.com (Roy Smith) Date: Sat, 10 May 2014 09:42:37 -0400 Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Dennis Lee Bieber wrote: > On 08 May 2014 16:04:51 GMT, Steven D'Aprano > declaimed the following: > > >Personally, I think that trying to be general and talk about "many other > >languages" is a failing strategy. Better to be concrete: C, Pascal, > >Algol, Fortran, VB (I think) are good examples of the "value in a box at > >a fixed location" model. Of those, Algol, Pascal and Fortran are either > >obsolete or legacy, and C is by far the most well-known by people here. > >(For some reason, few people seem to migrate from VB to Python.) Hence, > >"C-like". > > > > Obsolete and Legacy? Fortran still receives regular standards updates > (currently 2008, with the next revision due in 2015). Ars Technica article a couple of days ago, about Fortran, and what is likely to replace it: http://tinyurl.com/mr54p96 From malaclypse2 at gmail.com Sat May 10 10:41:24 2014 From: malaclypse2 at gmail.com (Jerry Hill) Date: Sat, 10 May 2014 10:41:24 -0400 Subject: Error while calling round() from future.builtins In-Reply-To: <591c2939-7648-47f5-854e-ad254a8a732f@googlegroups.com> References: <591c2939-7648-47f5-854e-ad254a8a732f@googlegroups.com> Message-ID: On Sat, May 10, 2014 at 7:39 AM, Preethi wrote: > future==0.9.0 It looks like that library is out of date. The current version looks to be 0.12.0, and it also looks like this bug was fixed in the 0.12.0 release. I'd upgrade your version if at all possible. -- Jerry From albert at spenarnc.xs4all.nl Sat May 10 11:24:49 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 10 May 2014 15:24:49 GMT Subject: How can this assert() ever trigger? Message-ID: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> I have the following code for calculating the determinant of a matrix. It works inasfar that it gives the same result as an octave program on a same matrix. / ---------------------------------------------------------------- def determinant( mat ): ''' Return the determinant of the n by n matrix mat i row j column Destroys mat ! ''' #print "getting determinat of", mat n=len(mat) nom = 1. if n == 1: return mat[0][0] lastr = mat.pop() jx=-1 for j in xrange(n): if lastr[j]: jx=j break if jx==-1: return 0. result = lastr[jx] assert(result<>0.) # Make column jx zero by subtracting a multiple of the last row. for i in xrange(n-1): pivot = mat[i][jx] if 0. == pivot: continue assert(result<>0.) nom *= result # Compenstate for multiplying a row. for j in xrange(n): mat[i][j] *= result for j in xrange(n): mat[i][j] -= pivot*lastr[j] # Remove colunm jx for i in xrange(n-1): x= mat[i].pop(jx) assert( x==0 ) if (n-1+jx)%2<>0: result = -result det = determinant( mat ) assert(nom<>0.) return result*det/nom /----------------------------------------- Now on some matrices the assert triggers, meaning that nom is zero. How can that ever happen? mon start out as 1. and gets multiplied with a number that is asserted to be not zero. Any hints appreciated. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From __peter__ at web.de Sat May 10 11:50:00 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 10 May 2014 17:50 +0200 Subject: How can this assert() ever trigger? References: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> Message-ID: Albert van der Horst wrote: > I have the following code for calculating the determinant of > a matrix. It works inasfar that it gives the same result as an > octave program on a same matrix. > > / ---------------------------------------------------------------- > > def determinant( mat ): > ''' Return the determinant of the n by n matrix mat > i row j column > Destroys mat ! ''' > #print "getting determinat of", mat > n=len(mat) > nom = 1. > if n == 1: return mat[0][0] > lastr = mat.pop() > jx=-1 > for j in xrange(n): > if lastr[j]: > jx=j > break > if jx==-1: return 0. > result = lastr[jx] > assert(result<>0.) > # Make column jx zero by subtracting a multiple of the last row. > for i in xrange(n-1): > pivot = mat[i][jx] > if 0. == pivot: continue > assert(result<>0.) > nom *= result # Compenstate for multiplying a row. > for j in xrange(n): > mat[i][j] *= result > for j in xrange(n): > mat[i][j] -= pivot*lastr[j] > # Remove colunm jx > for i in xrange(n-1): > x= mat[i].pop(jx) > assert( x==0 ) > > if (n-1+jx)%2<>0: result = -result > det = determinant( mat ) > assert(nom<>0.) > return result*det/nom > > /----------------------------------------- > > Now on some matrices the assert triggers, meaning that nom is zero. > How can that ever happen? mon start out as 1. and gets multiplied > with a number that is asserted to be not zero. > > Any hints appreciated. Floating point precision is limited: >>> x = 1.0 >>> for i in itertools.count(): ... x *= .1 ... assert x ... Traceback (most recent call last): File "", line 3, in AssertionError >>> i 323 From ethan at stoneleaf.us Sat May 10 11:35:04 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 10 May 2014 08:35:04 -0700 Subject: How can this assert() ever trigger? In-Reply-To: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> References: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <536E4728.8020505@stoneleaf.us> What happens if you run the same matrix through Octave? By any chance, is nom just really, really small? -- ~Ethan~ From gary.herron at islandtraining.com Sat May 10 11:48:17 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sat, 10 May 2014 08:48:17 -0700 Subject: How can this assert() ever trigger? In-Reply-To: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> References: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <536E4A41.7040906@islandtraining.com> On 05/10/2014 08:24 AM, Albert van der Horst wrote: > I have the following code for calculating the determinant of > a matrix. It works inasfar that it gives the same result as an > octave program on a same matrix. > > / ---------------------------------------------------------------- > > def determinant( mat ): > ''' Return the determinant of the n by n matrix mat > i row j column > Destroys mat ! ''' > #print "getting determinat of", mat > n=len(mat) > nom = 1. > if n == 1: return mat[0][0] > lastr = mat.pop() > jx=-1 > for j in xrange(n): > if lastr[j]: > jx=j > break > if jx==-1: return 0. > result = lastr[jx] > assert(result<>0.) > # Make column jx zero by subtracting a multiple of the last row. > for i in xrange(n-1): > pivot = mat[i][jx] > if 0. == pivot: continue > assert(result<>0.) > nom *= result # Compenstate for multiplying a row. > for j in xrange(n): > mat[i][j] *= result > for j in xrange(n): > mat[i][j] -= pivot*lastr[j] > # Remove colunm jx > for i in xrange(n-1): > x= mat[i].pop(jx) > assert( x==0 ) > > if (n-1+jx)%2<>0: result = -result > det = determinant( mat ) > assert(nom<>0.) > return result*det/nom > > /----------------------------------------- > > Now on some matrices the assert triggers, meaning that nom is zero. > How can that ever happen? mon start out as 1. and gets multiplied > with a number that is asserted to be not zero. Easily due to *underflow* precision trouble. Your "result" may never be zero, but it can be very small. Take the product of many of such tiny values, and the result can be less then the smallest value representable by a float, at which point it becomes zero. To see this clearly, try this Python code: >>> a = 1.0 >>> while a > 0: ... a = a*1.0e-50 ... print(a) ... 1e-50 1e-100 1e-150 1e-200 1e-250 1e-300 0.0 Gary Herron > > Any hints appreciated. > > Groetjes Albert From alain at dpt-info.u-strasbg.fr Sat May 10 11:56:58 2014 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sat, 10 May 2014 17:56:58 +0200 Subject: How can this assert() ever trigger? References: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <874n0xvd85.fsf@dpt-info.u-strasbg.fr> albert at spenarnc.xs4all.nl (Albert van der Horst) writes: [...] > Now on some matrices the assert triggers, meaning that nom is zero. > How can that ever happen? mon start out as 1. and gets multiplied [several times] > with a number that is asserted to be not zero. Finite precision. Try: 1.*1e-162*1e-162. Equals zero. -- Alain. From albert at spenarnc.xs4all.nl Sat May 10 12:39:02 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 10 May 2014 16:39:02 GMT Subject: How can this assert() ever trigger? References: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> <874n0xvd85.fsf@dpt-info.u-strasbg.fr> Message-ID: <536e5626$0$2931$e4fe514c@dreader37.news.xs4all.nl> In article <874n0xvd85.fsf at dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: >albert at spenarnc.xs4all.nl (Albert van der Horst) writes: > >[...] >> Now on some matrices the assert triggers, meaning that nom is zero. >> How can that ever happen? mon start out as 1. and gets multiplied > >[several times] > >> with a number that is asserted to be not zero. > >Finite precision. Try: 1.*1e-162*1e-162. Equals zero. > >-- Alain. Thanks you Alan and all others to point this out. That was indeed the problem. Somehow I expected that floating underflow would raise an exception, so I had a blind spot there. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From musicalhacksaw at yahoo.co.uk Sat May 10 12:58:18 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Sat, 10 May 2014 09:58:18 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. Message-ID: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> I am new to Python, but my main interest is to use it to Webscrape. I have downloaded Beautiful Soup, and have followed the instruction in the 'Getting Started with Beautiful Soup' book, but my Python installations keep returning errors, so I can't get started. I have unzipped Beautiful Soup to a folder of the same name on my C drive, in accordance with the first two steps of page 12 of the aforementioned publication, but proceeding to navigate to the program as in step three, re: "Open up the command line prompt and navigate to the folder where you have unzipped the folder as follows: cd Beautiful Soup python setup python install " This returns on my Python 27 : >>> cd Beautiful Soup File "",line 1 cd Beautiful Soup ^ SyntaxError: invalid syntax >>> also I get: >>> cd Beautiful Soup SyntaxError: invalid syntax >>> to my IDLE Python 2.7 version, same goes for the Python 3.4 installations. Hope someone can help. Thanks in advance. From rosuav at gmail.com Sat May 10 13:03:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 May 2014 03:03:26 +1000 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> Message-ID: On Sun, May 11, 2014 at 2:58 AM, Simon Evans wrote: > "Open up the command line prompt and navigate to the folder where you have unzipped the folder as follows: > cd Beautiful Soup > python setup python install " This would be the operating system command line, not Python's interactive mode. Since you refer to a C drive, I'm going to assume Windows; you'll want to open up "Command Prompt", or cmd.exe, or whatever name your version of Windows buries it under. (Microsoft does not make it particularly easy on you.) Since you have a space in the name, you'll need quotes: cd "c:\Beautiful Soup" Then proceed as per the instructions. ChrisA From esawiek at gmail.com Sat May 10 13:07:33 2014 From: esawiek at gmail.com (esawiek at gmail.com) Date: Sat, 10 May 2014 10:07:33 -0700 (PDT) Subject: NumPy, SciPy, & Python 3X Installation/compatibility issues Message-ID: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> Hi All-- Let me state at the start that I am new to Python. I am moving away from Fortran and Matlab to Python and I use all different types of numerical and statistical recipes in my work. I have been reading about NumPy and SciPy and could not find any definitive answers to my questions, below. I had run into many mostly installation problems that I could never get NumPy or SciPy to work with Python 3.3 or newer. I am using Windows7 64 bit OS. A few questions: 1. What are the latest versions of NumPy and SciPy that are compatible with Python 3.3 or newer and Windows7 64 bit? 2. What is the best source to download and install them on my computer? 3. Are they all installable on my OS w/o any major problems/addition? 4. In the long run, would it be better to use UNIX instead of Windows, if I were to use Python for all of my research? Thanks in advance. EK From rosuav at gmail.com Sat May 10 13:22:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 May 2014 03:22:18 +1000 Subject: NumPy, SciPy, & Python 3X Installation/compatibility issues In-Reply-To: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> References: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> Message-ID: On Sun, May 11, 2014 at 3:07 AM, wrote: > 4. In the long run, would it be better to use UNIX instead of Windows, if I were to use Python for all of my research? Yes. Absolutely yes. But that's because it's better to run Unix than Windows regardless of all other considerations. :) As a general rule, a Linux (I can't speak for other flavours of Unix, but I expect they'll be mostly the same) system will tend to settle into better performance the longer it keeps running, as long as it has sufficient RAM. The things you use will tend to be in cache, but other than that, nothing much changes as you seek toward infinite uptime. Windows, on the other hand, tends to accumulate cruft; the longer you keep the system running, the more RAM gets wasted in various nooks and crannies. I can't be sure of whether it's the OS itself or an application, but I do know that my Windows laptop sometimes needs to be rebooted just because "stuff's feeling a bit sluggish", and none of my Linux boxes are like that. That said, though, my idea of uptime is measured in months. If you're the sort of person who arrives at work, turns on the computer, uses it for a day, and then turns it off and goes home, the difference gets a lot smaller. (Unless you suspend/hibernate rather than actually shutting down, in which case the difference gets bigger again.) I still prefer a Unix system, though, because the worst messes I can get myself into can usually be cured by SSH'ing in and killing some process, which on Windows is both harder to do and less effective. ChrisA From hauzer at gmx.com Sat May 10 13:15:02 2014 From: hauzer at gmx.com (=?UTF-8?B?0J3QuNC60L7Qu9CwINCS0YPQutC+0YHQsNCy0ZnQtdCy0LjRmw==?=) Date: Sat, 10 May 2014 19:15:02 +0200 Subject: NumPy, SciPy, & Python 3X Installation/compatibility issues In-Reply-To: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> References: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> Message-ID: <536E5E96.30100@gmx.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 10.5.2014 19:07, esawiek at gmail.com wrote: > Hi All-- > > Let me state at the start that I am new to Python. I am moving away > from Fortran and Matlab to Python and I use all different types of > numerical and statistical recipes in my work. I have been reading > about NumPy and SciPy and could not find any definitive answers to > my questions, below. I had run into many mostly installation > problems that I could never get NumPy or SciPy to work with Python > 3.3 or newer. I am using Windows7 64 bit OS. A few questions: 1. > What are the latest versions of NumPy and SciPy that are compatible > with Python 3.3 or newer and Windows7 64 bit? 2. What is the best > source to download and install them on my computer? 3. Are they all > installable on my OS w/o any major problems/addition? 4. In the > long run, would it be better to use UNIX instead of Windows, if I > were to use Python for all of my research? Thanks in advance. EK > For 64-bit Windows, I've had luck with installations from http://www.lfd.uci.edu/~gohlke/pythonlibs/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBAgAGBQJTbl6WAAoJEB1x37R9kdwnVQ4QAMHRLmwKHKAKDiitrSlt/glo szOMAcjVff4vjNYt5N0x2Rqr1e6vgte9NoGcOgKPJbR1GUYMphQK3pgbkPfxX2Cl 030MI2ir//0WiCYP80rsLJBgAv88vhWx/dKFpG8EeN7LEP6AkJflVsWKeET4ZGfU p0S/L1n/pePpiNs15QwZ0LVvTu7u86ZSJuxkLQfznL53aJtl5ztPFgNfvgvbW56f Dap9KruqhbkC1EZD/6ogBQUgDZS51o0Cv3UsXdZJD0W69elnGXLHmCTY4kUwCDSa psY29aviZHf8RHn5cb/TWobbu5P5PRJx0PVoIRmE8/CDlQKfXny7wPaU6e6PgT0Y hmnskuN0PBubDm1zfZgiolOa4g5VzVVuB/r/JRpnAw4nxq6tluHbhs/OfFjSEUPu n3qA4nCTB2wI5cP32sy3Q87SJ33ZQR0Nc8wHOLDmhgyhox7699q/7yu1RLYUCXAS VLaQ4WEIgH3xJKrmDjktwdDsC+HBlfZuHqUxpHS/rAi54ey8OLWWoBW4t4ZE2PTn 0FPEejNI526WrUS1G/MjoaFAI/usSjnoThERg8gCroAi89JjoE4B53BT4Z5ONhQU APPfkCIlzW2WQslxXhuoJY2XWM4NMf/dOOfS60qCVZa3EQaX97xo2j96mKkR9bMO TYrl2RUWjMetm8t8VFNO =v+OK -----END PGP SIGNATURE----- From stefan_ml at behnel.de Sat May 10 14:25:58 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 10 May 2014 20:25:58 +0200 Subject: NumPy, SciPy, & Python 3X Installation/compatibility issues In-Reply-To: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> References: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> Message-ID: esawiek at gmail.com, 10.05.2014 19:07: > Let me state at the start that I am new to Python. I am moving away from Fortran and Matlab to Python and I use all different types of numerical and statistical recipes in my work. I have been reading about NumPy and SciPy and could not find any definitive answers to my questions, below. I had run into many mostly installation problems that I could never get NumPy or SciPy to work with Python 3.3 or newer. I am using Windows7 64 bit OS. > A few questions: > 1. What are the latest versions of NumPy and SciPy that are compatible with Python 3.3 or newer and Windows7 64 bit? > 2. What is the best source to download and install them on my computer? > 3. Are they all installable on my OS w/o any major problems/addition? > 4. In the long run, would it be better to use UNIX instead of Windows, if I were to use Python for all of my research? I concur with Chris that Linux is generally a better choice than Windows, if only to get a nicely preconfigured system that makes it easy to install stuff. Especially for "research" (assuming we're talking about the same thing). If you say that you're "moving away from Fortran" on Windows, then I guess you're aware how clumsy low level software development can be on that platform and how tricky it is to set up. That could be enough of a reason to switch platforms (assuming that's really an option for you). Ok, if you use only the IPython notebook for all your processing needs, you may not notice the difference in terms of interface all that much, but in that case, why stick with Windows in the first place? :) If you decide to use Windows, try Anaconda. It's an all inclusive installer that comes with pretty much all of your scientific processing tools in one package: http://docs.continuum.io/anaconda/ There's a Py3.3 version. Stefan From tjreedy at udel.edu Sat May 10 14:31:11 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 10 May 2014 14:31:11 -0400 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/10/2014 9:42 AM, Roy Smith wrote: > In article , > Dennis Lee Bieber wrote: >> Obsolete and Legacy? Fortran still receives regular standards updates >> (currently 2008, with the next revision due in 2015). > > Ars Technica article a couple of days ago, about Fortran, and what is > likely to replace it: What might *possibly* replace it. > > http://tinyurl.com/mr54p96 The article is deficient in that it ignores the 20-year-old combination of python with fortran and the facts that the combination gives fortran a repl loop and that this combination has already somewhat replaced bare fortran. -- Terry Jan Reedy From tjreedy at udel.edu Sat May 10 14:39:50 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 10 May 2014 14:39:50 -0400 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> Message-ID: On 5/10/2014 1:03 PM, Chris Angelico wrote: > On Sun, May 11, 2014 at 2:58 AM, Simon Evans wrote: >> "Open up the command line prompt and navigate to the folder where you have unzipped the folder as follows: >> cd Beautiful Soup >> python setup python install " > > This would be the operating system command line, not Python's > interactive mode. Since you refer to a C drive, I'm going to assume > Windows; you'll want to open up "Command Prompt", or cmd.exe, or > whatever name your version of Windows buries it under. (Microsoft does > not make it particularly easy on you.) On the All Programs / Start menu, look under Accessories. I have it pinned to my Win 7 task bar. > Since you have a space in the name, you'll need quotes: > > cd "c:\Beautiful Soup" Not for Win 7, at least C:\Users\Terry>cd \program files C:\Program Files> -- Terry Jan Reedy From ethan at stoneleaf.us Sat May 10 15:10:21 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 10 May 2014 12:10:21 -0700 Subject: Values and objects In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536E799D.6080602@stoneleaf.us> On 05/10/2014 02:32 AM, Chris Angelico wrote: > > Tell me, what may this function do in a compliant Python? > > def demo(): > ret = spam > spam = 23 > return ret > > In CPython, that'll raise UnboundLocalError, because the local > variable 'spam' does already exist, and currently has no value (no > object bound to it). No, it does not exist -- or, more accurately, it does not exist *yet* but will. The fact that there is a slot waiting for what will be spam is a cpython implementation detail. And if you don't like that argument (although it is a perfectly sound and correct argument), think of the module name space: ret = spam spam = 23 will net you a simple NameError, because spam has not yet been created. > If a compliant Python implementation is allowed > to have this return the value of a global or builtin spam, then I > would agree that you can create variables at run time. See module example above. This behavior is not allowed in functions for scope and sanity (mostly sanity) reasons. -- ~Ethan~ From python at mrabarnett.plus.com Sat May 10 15:22:12 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 10 May 2014 20:22:12 +0100 Subject: Values and objects In-Reply-To: <536E799D.6080602@stoneleaf.us> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> Message-ID: <536E7C64.30708@mrabarnett.plus.com> On 2014-05-10 20:10, Ethan Furman wrote: > On 05/10/2014 02:32 AM, Chris Angelico wrote: >> >> Tell me, what may this function do in a compliant Python? >> >> def demo(): >> ret = spam >> spam = 23 >> return ret >> >> In CPython, that'll raise UnboundLocalError, because the local >> variable 'spam' does already exist, and currently has no value (no >> object bound to it). > > No, it does not exist -- or, more accurately, it does not exist *yet* but will. The fact that there is a slot waiting > for what will be spam is a cpython implementation detail. > > And if you don't like that argument (although it is a perfectly sound and correct argument), think of the module name space: > > ret = spam > spam = 23 > > will net you a simple NameError, because spam has not yet been created. > > >> If a compliant Python implementation is allowed >> to have this return the value of a global or builtin spam, then I >> would agree that you can create variables at run time. > > See module example above. This behavior is not allowed in functions for scope and sanity (mostly sanity) reasons. > UnboundLocalError is like NameError, except that Python knows that the name is local because somewhere in the function you're binding to that name and you haven't said that it's global or nonlocal. Having a different exception for that case makes it clearer to the user what the problem is. From subhabangalore at gmail.com Sat May 10 15:27:34 2014 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sat, 10 May 2014 12:27:34 -0700 (PDT) Subject: Question on Debugging a code line Message-ID: <283e285b-4ab3-4ec7-a8be-4f1e047d9645@googlegroups.com> Dear Room, I was trying to go through a code given in http://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm[ Forward Backward is an algorithm of Machine Learning-I am not talking on that I am just trying to figure out a query on its Python coding.] I came across the following codes. >>> states = ('Healthy', 'Fever') >>> end_state = 'E' >>> observations = ('normal', 'cold', 'dizzy') >>> start_probability = {'Healthy': 0.6, 'Fever': 0.4} >>> transition_probability = { 'Healthy' : {'Healthy': 0.69, 'Fever': 0.3, 'E': 0.01}, 'Fever' : {'Healthy': 0.4, 'Fever': 0.59, 'E': 0.01}, } >>> emission_probability = { 'Healthy' : {'normal': 0.5, 'cold': 0.4, 'dizzy': 0.1}, 'Fever' : {'normal': 0.1, 'cold': 0.3, 'dizzy': 0.6}, } def fwd_bkw(x, states, a_0, a, e, end_st): L = len(x) fwd = [] f_prev = {} #THE PROBLEM # forward part of the algorithm for i, x_i in enumerate(x): f_curr = {} for st in states: if i == 0: # base case for the forward part prev_f_sum = a_0[st] else: prev_f_sum = sum(f_prev[k]*a[k][st] for k in states) ## f_curr[st] = e[st][x_i] * prev_f_sum fwd.append(f_curr) f_prev = f_curr p_fwd = sum(f_curr[k]*a[k][end_st] for k in states) As this value was being called in prev_f_sum = sum(f_prev[k]*a[k][st] for k in states marked ## I wanted to know what values it is generating. So, I had made the following experiment, after for i, x_i in enumerate(x): I had put print f_prev but I am not getting how f_prev is getting the values. Here, x=observations, states= states, a_0=start_probability, a= transition_probability, e=emission_probability, end_st= end_state Am I missing any minor aspect? Code is running fine. If any one of the esteemed members may kindly guide me. Regards, Subhabrata Banerjee. From ethan at stoneleaf.us Sat May 10 15:30:38 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 10 May 2014 12:30:38 -0700 Subject: The =?UTF-8?B?77+9IGRlYmF0ZQ==?= In-Reply-To: <717336ca-387c-4ca4-ba56-7d0f9f083036@googlegroups.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <8738gkh42a.fsf@elektro.pacujo.net> <8538gkaxr8.fsf@benfinney.id.au> <536c1b2e$0$29965$c3e8da3$5496439d@news.astraweb.com> <536d8208$0$29980$c3e8da3$5496439d@news.astraweb.com> <536dd9cb$0$29980$c3e8da3$5496439d@news.astraweb.com> <717336ca-387c-4ca4-ba56-7d0f9f083036@googlegroups.com> Message-ID: <536E7E5E.4080204@stoneleaf.us> On 05/10/2014 02:05 AM, Rustom Mody wrote: > On Saturday, May 10, 2014 1:18:27 PM UTC+5:30, Steven D'Aprano wrote: >> >> Python assignment doesn't copy values. > > Maybe our values differ? Obviously they do. Yours are irrelevant for Python. They could be, and probably are, useful when comparing and contrasting Python with other languages, or maybe when discussing a particular implementation of Python -- but when discussing the *language* of Python, your definition of value doesn't exist. When learning a foreign human language most folks start at, and some stay at, the "think in native language, translate on the fly" mode. And it probably works well enough to get by. But that is not fluency. Fluency is understanding the meaning behind the words, behind the sounds, and eventually being able to *think* in that other language. If that is not your goal, fine; please stop muddying other's understanding of how Python the language works. -- ~Ethan~ From ethan at stoneleaf.us Sat May 10 15:28:20 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 10 May 2014 12:28:20 -0700 Subject: Values and objects In-Reply-To: <536E7C64.30708@mrabarnett.plus.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536E7C64.30708@mrabarnett.plus.com> Message-ID: <536E7DD4.4060200@stoneleaf.us> On 05/10/2014 12:22 PM, MRAB wrote: > > UnboundLocalError is like NameError, except that Python knows that the > name is local because somewhere in the function you're binding to that > name and you haven't said that it's global or nonlocal. Having a > different exception for that case makes it clearer to the user what the > problem is. Absolutely. At one point NameError was raised in both cases, which could be very confusing to track down. -- ~Ethan~ From esawiek at gmail.com Sat May 10 16:08:09 2014 From: esawiek at gmail.com (esawiek at gmail.com) Date: Sat, 10 May 2014 13:08:09 -0700 (PDT) Subject: NumPy, SciPy, & Python 3X Installation/compatibility issues In-Reply-To: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> References: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> Message-ID: <7a80261b-99ba-4b8e-91b7-46cc36662ffa@googlegroups.com> On Saturday, May 10, 2014 1:07:33 PM UTC-4, esa... at gmail.com wrote: > Hi All-- > > > > Let me state at the start that I am new to Python. I am moving away from Fortran and Matlab to Python and I use all different types of numerical and statistical recipes in my work. I have been reading about NumPy and SciPy and could not find any definitive answers to my questions, below. I had run into many mostly installation problems that I could never get NumPy or SciPy to work with Python 3.3 or newer. I am using Windows7 64 bit OS. > > A few questions: > > 1. What are the latest versions of NumPy and SciPy that are compatible with Python 3.3 or newer and Windows7 64 bit? > > 2. What is the best source to download and install them on my computer? > > 3. Are they all installable on my OS w/o any major problems/addition? > > 4. In the long run, would it be better to use UNIX instead of Windows, if I were to use Python for all of my research? > > Thanks in advance. EK From esawiek at gmail.com Sat May 10 16:14:08 2014 From: esawiek at gmail.com (esawiek at gmail.com) Date: Sat, 10 May 2014 13:14:08 -0700 (PDT) Subject: NumPy, SciPy, & Python 3X Installation/compatibility issues In-Reply-To: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> References: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> Message-ID: On Saturday, May 10, 2014 1:07:33 PM UTC-4, esa... at gmail.com wrote: > Hi All-- > > > > Let me state at the start that I am new to Python. I am moving away from Fortran and Matlab to Python and I use all different types of numerical and statistical recipes in my work. I have been reading about NumPy and SciPy and could not find any definitive answers to my questions, below. I had run into many mostly installation problems that I could never get NumPy or SciPy to work with Python 3.3 or newer. I am using Windows7 64 bit OS. > > A few questions: > > 1. What are the latest versions of NumPy and SciPy that are compatible with Python 3.3 or newer and Windows7 64 bit? > > 2. What is the best source to download and install them on my computer? > > 3. Are they all installable on my OS w/o any major problems/addition? > > 4. In the long run, would it be better to use UNIX instead of Windows, if I were to use Python for all of my research? > > Thanks in advance. EK Thank you all. I checked the website suggested in on of the replies and it looks promising. Because I want to use Num, SciPy, and Python on windows just to be familiar with them a little more, then I do plan to migrate to UNIX. I will let you posted on my progress. Thanks again. EK From tjreedy at udel.edu Sat May 10 16:16:34 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 10 May 2014 16:16:34 -0400 Subject: Values and objects In-Reply-To: <536E799D.6080602@stoneleaf.us> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> Message-ID: On 5/10/2014 3:10 PM, Ethan Furman wrote: > On 05/10/2014 02:32 AM, Chris Angelico wrote: >> >> Tell me, what may this function do in a compliant Python? >> >> def demo(): >> ret = spam >> spam = 23 >> return ret >> >> In CPython, that'll raise UnboundLocalError, Note: >>> issubclass(UnboundLocalError, NameError) True I am not sure if adding the specificity is helpful or not. >> because the local >> variable 'spam' does already exist, and currently has no value (no >> object bound to it). > > No, it does not exist -- or, more accurately, it does not exist *yet* > but will. The fact that there is a slot waiting for what will be spam > is a cpython implementation detail. > > And if you don't like that argument (although it is a perfectly sound > and correct argument), think of the module name space: > > ret = spam > spam = 23 > > will net you a simple NameError, because spam has not yet been created. In other words, those two lines raise a NameError in either case. -- Terry Jan Reedy From harrismh777 at gmail.com Sat May 10 16:14:40 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 10 May 2014 15:14:40 -0500 Subject: NumPy, SciPy, & Python 3X Installation/compatibility issues References: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> Message-ID: On 5/10/14 12:07 PM, esawiek at gmail.com wrote: > 4. In the long run, would it be better to use UNIX instead of Windows, if I were to use Python for all of my research? > I concur with Chris and Stefan. The *nix model is faster, cleaner, and more secure. I prefer gnu/linux, but mac os/x is also quite nice. Simply change... or, if you like, just switch. I moved away from OS/2 and Windows in the late 1990s and have never looked back; no reason to use Windows what-so-ever. You're question (in the long run) is important, to be fair. Because, in the short run there will be some learning curve, and there will be some conceptual porting as well as code porting to handle; not to mention apps. All critical apps from Windows, and most day-to-day apps have free libre counter-parts in the unix world, and most everyday apps have gnu counter parts and others. Just switch. Proprietary code and systems will not survive the 21st century, you can be sure of that. 'We' can never allow another Microsoft to rule again; not google, nor canonical, nor oracle, nor anyone else. 'We' must have net neutrality, and software idea patents must die (world-wide). Go gnu/linux Go Python Go away, Microsoft, go away Oracle. marcus From tjreedy at udel.edu Sat May 10 16:24:21 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 10 May 2014 16:24:21 -0400 Subject: Values and objects In-Reply-To: <536E7C64.30708@mrabarnett.plus.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536E7C64.30708@mrabarnett.plus.com> Message-ID: On 5/10/2014 3:22 PM, MRAB wrote: > UnboundLocalError is like NameError, More specifically, >>> isinstance(UnboundLocalError(), NameError) True This means that 'except NameError:' clauses written before the UnboundLocalError subclass was added still work and do not necessarily need to be modified. (I am allowing for the possibility that the body of the clause tries to separate the specific error from other NameErrors). -- Terry Jan Reedy From python at mrabarnett.plus.com Sat May 10 16:44:59 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 10 May 2014 21:44:59 +0100 Subject: Question on Debugging a code line In-Reply-To: <283e285b-4ab3-4ec7-a8be-4f1e047d9645@googlegroups.com> References: <283e285b-4ab3-4ec7-a8be-4f1e047d9645@googlegroups.com> Message-ID: <536E8FCB.3020400@mrabarnett.plus.com> On 2014-05-10 20:27, subhabangalore at gmail.com wrote: > Dear Room, > > I was trying to go through a code given in http://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm[ Forward Backward is an algorithm of Machine Learning-I am not talking on that > I am just trying to figure out a query on its Python coding.] > > I came across the following codes. > >>>> states = ('Healthy', 'Fever') >>>> end_state = 'E' >>>> observations = ('normal', 'cold', 'dizzy') >>>> start_probability = {'Healthy': 0.6, 'Fever': 0.4} >>>> transition_probability = { > 'Healthy' : {'Healthy': 0.69, 'Fever': 0.3, 'E': 0.01}, > 'Fever' : {'Healthy': 0.4, 'Fever': 0.59, 'E': 0.01}, > } >>>> emission_probability = { > 'Healthy' : {'normal': 0.5, 'cold': 0.4, 'dizzy': 0.1}, > 'Fever' : {'normal': 0.1, 'cold': 0.3, 'dizzy': 0.6}, > } > > def fwd_bkw(x, states, a_0, a, e, end_st): > L = len(x) > fwd = [] > f_prev = {} #THE PROBLEM > # forward part of the algorithm > for i, x_i in enumerate(x): > f_curr = {} > for st in states: > if i == 0: > # base case for the forward part > prev_f_sum = a_0[st] > else: > prev_f_sum = sum(f_prev[k]*a[k][st] for k in states) ## > > f_curr[st] = e[st][x_i] * prev_f_sum > > fwd.append(f_curr) > f_prev = f_curr > > p_fwd = sum(f_curr[k]*a[k][end_st] for k in states) > > As this value was being called in prev_f_sum = sum(f_prev[k]*a[k][st] for k in states marked ## > I wanted to know what values it is generating. > So, I had made the following experiment, after > for i, x_i in enumerate(x): > I had put print f_prev > but I am not getting how f_prev is getting the values. > > Here, > x=observations, > states= states, > a_0=start_probability, > a= transition_probability, > e=emission_probability, > end_st= end_state > > Am I missing any minor aspect? > Code is running fine. > > If any one of the esteemed members may kindly guide me. > The values calculated in the inner loop are being put into the dict 'f_curr' and then, when that loop has completed, 'f_prev' is being bound to that dict. 'f_curr' is bound to a new dict just before the inner loop, ready for the new values. From jeanpierreda at gmail.com Sat May 10 17:03:11 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 10 May 2014 14:03:11 -0700 Subject: Values and objects In-Reply-To: <536E799D.6080602@stoneleaf.us> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> Message-ID: On Sat, May 10, 2014 at 12:10 PM, Ethan Furman wrote: > On 05/10/2014 02:32 AM, Chris Angelico wrote: >> >> >> Tell me, what may this function do in a compliant Python? >> >> def demo(): >> ret = spam >> spam = 23 >> return ret >> >> In CPython, that'll raise UnboundLocalError, because the local >> variable 'spam' does already exist, and currently has no value (no >> object bound to it). > > > No, it does not exist -- or, more accurately, it does not exist *yet* but > will. The fact that there is a slot waiting for what will be spam is a > cpython implementation detail. The name of the exception is "UnboundLocalError". And the message says that we referred to a "local variable". Also see the language reference: "When a name is not found at all, a NameError exception is raised. If the name refers to a local variable that has not been bound, a UnboundLocalError exception is raised. UnboundLocalError is a subclass of NameError." spam is referring to a local variable that has not been bound. This is not an implementation detail. > And if you don't like that argument (although it is a perfectly sound and > correct argument), think of the module name space: > > > ret = spam > spam = 23 > > will net you a simple NameError, because spam has not yet been created. Because module level variables work differently from local variables. -- Devin From flebber.crue at gmail.com Sat May 10 18:36:45 2014 From: flebber.crue at gmail.com (flebber) Date: Sat, 10 May 2014 15:36:45 -0700 (PDT) Subject: xmltodict - TypeError: list indices must be integers, not str In-Reply-To: References: Message-ID: <35b4fd26-49ee-40b6-be1a-c15994bc79eb@googlegroups.com> On Saturday, 10 May 2014 22:10:14 UTC+10, Peter Otten wrote: > flebber wrote: > > > > > I am using xmltodict. > > > > > > This is how I have accessed and loaded my file. > > > > > > import xmltodict > > > document = open("/home/sayth/Scripts/va_benefits/20140508GOSF0.xml", "r") > > > read_doc = document.read() > > > xml_doc = xmltodict.parse(read_doc) > > > > > > The start of the file I am trying to get data out of is. > > > > > > > > date="2014-05-08T00:00:00" gearchanges="-1" stewardsreport="-1" > > > gearlist="-1" racebook="0" postracestewards="0" meetingtype="TAB" > > > rail="True" weather="Fine " trackcondition="Dead " > > > nomsdeadline="2014-05-02T11:00:00" weightsdeadline="2014-05-05T16:00:00" > > > acceptdeadline="2014-05-06T09:00:00" jockeydeadline="2014-05-06T12:00:00"> > > > > > website="http://" /> > > > > > stage="Acceptances" distance="1600" minweight="55" raisedweight="0" > > > class="MDN " age="~ " grade="0" weightcondition="HCP > > > " trophy="0" owner="0" trainer="0" jockey="0" strapper="0" > > > totalprize="22000" first="12250" second="4250" third="2100" > > > fourth="1000" fifth="525" time="2014-05-08T12:30:00" bonustype="BX02 > > > " nomsfee="0" acceptfee="0" trackcondition=" " timingmethod=" > > > " fastesttime=" " sectionaltime=" " > > > formavailable="0" racebookprize="Of $22000. First $12250, second $4250, > > > third $2100, fourth $1000, fifth $525, sixth $375, seventh $375, eighth > > > $375, ninth $375, tenth $375"> > > > > > > > > > So thought I had it figured. Can access the elements of meeting and the > > > elements of club such as by doing this. > > > > > > In [5]: xml_doc['meeting']['club']['@abbrevname'] > > > Out[5]: u'Gosford Race Club' > > > > > > However whenever I try and access race in the same manner I get errors. > > > > > > In [11]: xml_doc['meeting']['club']['race']['@id'] > > > > > --------------------------------------------------------------------------- > > > KeyError Traceback (most recent call > > > last) in () > > > ----> 1 xml_doc['meeting']['club']['race']['@id'] > > > > > > KeyError: 'race' > > > > > > In [12]: xml_doc['meeting']['race']['@id'] > > > > > --------------------------------------------------------------------------- > > > TypeError Traceback (most recent call > > > last) in () > > > ----> 1 xml_doc['meeting']['race']['@id'] > > > > > > TypeError: list indices must be integers, not str > > > > > > why is accessing race @id any different to the access of club @abbrevname > > > and how do I get it for race? > > > > If I were to guess: there are multiple races per meeting, xmltodict puts > > them into a list under the "race" key, and you have to pick one: > > > > >>> doc = xmltodict.parse("""\ > > ... > > ... ... > > ... ... > > ... > > ... """) > > >>> type(doc["meeting"]["race"]) > > > > >>> doc["meeting"]["race"][0]["@id"] > > 'first race' > > >>> doc["meeting"]["race"][1]["@id"] > > 'second race' > > > > So > > > > xml_doc['meeting']['race'][0]['@id'] > > > > or > > > > for race in xml_doc["meeting"]["race"]: > > print(race["@id"]) > > > > might work for you. Thanks so much Peter, yes both worked indeed. Sayth From rosuav at gmail.com Sat May 10 19:23:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 May 2014 09:23:55 +1000 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> Message-ID: On Sun, May 11, 2014 at 4:39 AM, Terry Reedy wrote: >> Since you have a space in the name, you'll need quotes: >> >> >> cd "c:\Beautiful Soup" > > > Not for Win 7, at least > > C:\Users\Terry>cd \program files > > C:\Program Files> Huh, good to know. Unfortunately, Windows leaves command-line parsing completely up to the individual command/application, so some will need quotes, some won't, and some will actually do very different things if you put an argument in quotes (look at START and FIND). There is a broad convention that spaces in file names get protected with quotes, though (for instance, tab completion will put quotes around them), so it's not complete chaos. ChrisA From rosuav at gmail.com Sat May 10 19:18:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 May 2014 09:18:34 +1000 Subject: Values and objects In-Reply-To: <536E799D.6080602@stoneleaf.us> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> Message-ID: On Sun, May 11, 2014 at 5:10 AM, Ethan Furman wrote: > And if you don't like that argument (although it is a perfectly sound and > correct argument), think of the module name space: > > > ret = spam > spam = 23 > > will net you a simple NameError, because spam has not yet been created. What about this, though: ret = int int = 23 That will *not* net you a NameError, because 'int' exists in an outer scope (builtins). You can create a new module-scope variable and it will immediately begin to shadow a builtin; you can delete that variable and it will immediately cease to shadow that builtin. That's the difference I'm talking about. With function-local variables, they all have to exist (as other responses confirmed, that *is* a language guarantee), even though some of them aren't bound to anything yet. ChrisA From rosuav at gmail.com Sat May 10 19:35:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 May 2014 09:35:44 +1000 Subject: Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues) Message-ID: On Sun, May 11, 2014 at 6:14 AM, Mark H Harris wrote: > Proprietary code and systems will not survive the 21st century, you can be > sure of that. 'We' can never allow another Microsoft to rule again; not > google, nor canonical, nor oracle, nor anyone else. 'We' must have net > neutrality, and software idea patents must die (world-wide). > > Go gnu/linux > > Go Python > > Go away, Microsoft, go away Oracle. Actually, I'm not so sure of that. If all free software worked only with itself, was GPL3'd to prevent non-free software from using it, etc, the world would be a worse place. Part of what makes free software so tempting is that it happily interacts with *everything*, not just other free software. Otherwise, there'd be a massive gulf between the Apple world, the Microsoft world, and the GNU world, with minimal interoperability between them. Instead, what we have is a world in which Python can be used to write closed-source software, LibreOffice Writer will happily open a Microsoft Word document, Samba communicates with Windows computers, libc can be linked to non-free binaries, etc, etc, etc. Yes, that means the open source community can't wield its weight against closed-source. I am glad of that. Freedom means letting people choose to be free, not forcing them to be free. (Don't get me wrong, forcing someone to be free is better than forcing them to be enslaved. I don't mind a preinstalled LibreOffice on someone's computer as much as I would a preinstalled MS Office. But actually letting people choose is better.) Proprietary code and systems will continue to exist for as long as people are willing to buy them. Maybe we'll see a shift away from non-free desktop software, but cloud and mobile are still very much the domain of closed source at the moment. There might be a shift toward free mobile platforms, but I doubt the cloud will change. You can run anything you like on a server, and people will use it if it's useful. For one very very obvious example: you and I are both posting from Gmail. :) ChrisA From ethan at stoneleaf.us Sat May 10 21:28:43 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 10 May 2014 18:28:43 -0700 Subject: Values and objects In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> Message-ID: <536ED24B.7040300@stoneleaf.us> On 05/10/2014 04:18 PM, Chris Angelico wrote: > On Sun, May 11, 2014 at 5:10 AM, Ethan Furman wrote: >> And if you don't like that argument (although it is a perfectly sound and >> correct argument), think of the module name space: >> >> >> ret = spam >> spam = 23 >> >> will net you a simple NameError, because spam has not yet been created. > > What about this, though: > > ret = int > int = 23 > > That will *not* net you a NameError, because 'int' exists in an outer > scope (builtins). You can create a new module-scope variable and it > will immediately begin to shadow a builtin; you can delete that > variable and it will immediately cease to shadow that builtin. That's > the difference I'm talking about. With function-local variables, they > all have to exist (as other responses confirmed, that *is* a language > guarantee), even though some of them aren't bound to anything yet. Well, with function variables they have to exist *when you use them*. ;) This seems like more of a scoping issue than a "can we create variables in Python" issue. I am curious, though, what other python's do with respect to function variables. -- ~Ethan~ From rosuav at gmail.com Sat May 10 21:59:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 May 2014 11:59:21 +1000 Subject: Values and objects In-Reply-To: <536ED24B.7040300@stoneleaf.us> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536ED24B.7040300@stoneleaf.us> Message-ID: On Sun, May 11, 2014 at 11:28 AM, Ethan Furman wrote: > Well, with function variables they have to exist *when you use them*. ;) > > This seems like more of a scoping issue than a "can we create variables in > Python" issue. > > I am curious, though, what other python's do with respect to function > variables. Variables exist in scope. Apart from assembly language, where registers have universal scope, every language I know of has some concept of scope. (REXX is very different from most, in that "PROCEDURE EXPOSE" isn't at all your classic notion of scoping, but there's still the concept that there can be two variables with the same name.) When you create one, you create it in a particular scope, and that's how it must be. ChrisA From d at davea.name Sat May 10 22:16:32 2014 From: d at davea.name (Dave Angel) Date: Sat, 10 May 2014 22:16:32 -0400 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> Message-ID: <536EDD80.7000100@davea.name> On 05/10/2014 07:23 PM, Chris Angelico wrote: > There is a broad > convention that spaces in file names get protected with quotes, though > (for instance, tab completion will put quotes around them), so it's > not complete chaos. > "Complete chaos" is a pretty good description, especially since MS decided to make the default directory paths for many things have embedded spaces in them. And to change the rules from version to version of the OS. And it's not just the cmd line that's inconsistent; some exec function variants liberally parse unquoted names looking for some file that happens to match the first few 'words" of the string. I once debugged a customer problem (without actually seeing the machine), and told tech support to ask him if he had a file in the root directory called "program.exe." I turned out to be right, and the customer was sure I must have hacked into his machine. There was a bug in our code (missing quotes), masked by the liberality of the function I mentioned, that wasn't visible till such a file existed. The customer symptom? Our code complained that the linker couldn't be found. -- DaveA From steve+comp.lang.python at pearwood.info Sat May 10 23:11:22 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2014 03:11:22 GMT Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> Message-ID: <536eea59$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 May 2014 09:18:34 +1000, Chris Angelico wrote: > On Sun, May 11, 2014 at 5:10 AM, Ethan Furman > wrote: >> And if you don't like that argument (although it is a perfectly sound >> and correct argument), think of the module name space: >> >> >> ret = spam >> spam = 23 >> >> will net you a simple NameError, because spam has not yet been created. > > What about this, though: > > ret = int > int = 23 > > That will *not* net you a NameError, because 'int' exists in an outer > scope (builtins). You can create a new module-scope variable and it will > immediately begin to shadow a builtin; you can delete that variable and > it will immediately cease to shadow that builtin. Yes. That's part of documented language behaviour to do with scoping search paths. See below. > That's the difference > I'm talking about. With function-local variables, they all have to exist > (as other responses confirmed, that *is* a language guarantee), even > though some of them aren't bound to anything yet. Define "exist". Just because a slot exists waiting for a variable, doesn't mean that the variable which would use that slot exists. Like dicts and lists, function locals() are over-allocated: CPython pre-allocates slots for locals based on compile-time information, even if those locals are never bound to and therefore don't exist: def demo(): if False: x = 23 print x # Fails You're trying to argue that because there is a slot for x, the variable x exists. But I think that is the wrong definition of "exists". If you have a list L = [], would you say that L[4] exists because the array is over- allocated and already has (at least) four slots waiting to be used, but L[100] doesn't because it isn't over-allocated that much? What if the pre- allocation rules change? What if an implementation decides not to bother pre-allocating empty lists? What if an implementation pre-allocates a random number of array slots? Would you be comfortable saying that there is a 25% chance that L[4] exists and a 1% chance that L[100] exists? In both these cases, array slots in a list or dict, and locals, we risk mistaking implementation details for language features. I think you actually are making this error when it comes to locals. When talking about the implementation, it is relevant to discuss the existence of slots. But when talking about the language, about features visible from Python code such as variables (a.k.a. name bindings), local slots don't matter. Jython and IronPython don't (so far as I know) use them, and locals() happens to be writable. Here's an example from IronPython 2.6: >>> def test(): ... if False: spam = None ... d = locals() ... d['spam'] = 23 ... return spam ... >>> test() 23 And a similar example from Jython 2.5: >>> def test(): ... locals()['spam'] = 42 ... return spam ... spam = None ... >>> test() 42 Neither example works in CPython, you get an UnboundLocalError, but whether or not locals() is writable is is *explicitly* documented as an implementation detail. How implementations store local variables (in a dictionary like globals, slots, in the Cloud) is up to them, so long as the implementation follows the scoping rules. Python determines whether a variable is local or not at compile-time: (1) If a function contains a binding operation (assignment; import; del) on that variable, then the variable is defined as a local unless otherwise declared as a global or nonlocal (Python 3 only). (2) Otherwise it is not a local. (3) Outside of a function, it is a global whether declared as such or not. (4) Variables (names) don't exist until they have a value bound to them. I guess you want to challenge #4, and say that local variables exist as soon as the slot that holds them exists. I think that is wrong. And besides, even CPython 2 doesn't always use slots for locals: consider what happens when you use import * inside a function. And try running this function in both 2.7 and 3.3 and see if you can explain the difference: def test(): if False: x = None exec("x = 1") return x But I digress. Name look-ups for locals look only in the local scope. Name lookups for everything else search the chain nonlocals:globals:builtins. Name bindings (assignments, del, imports) for locals write only to the local scope. For globals they write only to the global scope and for nonlocals they write to the nearest enclosing nonlocal scope that already defines that variable. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sat May 10 23:17:22 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2014 03:17:22 GMT Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> Message-ID: <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 May 2014 14:03:11 -0700, Devin Jeanpierre wrote: > On Sat, May 10, 2014 at 12:10 PM, Ethan Furman > wrote: >> On 05/10/2014 02:32 AM, Chris Angelico wrote: >>> >>> >>> Tell me, what may this function do in a compliant Python? >>> >>> def demo(): >>> ret = spam >>> spam = 23 >>> return ret >>> >>> In CPython, that'll raise UnboundLocalError, because the local >>> variable 'spam' does already exist, and currently has no value (no >>> object bound to it). >> >> >> No, it does not exist -- or, more accurately, it does not exist *yet* >> but will. The fact that there is a slot waiting for what will be spam >> is a cpython implementation detail. > > The name of the exception is "UnboundLocalError". And the message says > that we referred to a "local variable". > > Also see the language reference: > > "When a name is not found at all, a NameError exception is raised. If > the name refers to a local variable that has not been bound, a > UnboundLocalError exception is raised. UnboundLocalError is a subclass > of NameError." > > spam is referring to a local variable that has not been bound. This is > not an implementation detail. Of course not. What is an implementation detail is that there is a slot waiting to be filled for it, just like Ethan said. It's the existence of pre-allocated slots for locals which is an implementation detail, not whether a name is treated as local or not. >> And if you don't like that argument (although it is a perfectly sound >> and correct argument), think of the module name space: >> >> >> ret = spam >> spam = 23 >> >> will net you a simple NameError, because spam has not yet been created. > > Because module level variables work differently from local variables. But that is an implementation detail. IronPython and Jython use an ordinary dict for local variable namespaces, just like globals. Consider this example from Jython: >>> spam = 9999 >>> def modify(namespace): ... namespace['spam'] = 42 ... >>> def demo(): ... modify(locals()) ... spam = spam ... return spam ... >>> demo() 42 -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sat May 10 23:30:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 May 2014 13:30:03 +1000 Subject: Values and objects In-Reply-To: <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 11, 2014 at 1:17 PM, Steven D'Aprano wrote: > But that is an implementation detail. IronPython and Jython use an > ordinary dict for local variable namespaces, just like globals. Consider > this example from Jython: > >>>> spam = 9999 >>>> def modify(namespace): > ... namespace['spam'] = 42 > ... >>>> def demo(): > ... modify(locals()) > ... spam = spam > ... return spam > ... >>>> demo() > 42 All you're proving here is that, in some Pythons, locals() is writeable. What happens if you remove the "spam = spam" line? Would demo() not then return spam from the global scope, because the variable does not exist at local scope? Every example you've shown is simply giving a value to something that you've created by the normal method of having an assignment inside the function. ChrisA From nelsoncrosby at gmail.com Sun May 11 00:16:06 2014 From: nelsoncrosby at gmail.com (Nelson Crosby) Date: Sat, 10 May 2014 21:16:06 -0700 (PDT) Subject: Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues) In-Reply-To: References: Message-ID: <39c6fc1b-9720-4606-9879-bcb48aa9958b@googlegroups.com> I also believe in this more 'BSD-like' view, but from a business point of view. No one is going to invest in a business that can't guarantee against piracy, and such a business is much less likely to receive profit (see Ardour). Don't get me wrong - I love free software. It's seriously awesome to she what a community can do. But at the same time, some people want to earn a living from writing code. That is simply not possible without proprietary software. From rustompmody at gmail.com Sun May 11 00:48:59 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 10 May 2014 21:48:59 -0700 (PDT) Subject: Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues) In-Reply-To: <39c6fc1b-9720-4606-9879-bcb48aa9958b@googlegroups.com> References: <39c6fc1b-9720-4606-9879-bcb48aa9958b@googlegroups.com> Message-ID: <486fb0f6-4447-4b54-817f-df184c975377@googlegroups.com> On Sunday, May 11, 2014 9:46:06 AM UTC+5:30, Nelson Crosby wrote: > I also believe in this more 'BSD-like' view, but from a business point of view. No one is going to invest in a business that can't guarantee against piracy, and such a business is much less likely to receive profit (see Ardour). > > > > Don't get me wrong - I love free software. It's seriously awesome to she what a community can do. But at the same time, some people want to earn a living from writing code. That is simply not possible without proprietary software. Whenever this (kind of) debate arises people talk of 'Free' vs 'OpenSource' which then becomes an rms vs esr debate. It seems to me that esr gets more press than is his due and the more significant ideological difference between rms and Torvalds gets neglected. rms started working on hurd before Linus was a CS student. Its taken him a good 20 years to admit the mistake http://en.wikipedia.org/wiki/GNU_Hurd#cite_note-fsf-future-of-freedom-12 I believe that he still does not get it - that the mistakes were political more than technical. By contrast, - the Linux kernel targeting hardware for which it was never intended - perl running equally on DOS and unix, (with all due respect python, ruby etc just followed the lead) - Samba talking to Windows as though it were Windows itself all show that some amount of guerrilla mindset is necessary From steve+comp.lang.python at pearwood.info Sun May 11 01:11:56 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2014 05:11:56 GMT Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 May 2014 13:30:03 +1000, Chris Angelico wrote: > On Sun, May 11, 2014 at 1:17 PM, Steven D'Aprano > wrote: >> But that is an implementation detail. IronPython and Jython use an >> ordinary dict for local variable namespaces, just like globals. >> Consider this example from Jython: >> >>>>> spam = 9999 >>>>> def modify(namespace): >> ... namespace['spam'] = 42 >> ... >>>>> def demo(): >> ... modify(locals()) >> ... spam = spam >> ... return spam >> ... >>>>> demo() >> 42 > > All you're proving here is that, in some Pythons, locals() is writeable. > What happens if you remove the "spam = spam" line? Would demo() not then > return spam from the global scope, Yes, this. See my previous email, and take careful note of Rule #2: in the absence of a binding operation, variables are not treated as local. > because the variable does not exist at local scope? No to this. Consider this example: >>> spam = 9999 >>> def modify(namespace): ... namespace['spam'] = 42 ... >>> def demo2(): ... assert 'spam' not in locals() ... modify(locals()) ... assert 'spam' in locals() ... return spam ... >>> demo2() 9999 This proves that the spam variable *does* exist in locals, but it is not seen because the "return spam" doesn't check the local scope, so it sees the global spam. Sadly, the version of Jython I have doesn't provide a working dis module, but if it did I expect it would show the equivalent of what CPython does: the first version uses LOAD_FAST to look up "spam", and the second version used LOAD_GLOBAL (a misnomer since it doesn't *just* look up globals). > Every example you've shown is simply giving a value to > something that you've created by the normal method of having an > assignment inside the function. Nonsense. Look at the original examples again, more closely. Here they are again, this time with comments: def test(): if False: spam = None # Dead code, never executed. d = locals() d['spam'] = 23 # Not a normal assignment. return spam def test(): locals()['spam'] = 42 # Not a normal assignment. return spam spam = None # Dead code. and from my reply to Devin: def modify(namespace): namespace['spam'] = 42 def demo(): modify(locals()) # Not an ordinary assignment. spam = spam # Where does the initial value of spam come from? return spam The *only* purpose of the dead code in the two test() functions is to force the compiler to use LOAD_FAST (or equivalent) rather than LOAD_GLOBAL. But they aren't ever executed. At no time do I use normal name binding assignment to create local variables. In the demo() function, if I expand the line "spam = spam" out: temp = spam # Look up of spam occurs first. spam = temp # Binding occurs second. the difficulty should be even more obvious. Where does the value of spam come from before the binding? The answer is that it comes from writing directly to the namespace (a dict). There is no fixed slot for spam waiting for a value, because Jython and IronPython don't use fixed slots. There's only a dict. If we were using globals, it would be be more obvious what was going on, and there would be no argument about whether or not a variable exists before you give it a value. The answer would be, of course it doesn't exist before it has a value. Python declarations (whether implicit or explicit) don't create variables, they just instruct the compiler how to perform lookups on them. # Global scope print spam # fails, because there is no spam variable yet "spam" in globals() # returns False globals()['spam'] = 42 # now it exists spam = spam # a no-op print spam It's only because CPython is special, and locals() is special, that the equivalent code is indeterminate inside functions. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sun May 11 01:22:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 May 2014 15:22:23 +1000 Subject: Values and objects In-Reply-To: <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 11, 2014 at 3:11 PM, Steven D'Aprano wrote: > Nonsense. Look at the original examples again, more closely. Here they > are again, this time with comments: > > def test(): > if False: spam = None # Dead code, never executed. > d = locals() > d['spam'] = 23 # Not a normal assignment. > return spam > > def test(): > locals()['spam'] = 42 # Not a normal assignment. > return spam > spam = None # Dead code. > > > The *only* purpose of the dead code in the two test() functions is to > force the compiler to use LOAD_FAST (or equivalent) rather than > LOAD_GLOBAL. In a C-like language, locals are created by a declaration, and assigned a value separately. In Python, locals are created by the presence of assignment within the function, which in simple cases coincides with giving the value to it; but guarding the assignment with "if False" prevents the giving of the value, while still being an assignment for the sake of creating a local variable. Same if the assignment happens further down, or even in the same statement ("spam = spam"). It's still an assignment, so it has the declarative effect of telling the compiler "this is now local, unless declared global/nonlocal". It's that declaration that creates the variable, not changing locals(). ChrisA From rustompmody at gmail.com Sun May 11 01:31:57 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 10 May 2014 22:31:57 -0700 (PDT) Subject: Values and objects In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3fb2d95e-2fb6-43a5-a725-c6d38444b80c@googlegroups.com> On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote: > > Personally, I don't imagine that there ever could be a language where > variables were first class values *exactly* the same as ints, strings, > floats etc. Otherwise, how could you tell the difference between a > function which operated on the variable itself, and one which operated on > the value contained by the value? Its standard fare in theorem proving languages - see eg twelf: https://www.cs.cmu.edu/~fp/papers/cade99.pdf where the distinction is made between variables in the meta-language (ie twelf itself) and variables in the the object theory What you mean by *exactly* the same mean, I am not sure... Also I note that I was not meaning first-classness of variables in C in that literal sense. Its just I consider them more first-class than say Pascal but less than say Lisp. [The wikipedia link that Chris posted links to an article that makes the claim that firstclassness is not really defined but can be used in a vague/relative way ] From harrismh777 at gmail.com Sun May 11 01:36:55 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 11 May 2014 00:36:55 -0500 Subject: Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues) References: <39c6fc1b-9720-4606-9879-bcb48aa9958b@googlegroups.com> Message-ID: <536F0C77.5030108@gmail.com> On 5/10/14 11:16 PM, Nelson Crosby wrote: > I also believe in this more 'BSD-like' view, but from a business > point of view. No one is going to invest in a business that can't > guarantee against piracy, and such a business is much less likely > to receive profit (see Ardour). > > Don't get me wrong - I love free software. It's seriously awesome > to see what a community can do. But at the same time, some people want > to earn a living from writing code. That is simply not possible > without proprietary software. > That's just the point... The twenty-first century is not going to be about making money by moving bits around a network, nor about making money writing code. It is going to be about making money|living (whatever that means) by leveraging free networking (think libre box) and by leveraging free (as in libre) software and libre software engineering. In other words, no longer are coders going to make a living writing proprietary code; rather, coders are going to make a living leveraging their skill writing libre software (in the specialized problem domain needing their resources --- free agents, have skill, will travel, or connect). So, I go to work for some technical scientific research outfit that just got a federal grant for yadda yadda... and I bring in my toolkit|toobox (julia, haskell, python, C++ &c whatever) and I make a living coding within that specialized domain. I don't market the app (& they don't either). The killer app in the 21st century IS the unix distro (gnu/linux), and the toolbox is (mine, or yours). We are going to stop purchasing software across the board, and we are going to share. In the process we are going to make our livings with our skills, services, innovations towards specialized problem domains through leveraged technical specialty, and by working together to better the whole. This is already occurring. marcus From ethan at stoneleaf.us Sun May 11 00:46:44 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 10 May 2014 21:46:44 -0700 Subject: Values and objects In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> Message-ID: <536F00B4.2020100@stoneleaf.us> [accidentally went off-list; sorry] On 05/10/2014 02:03 PM, Devin Jeanpierre wrote: > > spam is referring to a local variable that has not been bound. This is > not an implementation detail. The implementation detail is that in cpython there is a spot already reserved for what will be the 'spam' variable, as opposed to the module level where no such spots are reserved. > Because module level variables work differently from local variables. Not by language definition. There are pythons where modifying function locals works, but the working or not-working is not a language guarantee. -- ~Ethan~ From ethan at stoneleaf.us Sun May 11 01:42:13 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 10 May 2014 22:42:13 -0700 Subject: Values and objects In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536F0DB5.9050905@stoneleaf.us> On 05/10/2014 10:22 PM, Chris Angelico wrote: > It's that declaration that creates the variable, not > changing locals(). A Python variable is a name bound to a value (and values, of course, are objects). If you don't have both pieces, you don't have a Python variable. -- ~Ethan~ From rosuav at gmail.com Sun May 11 02:08:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 May 2014 16:08:09 +1000 Subject: [Python-Dev] Values and objects In-Reply-To: <536F0A48.5040604@stoneleaf.us> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536E9C3A.7060706@stoneleaf.us> <536F0A48.5040604@stoneleaf.us> Message-ID: [ I think you meant for this to go to python-list, not python-dev. Sending this to python-list. ] On Sun, May 11, 2014 at 3:27 PM, Ethan Furman wrote: > Seriously though, error messages are chosen to provide a simple and clear > description that will help the user track down what went wrong, not for > enshrining in exact detail the language semantics. Would you really rather > have: > > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in func > UnboundLocalError: the name 'not_here' does not yet exist as you have not > yet assigned anything to it so there is currently no variable by that name > although at some point (in the future of this function, or perhaps in a > branch that has been passed and did not execute) you will or did assign > something to it so it will exist in the future of this function or may exist > at this point in a future run of this function. > > or: > > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in func > UnboundLocalError: local variable 'not_here' referenced before assignment The way I'd say it is: The error text should be brief, and can leave stuff out, but should not actively *conflict* with language semantics. So if it says there's a local variable that hasn't been assigned, I would expect it to mean that there is, according to language semantics, a local variable that can be in a state of not-being-assigned to. If that's not the case, the message definitely needs to be changed, because it's actively misleading. ChrisA From harrismh777 at gmail.com Sun May 11 02:17:55 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 11 May 2014 01:17:55 -0500 Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/10/14 8:42 AM, Roy Smith wrote: > Ars Technica article a couple of days ago, about Fortran, and what is > likely to replace it: > > http://tinyurl.com/mr54p96 > uhm, yeeah! 'Julia' is going to give everyone a not so small run for competition; justifiably so, not just against FORTRAN. Julia is Matlab and R, Python, Lisp, Scheme; all rolled together on steroids. Its amazing as a dynamic language, and its fast, like lightning fast as well as multiprocessing (parallel processing) at its core. Its astounding, really. Its number concept is unified, BigFloats are by default arbitrary precision with full scientific and transcendental functions built-in, everything complex just works, and did I mention its fast? The bench-marks are within 2x of C across the boards; makes Matlab look like a rock, and is well ahead of python (NumPy SciPy) for technical computing. Julia is still very much beta in my opinion but its maturing fast. Its open free (libre) and cross platform and did I mention it flatout screams? Not only will it replace FORTRAN completely if things keep progressing, but also Matlab, Mathematica, NumPy, & SciPy (and others). Keep your eye on her fellows. marcus From subhabangalore at gmail.com Sun May 11 02:20:32 2014 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sat, 10 May 2014 23:20:32 -0700 (PDT) Subject: Question on Debugging a code line In-Reply-To: <283e285b-4ab3-4ec7-a8be-4f1e047d9645@googlegroups.com> References: <283e285b-4ab3-4ec7-a8be-4f1e047d9645@googlegroups.com> Message-ID: On Sunday, May 11, 2014 12:57:34 AM UTC+5:30, subhaba... at gmail.com wrote: > Dear Room, > > > > I was trying to go through a code given in http://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm[ Forward Backward is an algorithm of Machine Learning-I am not talking on that > > I am just trying to figure out a query on its Python coding.] > > > > I came across the following codes. > > > > >>> states = ('Healthy', 'Fever') > > >>> end_state = 'E' > > >>> observations = ('normal', 'cold', 'dizzy') > > >>> start_probability = {'Healthy': 0.6, 'Fever': 0.4} > > >>> transition_probability = { > > 'Healthy' : {'Healthy': 0.69, 'Fever': 0.3, 'E': 0.01}, > > 'Fever' : {'Healthy': 0.4, 'Fever': 0.59, 'E': 0.01}, > > } > > >>> emission_probability = { > > 'Healthy' : {'normal': 0.5, 'cold': 0.4, 'dizzy': 0.1}, > > 'Fever' : {'normal': 0.1, 'cold': 0.3, 'dizzy': 0.6}, > > } > > > > def fwd_bkw(x, states, a_0, a, e, end_st): > > L = len(x) > > fwd = [] > > f_prev = {} #THE PROBLEM > > # forward part of the algorithm > > for i, x_i in enumerate(x): > > f_curr = {} > > for st in states: > > if i == 0: > > # base case for the forward part > > prev_f_sum = a_0[st] > > else: > > prev_f_sum = sum(f_prev[k]*a[k][st] for k in states) ## > > > > f_curr[st] = e[st][x_i] * prev_f_sum > > > > fwd.append(f_curr) > > f_prev = f_curr > > > > p_fwd = sum(f_curr[k]*a[k][end_st] for k in states) > > > > As this value was being called in prev_f_sum = sum(f_prev[k]*a[k][st] for k in states marked ## > > I wanted to know what values it is generating. > > So, I had made the following experiment, after > > for i, x_i in enumerate(x): > > I had put print f_prev > > but I am not getting how f_prev is getting the values. > > > > Here, > > x=observations, > > states= states, > > a_0=start_probability, > > a= transition_probability, > > e=emission_probability, > > end_st= end_state > > > > Am I missing any minor aspect? > > Code is running fine. > > > > If any one of the esteemed members may kindly guide me. > > > > Regards, > > Subhabrata Banerjee. Dear Sir, Thank you for your kind reply. I will check. Regards, Subhabrata Banerjee. From marko at pacujo.net Sun May 11 02:21:59 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 11 May 2014 09:21:59 +0300 Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> <3fb2d95e-2fb6-43a5-a725-c6d38444b80c@googlegroups.com> Message-ID: <87ppjksum0.fsf@elektro.pacujo.net> Rustom Mody : > On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote: >> >> Personally, I don't imagine that there ever could be a language where >> variables were first class values *exactly* the same as ints, >> strings, floats etc. > > [...] > > What you mean by *exactly* the same mean, I am not sure... Lisp variables (symbols) are on an equal footing with other objects. IOW, lisp variables are objects in the heap. Marko From harrismh777 at gmail.com Sun May 11 02:25:49 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 11 May 2014 01:25:49 -0500 Subject: Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues) In-Reply-To: References: Message-ID: <536F17ED.6060102@gmail.com> On 5/10/14 6:35 PM, Chris Angelico wrote: > Instead, what we have is a world in which Python can be used to write > closed-source software, LibreOffice Writer will happily open a > Microsoft Word document, Samba communicates with Windows computers, > libc can be linked to non-free binaries, etc, etc, etc. Yes, that > means the open source community can't wield its weight against > closed-source. Its not open source that's the big deal. Its freedom that's the big deal. Many have latched onto open source because its efficient. But that was the wrong reason to latch onto it! Libre software is the ONLY way to fight NSA GCHQ. Libre software is the ONLY way to ensure privacy and interoperability --- its a huge paradox. Libre software and libre Internet are absolutely paramount for the 21st century. I may not live to see it fully, but I have absolutely no doubt that its coming. There is going to be one whopping paradigm shift Chris. marcus From harrismh777 at gmail.com Sun May 11 02:25:49 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 11 May 2014 01:25:49 -0500 Subject: Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues) References: Message-ID: <536F17ED.6060102@gmail.com> On 5/10/14 6:35 PM, Chris Angelico wrote: > Instead, what we have is a world in which Python can be used to write > closed-source software, LibreOffice Writer will happily open a > Microsoft Word document, Samba communicates with Windows computers, > libc can be linked to non-free binaries, etc, etc, etc. Yes, that > means the open source community can't wield its weight against > closed-source. Its not open source that's the big deal. Its freedom that's the big deal. Many have latched onto open source because its efficient. But that was the wrong reason to latch onto it! Libre software is the ONLY way to fight NSA GCHQ. Libre software is the ONLY way to ensure privacy and interoperability --- its a huge paradox. Libre software and libre Internet are absolutely paramount for the 21st century. I may not live to see it fully, but I have absolutely no doubt that its coming. There is going to be one whopping paradigm shift Chris. marcus From steve+comp.lang.python at pearwood.info Sun May 11 02:40:44 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2014 06:40:44 GMT Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536f1b6c$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 May 2014 22:42:13 -0700, Ethan Furman wrote: > On 05/10/2014 10:22 PM, Chris Angelico wrote: >> It's that declaration that creates the variable, not changing locals(). > > A Python variable is a name bound to a value (and values, of course, are > objects). If you don't have both pieces, you don't have a Python > variable. +1 Well said. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Sun May 11 02:48:34 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 10 May 2014 23:48:34 -0700 (PDT) Subject: Values and objects In-Reply-To: <87ppjksum0.fsf@elektro.pacujo.net> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> <3fb2d95e-2fb6-43a5-a725-c6d38444b80c@googlegroups.com> <87ppjksum0.fsf@elektro.pacujo.net> Message-ID: <9d950f96-3457-4c13-b9e2-8e4e1b20cd54@googlegroups.com> On Sunday, May 11, 2014 11:51:59 AM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody : > > > > > On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote: > > >> > > >> Personally, I don't imagine that there ever could be a language where > >> variables were first class values *exactly* the same as ints, > >> strings, floats etc. > > > > [...] > > > > What you mean by *exactly* the same mean, I am not sure... > > > > Lisp variables (symbols) are on an equal footing with other objects. > IOW, lisp variables are objects in the heap. But is a symbol a variable?? Sure, by providing a data-structure symbol, lisp provides one of the key building blocks for developing language processing systems. However I would argue that a variable is not a merely a symbol (identifier in more usual programming language-speak) but a relation between identifiers/symbols and some 'rhs' For an (interpreted?) language like python, rhs is naturally value/object For a C like language it is memory. [Just invoking the standard denotational semantics fare: Env : Symbol ? Value for interpreted languages For 'compiled' languages Env : Symbol ? Location (at compile time) Store : Location ? Value (at run time) From rustompmody at gmail.com Sun May 11 03:01:48 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 11 May 2014 00:01:48 -0700 (PDT) Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, May 11, 2014 11:47:55 AM UTC+5:30, Mark H. Harris wrote: > 'Julia' is going to give everyone a not so small run for competition; > justifiably so, not just against FORTRAN. > > > Julia is Matlab and R, Python, Lisp, Scheme; all rolled together on > steroids. Its amazing as a dynamic language, and its fast, like > lightning fast as well as multiprocessing (parallel processing) at its > core. Its astounding, really. I think the big thing is that Julia is cooperating rather than competing https://github.com/JuliaLang/IJulia.jl If they can carry this off, its a definite winning strategy From steve+comp.lang.python at pearwood.info Sun May 11 03:09:27 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2014 07:09:27 GMT Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 May 2014 01:17:55 -0500, Mark H Harris wrote: > On 5/10/14 8:42 AM, Roy Smith wrote: >> Ars Technica article a couple of days ago, about Fortran, and what is >> likely to replace it: >> >> http://tinyurl.com/mr54p96 >> >> > uhm, yeeah! > > 'Julia' is going to give everyone a not so small run for competition; > justifiably so, not just against FORTRAN. That and two hundred other languages. Good languages (for some definition of "good") are a dime a dozen. Miranda, Rust, Go, D, Ceylon, Coffeescript, F#, Scala, Lua, Erlang, Eiffel, Ocaml, Haskell, Kotlin, Grovy, Clojure, Dart, Mercury, ML... the list of "amazing", "astounding" languages is never ending. Very few of them take over the world, and those that do rarely do so due to technical excellence. (BASIC, Java, PHP, Javascript ...) Some of them, like Haskell, influence other languages without ever being popular themselves. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun May 11 03:13:20 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2014 07:13:20 GMT Subject: Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues) References: <39c6fc1b-9720-4606-9879-bcb48aa9958b@googlegroups.com> Message-ID: <536f2310$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 May 2014 21:16:06 -0700, Nelson Crosby wrote: > I also believe in this more 'BSD-like' view, but from a business point > of view. No one is going to invest in a business that can't guarantee > against piracy, and such a business is much less likely to receive > profit (see Ardour). I think that's nonsense. Look at Red Hat, and Ubuntu. Their software is free to copy and free to distribute, although Red Hat does make it more difficult to copy actual RHEL, you can copy and distribute the re-branded RHEL known as Centos completely free of charge. Selling physical product is not the only way to make money from software, and in fact, most programmers are not paid to write software for sale. They are paid to write in-house applications which are never distributed outside of the company paying for their labour. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun May 11 03:24:06 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2014 07:24:06 GMT Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> Message-ID: <536f2595$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 May 2014 18:28:43 -0700, Ethan Furman wrote: > On 05/10/2014 04:18 PM, Chris Angelico wrote: >> On Sun, May 11, 2014 at 5:10 AM, Ethan Furman >> wrote: >>> And if you don't like that argument (although it is a perfectly sound >>> and correct argument), think of the module name space: >>> >>> >>> ret = spam >>> spam = 23 >>> >>> will net you a simple NameError, because spam has not yet been >>> created. >> >> What about this, though: >> >> ret = int >> int = 23 >> >> That will *not* net you a NameError, because 'int' exists in an outer >> scope (builtins). You can create a new module-scope variable and it >> will immediately begin to shadow a builtin; you can delete that >> variable and it will immediately cease to shadow that builtin. That's >> the difference I'm talking about. With function-local variables, they >> all have to exist (as other responses confirmed, that *is* a language >> guarantee), even though some of them aren't bound to anything yet. > > Well, with function variables they have to exist *when you use them*. ;) > > This seems like more of a scoping issue than a "can we create variables > in Python" issue. Correct. The first line "ret = int" does a name lookup for "int", finds it in the built-ins, and binds it to "ret". The second line "int = 23" binds the object 23 to the name "int" in the current namespace, i.e. the globals. It has nothing to do with how variables are created. By default, you can't do that inside a function because function scoping is special, not because function locals are kept inside slots. (1) They aren't always, not even in CPython, and (2) even if they are, an implementation could hide that fact and provide the same behaviour. I say "by default" because with byte-code hacking you can. Suppose I write the function: def special(): spam = spam process(spam) Under normal circumstances, this will fail, because the assignment "spam = ..." tells the compiler that spam is a local, and so the lookup for "... = spam" does a LOAD_FAST which fails. But if I hack the byte code, I can turn that LOAD_FAST into a LOAD_GLOBAL, which then gives behaviour just like Lua: spam (the local variable) = spam (the global variable) Of course, this isn't a feature of Python the language. But with sufficient byte-code hacking skills, it is possible. > I am curious, though, what other python's do with respect to function > variables. As far as I know, Jython and IronPython store them in a dict namespace, just like globals. See my previous responses to Chris. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun May 11 03:29:07 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2014 07:29:07 GMT Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536ED24B.7040300@stoneleaf.us> Message-ID: <536f26c2$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 May 2014 11:59:21 +1000, Chris Angelico wrote: > On Sun, May 11, 2014 at 11:28 AM, Ethan Furman > wrote: >> Well, with function variables they have to exist *when you use them*. >> ;) >> >> This seems like more of a scoping issue than a "can we create variables >> in Python" issue. >> >> I am curious, though, what other python's do with respect to function >> variables. > > Variables exist in scope. Apart from assembly language, where registers > have universal scope, every language I know of has some concept of > scope. BASIC. > (REXX is very different from most, in that "PROCEDURE EXPOSE" > isn't at all your classic notion of scoping, but there's still the > concept that there can be two variables with the same name.) When you > create one, you create it in a particular scope, and that's how it must > be. Yes. But when do you create it? At declaration time, or when a value is bound to it? # Ensure spam does not exist. try: del spam except NameError: pass assert "spam" not in globals() # Declare spam. global spam print ("spam" in globals()) # prints False print (spam) # raises NameError The same applies to locals. Whether a slot is pre-allocated or not, the variable doesn't exist until there is a value bound to the name. -- Steven D'Aprano http://import-that.dreamwidth.org/ From subhabangalore at gmail.com Sun May 11 03:45:45 2014 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sun, 11 May 2014 00:45:45 -0700 (PDT) Subject: Question on Debugging a code line In-Reply-To: References: <283e285b-4ab3-4ec7-a8be-4f1e047d9645@googlegroups.com> Message-ID: On Sunday, May 11, 2014 11:50:32 AM UTC+5:30, subhaba... at gmail.com wrote: > On Sunday, May 11, 2014 12:57:34 AM UTC+5:30, subhaba... at gmail.com wrote: > > > Dear Room, > > > > > > > > > > > > I was trying to go through a code given in http://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm[ Forward Backward is an algorithm of Machine Learning-I am not talking on that > > > > > > I am just trying to figure out a query on its Python coding.] > > > > > > > > > > > > I came across the following codes. > > > > > > > > > > > > >>> states = ('Healthy', 'Fever') > > > > > > >>> end_state = 'E' > > > > > > >>> observations = ('normal', 'cold', 'dizzy') > > > > > > >>> start_probability = {'Healthy': 0.6, 'Fever': 0.4} > > > > > > >>> transition_probability = { > > > > > > 'Healthy' : {'Healthy': 0.69, 'Fever': 0.3, 'E': 0.01}, > > > > > > 'Fever' : {'Healthy': 0.4, 'Fever': 0.59, 'E': 0.01}, > > > > > > } > > > > > > >>> emission_probability = { > > > > > > 'Healthy' : {'normal': 0.5, 'cold': 0.4, 'dizzy': 0.1}, > > > > > > 'Fever' : {'normal': 0.1, 'cold': 0.3, 'dizzy': 0.6}, > > > > > > } > > > > > > > > > > > > def fwd_bkw(x, states, a_0, a, e, end_st): > > > > > > L = len(x) > > > > > > fwd = [] > > > > > > f_prev = {} #THE PROBLEM > > > > > > # forward part of the algorithm > > > > > > for i, x_i in enumerate(x): > > > > > > f_curr = {} > > > > > > for st in states: > > > > > > if i == 0: > > > > > > # base case for the forward part > > > > > > prev_f_sum = a_0[st] > > > > > > else: > > > > > > prev_f_sum = sum(f_prev[k]*a[k][st] for k in states) ## > > > > > > > > > > > > f_curr[st] = e[st][x_i] * prev_f_sum > > > > > > > > > > > > fwd.append(f_curr) > > > > > > f_prev = f_curr > > > > > > > > > > > > p_fwd = sum(f_curr[k]*a[k][end_st] for k in states) > > > > > > > > > > > > As this value was being called in prev_f_sum = sum(f_prev[k]*a[k][st] for k in states marked ## > > > > > > I wanted to know what values it is generating. > > > > > > So, I had made the following experiment, after > > > > > > for i, x_i in enumerate(x): > > > > > > I had put print f_prev > > > > > > but I am not getting how f_prev is getting the values. > > > > > > > > > > > > Here, > > > > > > x=observations, > > > > > > states= states, > > > > > > a_0=start_probability, > > > > > > a= transition_probability, > > > > > > e=emission_probability, > > > > > > end_st= end_state > > > > > > > > > > > > Am I missing any minor aspect? > > > > > > Code is running fine. > > > > > > > > > > > > If any one of the esteemed members may kindly guide me. > > > > > > > > > > > > Regards, > > > > > > Subhabrata Banerjee. > > > > Dear Sir, > > Thank you for your kind reply. I will check. > > Regards, > > Subhabrata Banerjee. Dear Sir, Thank you. It worked. I made another similar statement over another set of values on your reply it went nice. Regards, Subhabrata Banerjee. From jpiitula at ling.helsinki.fi Sun May 11 04:26:41 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 11 May 2014 11:26:41 +0300 Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> <3fb2d95e-2fb6-43a5-a725-c6d38444b80c@googlegroups.com> <87ppjksum0.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Rustom Mody: > > > On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote: > >> > >> Personally, I don't imagine that there ever could be a language > >> where variables were first class values *exactly* the same as > >> ints, strings, floats etc. > > > > [...] > > > > What you mean by *exactly* the same mean, I am not sure... > > Lisp variables (symbols) are on an equal footing with other objects. > IOW, lisp variables are objects in the heap. Only some, or only in quite old or special members of the family. But yes, I suppose when Lisp was still LISP, it was the kind of language that Steven fails to imagine in the quotation above. Variables really were symbols, which still are objects that can be passed around and stored in data structures. Or maybe not - wasn't the essential binding component (originally an "association list", later a more abstract "environment", called "namespace" in Python culture) separate from the symbol even then? Global bindings aside. But default in Common Lisp is lexical binding, and Scheme has only lexical bindings. An ordinary lexical variable is not an object in any reasonable sense that I can see. (let ((f (let ((x 3)) (lambda () x)))) ;; The binding of x is still relevant here but not in scope and not ;; accessible through the symbol x (funcall f)) ;==> 3 # That's (lambda f : f())((lambda x : (lambda : x))(3)) #=> 3 # Roughly, f = (lambda x : (lambda : x))(3) ; f() #=> 3 From rustompmody at gmail.com Sun May 11 04:48:07 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 11 May 2014 01:48:07 -0700 (PDT) Subject: Values and objects In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> <3fb2d95e-2fb6-43a5-a725-c6d38444b80c@googlegroups.com> <87ppjksum0.fsf@elektro.pacujo.net> Message-ID: <455a3dc0-c492-498b-9593-d30b8a967898@googlegroups.com> On Sunday, May 11, 2014 1:56:41 PM UTC+5:30, Jussi Piitulainen wrote: > Marko Rauhamaa writes: > > Rustom Mody: > > > > > On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote: > > >> > > >> Personally, I don't imagine that there ever could be a language > > >> where variables were first class values *exactly* the same as > > >> ints, strings, floats etc. > > > > > > > > [...] > > > > > > > > What you mean by *exactly* the same mean, I am not sure... > > > > > > Lisp variables (symbols) are on an equal footing with other objects. > > > IOW, lisp variables are objects in the heap. > > > Only some, or only in quite old or special members of the family. But > yes, I suppose when Lisp was still LISP, it was the kind of language > that Steven fails to imagine in the quotation above. Variables really > were symbols, which still are objects that can be passed around and > stored in data structures. Or maybe not - wasn't the essential binding > component (originally an "association list", later a more abstract > "environment", called "namespace" in Python culture) separate from the > symbol even then? Global bindings aside. > A symbol is a first-class data structure in any lisp (that I know) http://en.wikipedia.org/wiki/Homoiconicity is a defining characteristic of lisp Environments are first class in many schemes: http://sicp.ai.mit.edu/Fall-2004/manuals/scheme-7.5.5/doc/scheme_14.html (The '+'es there indicate its an MIT scheme extension; but its quite common) In my understanding a symbol can be called a variable only wrt some environment IOW there is no meaning to the word 'variable' without some notion of scope. I am not sure what your references to old and new lisps and static vs dynamic scope has to do with this. Or are you saying that in the 1960s lisps, a symbol was the string (name) along with its (dynamic binding) stack?? Python to qualify for this not only would the namespacing of locals have to be systematic with globals, the nesting structure of environments would have to be introspectively available as in the scheme example. Note the functions: environment-parent and environment-bound-names From r.gayler at gmail.com Sun May 11 02:56:02 2014 From: r.gayler at gmail.com (Ross Gayler) Date: Sun, 11 May 2014 16:56:02 +1000 Subject: What is the difference between 32 and 64 bit Python on Windows 7 64 bit? Message-ID: Hi, I want to install Python on a PC with 16GB of RAM and the 64 bit version of Windows 7. I want Python to be able to use as much as possible of the RAM. When I install the 64 bit version of Python I find that sys.maxint == 2**31 - 1 Whereas the Pythpon installed on my 64 bit linux system returns sys.maxint == 2**63 - 1. It looks to me as though 32 and 64 bit versions of Python on 64 bit Windows are both really 32 bit Python, differing only in how they interact with Windows. So I wouldn't expect 64 bit Python running on 64 bit Windows to allow the large data struictures I could have with 64 bit Python running on 64 bit linux. Is that true?I have spent a couple of hours searching for a definitive description of the difference between the 32 and 64 bit versions of Python for Windows and haven't found anything. Thanks Ross -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun May 11 05:36:49 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 11 May 2014 05:36:49 -0400 Subject: What is the difference between 32 and 64 bit Python on Windows 7 64 bit? In-Reply-To: References: Message-ID: On 5/11/2014 2:56 AM, Ross Gayler wrote: > Hi, > > I want to install Python on a PC with 16GB of RAM and the 64 bit version > of Windows 7. > I want Python to be able to use as much as possible of the RAM. > > When I install the 64 bit version of Python I find that sys.maxint == > 2**31 - 1 Since sys.maxint is gone in 3.x, you must be using some version of 2.x. Do yourself a favor and install 3.4 unless you absolutely need 2.x. With 3.4: >>> a = [None]*1000000000 >>> sys.getsizeof(a) 8000000064 That is 1000000000 8-byte pointers, as I expected. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sun May 11 08:03:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 11 May 2014 13:03:06 +0100 Subject: Question on Debugging a code line In-Reply-To: References: <283e285b-4ab3-4ec7-a8be-4f1e047d9645@googlegroups.com> Message-ID: On 11/05/2014 08:45, subhabangalore at gmail.com wrote: [268 lines snipped] Would you please use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From jpiitula at ling.helsinki.fi Sun May 11 08:22:33 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 11 May 2014 15:22:33 +0300 Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> <3fb2d95e-2fb6-43a5-a725-c6d38444b80c@googlegroups.com> <87ppjksum0.fsf@elektro.pacujo.net> <455a3dc0-c492-498b-9593-d30b8a967898@googlegroups.com> Message-ID: Rustom Mody writes: > On Sunday, May 11, 2014 1:56:41 PM UTC+5:30, Jussi Piitulainen wrote: > > Marko Rauhamaa writes: > > > Rustom Mody: > > > > > > > On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote: > > > >> > > > >> Personally, I don't imagine that there ever could be a > > > >> language where variables were first class values *exactly* > > > >> the same as ints, strings, floats etc. > > > > > > [...] > > > > > > What you mean by *exactly* the same mean, I am not sure... > > > > > Lisp variables (symbols) are on an equal footing with other > > > objects. IOW, lisp variables are objects in the heap. > > > > Only some, or only in quite old or special members of the > > family. But yes, I suppose when Lisp was still LISP, it was the > > kind of language that Steven fails to imagine in the quotation > > above. Variables really were symbols, which still are objects that > > can be passed around and stored in data structures. Or maybe not - > > wasn't the essential binding component (originally an "association > > list", later a more abstract "environment", called "namespace" in > > Python culture) separate from the symbol even then? Global > > bindings aside. > > A symbol is a first-class data structure in any lisp (that I know) > http://en.wikipedia.org/wiki/Homoiconicity is a defining characteristic of lisp I don't see the relevance of these observations. The claim was that Lisp variables are symbols. What do you write in Common Lisp in place of the "..." to have the following evaluate to the the value of the variable x? (let ((x (f)) (y 'x)) (... y ...)) No, (eval y) is not an answer, and (symbol-value y) is not an answer: these do not do the thing at all. To suggest (progn y x) is to concede my point that there is no way to get the value of x through the symbol x that is the value of y. > Environments are first class in many schemes: > http://sicp.ai.mit.edu/Fall-2004/manuals/scheme-7.5.5/doc/scheme_14.html > (The '+'es there indicate its an MIT scheme extension; but its quite common) It's not very common. A couple of top-level environment specifiers are in the reports (scheme-report-environment, null-environment, and interaction-environment is optional, if I recall correctly) but the crucial reifier of an arbitrary lexical environment is not, and environment specifiers can only be used as an argument to eval. Even if that were common, it seems to me a joke to say that the symbol itself is the variable, which is the claim that I responded to. It's like saying that pairs of integers are first class variables because they can be interpreted as lexical addresses wrt an environment. You know, (0, 0) refers to the first variable in the current environment frame, (3, 1) to the second variable in a specific ancestor frame, and so on. > In my understanding a symbol can be called a variable only wrt some > environment > > IOW there is no meaning to the word 'variable' without some notion > of scope. Agreed. So you consider it reasonable to say that variables are symbols in Lisp, and then clarify that a symbol means a symbol together with a first-class lexical environment, as if that was implicit in the original claim (and as if such environments were widely available in Lisp)? If so, I admit I've been fooled, and I've spent far too much time on this already. At least I was responding in good faith. > I am not sure what your references to old and new lisps and static > vs dynamic scope has to do with this. I'm saying that lexical variables are not accessible through the symbol that happens to look like the variable in the source code. And I'm saying that it's the lexical variables that need to be considered, because they are the default kind even in Lisp today. Dynamic variables are special. (They are even _called_ special.) I'm not saying that a dynamic variable cannot be accessed through the symbol, because that doesn't seem to be true. (I installed a Common Lisp and experimented a little when I wrote my original response.) > Or are you saying that in the 1960s lisps, a symbol was the string > (name) along with its (dynamic binding) stack?? It seems to be the case today, in Common Lisp, that a special variable is accessible through the symbol. For example, (symbol-value y) would work in my example above if x had been declared special. The dynamic environment is implicit. In the 1960s, before Scheme AFAIUI, things were that way. > Python to qualify for this not only would the namespacing of locals > have to be systematic with globals, the nesting structure of > environments would have to be introspectively available as in the > scheme example. > > Note the functions: environment-parent and environment-bound-names If Marko meant MIT Scheme when he said Lisp, and reification of arbitrary lexical environments when he said symbol, I've responded to a quite different claim than he intended, and spent far too much effort on this. From steve+comp.lang.python at pearwood.info Sun May 11 08:51:08 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2014 12:51:08 GMT Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> <3fb2d95e-2fb6-43a5-a725-c6d38444b80c@googlegroups.com> <87ppjksum0.fsf@elektro.pacujo.net> Message-ID: <536f723c$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 May 2014 11:26:41 +0300, Jussi Piitulainen wrote: > Marko Rauhamaa writes: >> Rustom Mody: >> >> > On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote: >> >> >> >> Personally, I don't imagine that there ever could be a language >> >> where variables were first class values *exactly* the same as ints, >> >> strings, floats etc. >> > >> > [...] >> > >> > What you mean by *exactly* the same mean, I am not sure... >> >> Lisp variables (symbols) are on an equal footing with other objects. >> IOW, lisp variables are objects in the heap. > > Only some, or only in quite old or special members of the family. But > yes, I suppose when Lisp was still LISP, it was the kind of language > that Steven fails to imagine in the quotation above. Variables really > were symbols, which still are objects that can be passed around and > stored in data structures. Or maybe not - wasn't the essential binding > component (originally an "association list", later a more abstract > "environment", called "namespace" in Python culture) separate from the > symbol even then? Global bindings aside. I'm not sure if you are agreeing or disagreeing that variables are values in Common Lisp or not. First you say they are, they you say "maybe not". The point is, it is *logically impossible* for a language to use precisely the same syntax for value-assignment and variable-assignment. Consider the variable called "x", which is bound to the value 23. If the language has a single assignment operator or statement: let y := name; that cannot be used for *both* binding the value 23 to y and binding the variable "x" to y (making y an alias for x). To use Pascal as an example, you cannot use the same declaration for pass- by-value and pass-by-reference, one or the other must use different syntax. function foo(x: integer, var y: integer): integer; Given that declaration, and the function call foo(a, b), x is bound to the value of a, while y is bound to the variable b. In the case of Common List, I count at least four different assignment forms: set, setq, setf, psetq, let plus two unbinding forms: makunbound, fmakunbound but I don't know enough about Lisp to tell you which ones implement binding-to-values and which binding-to-variables, if any. -- Steven D'Aprano http://import-that.dreamwidth.org/ From benjamin.kaplan at case.edu Sun May 11 08:53:23 2014 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 11 May 2014 05:53:23 -0700 Subject: What is the difference between 32 and 64 bit Python on Windows 7 64 bit? In-Reply-To: References: Message-ID: On Sat, May 10, 2014 at 11:56 PM, Ross Gayler wrote: > > Hi, > > I want to install Python on a PC with 16GB of RAM and the 64 bit version of Windows 7. > I want Python to be able to use as much as possible of the RAM. > > When I install the 64 bit version of Python I find that sys.maxint == 2**31 - 1 > Whereas the Pythpon installed on my 64 bit linux system returns sys.maxint == 2**63 - 1. > That comes from the underlying C implementation. 64-bit MSVC still has long int as 32-bit. You need to specify long long int to get a 64-bit number even on a 64-bit compiler. Microsoft is a little nuts on the backwards compatiblity. > It looks to me as though 32 and 64 bit versions of Python on 64 bit Windows are both really 32 bit Python, differing only in how they interact with Windows. So I wouldn't expect 64 bit Python running on 64 bit Windows to allow the large data struictures I could have with 64 bit Python running on 64 bit linux. > > Is that true?I have spent a couple of hours searching for a definitive description of the difference between the 32 and 64 bit versions of Python for Windows and haven't found anything. > long int (the size of an integer) != size_t (the size of an object). 64-bit Python still uses 64-bit pointers so it can still address more than 4GB of memory. It just rolls over into longs after 32-bit int max instead of after 64-bit int max. From sg552 at hotmail.co.uk Sun May 11 09:46:10 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Sun, 11 May 2014 14:46:10 +0100 Subject: Values and objects In-Reply-To: <536eea59$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eea59$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/05/2014 04:11, Steven D'Aprano wrote: > [...] > > And try running > this function in both 2.7 and 3.3 and see if you can explain the > difference: > > def test(): > if False: x = None > exec("x = 1") > return x I must confess to being baffled by what happens in 3.3 with this example. Neither locals() nor globals() has x = 1 immediately before the return statement, so what is exec("x = 1") actually doing? From rustompmody at gmail.com Sun May 11 10:12:11 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 11 May 2014 07:12:11 -0700 (PDT) Subject: Values and objects In-Reply-To: <536f723c$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> <3fb2d95e-2fb6-43a5-a725-c6d38444b80c@googlegroups.com> <87ppjksum0.fsf@elektro.pacujo.net> <536f723c$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <35eb82b8-ca79-438e-bdde-430c6ffbfa3c@googlegroups.com> On Sunday, May 11, 2014 6:21:08 PM UTC+5:30, Steven D'Aprano wrote: > The point is, it is *logically impossible* for a language to use > precisely the same syntax for value-assignment and variable-assignment. > Consider the variable called "x", which is bound to the value 23. If the > language has a single assignment operator or statement: Its called set in classic lisp. Here's an emacs lisp session (the oldest lisp I can lay my hands on) The semicolons are comments like python's # *** Welcome to IELM *** Type (describe-mode) for help. ELISP> (set (quote d) "Hello World") "Hello World" ELISP> (set (quote c) (quote d)) d ELISP> ; those quote-s are getting boring ELISP> (set 'b 'c) c ELISP> ; once more short-form a very common case ELISP> (setq a 'b) b ELISP> ; Now unfold the chain ELISP> ; Level 0 ELISP> 'a a ELISP> ; Level 1 ELISP> a b ELISP> ;Level 2 ELISP> (eval a) c ELISP> ;Level 3 ELISP> (eval (eval a)) d ELISP> ;Level 4 ELISP> (eval (eval (eval a))) "Hello World" ELISP> IOW set UNIFORMLY evaluates its 2 arguments. To get usual assignment like behavior of normal programming languages, one (typically) quotes the first argument. This is a sufficiently common case that it gets its own 'special form' -- setq (ie set-quote) However the more general case in which (the name of)* the variable is evaluated at run-time is always available. * "Name of" is strictly not correct because: ELISP> (symbol-name 'a) "a" However if I dont say the "name of..." its hard to speak in an intelligible way. Here is the relevant intro from the elisp manual: A "symbol" in GNU Emacs Lisp is an object with a name. The symbol name serves as the printed representation of the symbol. In ordinary Lisp use, ... a symbol's name is unique--no two symbols have the same name. A symbol can serve as a variable, as a function name, or to hold a property list. Or it may serve only to be distinct from all other Lisp objects, so that its presence in a data structure may be recognized reliably. tl;dr: Quote-Eval go up and down the 'meta-language' tower just as Lambda-(function)Apply go up and down the functional tower. Elaborated further: http://blog.languager.org/2013/08/applying-si-on-sicp.html From lgabiot at hotmail.com Sun May 11 10:18:04 2014 From: lgabiot at hotmail.com (lgabiot) Date: Sun, 11 May 2014 16:18:04 +0200 Subject: Using threads for audio computing? Message-ID: <536f869c$0$2178$426a74cc@news.free.fr> Hello, I'd like to be able to analyze incoming audio from a sound card using Python, and I'm trying to establish a correct architecture for this. Getting the audio is OK (using PyAudio), as well as the calculations needed, so won't be discussing those, but the general idea of being able at (roughly) the same time: getting audio, and performing calculation on it, while not loosing any incoming audio. I also make the assumption that my calculations on audio will be done faster than the time I need to get the audio itself, so that the application would be almost real time. So far my idea (which works according to the small tests I did) consist of using a Queue object as a buffer for the incoming audio and two threads, one to feed the queue, the other to consume it. The queue could store the audio as a collection of numpy array of x samples. The first thread work would be to put() into the queue new chunks of audio as they are received from the audio card, while the second would get() from the queue chunks and perform the necessary calculations on them. Am I in the right direction, or is there a better general idea? Thanks! From roy at panix.com Sun May 11 10:40:49 2014 From: roy at panix.com (Roy Smith) Date: Sun, 11 May 2014 10:40:49 -0400 Subject: Using threads for audio computing? References: <536f869c$0$2178$426a74cc@news.free.fr> Message-ID: In article <536f869c$0$2178$426a74cc at news.free.fr>, lgabiot wrote: > Hello, > > I'd like to be able to analyze incoming audio from a sound card using > Python, and I'm trying to establish a correct architecture for this. > > Getting the audio is OK (using PyAudio), as well as the calculations > needed, so won't be discussing those, but the general idea of being able > at (roughly) the same time: getting audio, and performing calculation on > it, while not loosing any incoming audio. > I also make the assumption that my calculations on audio will be done > faster than the time I need to get the audio itself, so that the > application would be almost real time. > > > So far my idea (which works according to the small tests I did) consist > of using a Queue object as a buffer for the incoming audio and two > threads, one to feed the queue, the other to consume it. > > > The queue could store the audio as a collection of numpy array of x samples. > The first thread work would be to put() into the queue new chunks of > audio as they are received from the audio card, while the second would > get() from the queue chunks and perform the necessary calculations on them. > > Am I in the right direction, or is there a better general idea? > > Thanks! If you are going to use threads, the architecture you describe seems perfectly reasonable. It's a classic producer-consumer pattern. But, I wonder if you even need anything this complicated. Using a queue to buffer work between threads makes sense if the workload presented is uneven. Sometimes you'll get a burst of work all at once and don't have the capacity to process it in real-time, so you want to buffer it up. I would think sampling audio would be a steady stream. Every x ms, you get another chunk of samples, like clockwork. Is this not the case? From marko at pacujo.net Sun May 11 11:10:16 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 11 May 2014 18:10:16 +0300 Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> <3fb2d95e-2fb6-43a5-a725-c6d38444b80c@googlegroups.com> <87ppjksum0.fsf@elektro.pacujo.net> <9d950f96-3457-4c13-b9e2-8e4e1b20cd54@googlegroups.com> Message-ID: <87eh00s65j.fsf@elektro.pacujo.net> Rustom Mody : > On Sunday, May 11, 2014 11:51:59 AM UTC+5:30, Marko Rauhamaa wrote: >> Lisp variables (symbols) are on an equal footing with other objects. >> IOW, lisp variables are objects in the heap. > > But is a symbol a variable?? Yes. A classic lisp symbol is even more "variable" than most other variables! It can hold *two* values. One is called a value binding and the other one the function binding. Scheme has unified the two; scheme symbols have only one value binding, which can be a function. > Sure, by providing a data-structure symbol, lisp provides one of the > key building blocks for developing language processing systems. > > However I would argue that a variable is not a merely a symbol > (identifier in more usual programming language-speak) but a relation > between identifiers/symbols and some 'rhs' The lisp symbol really is a data object with several fields: I can think of name, value, function and properties. They can be accessed with accessor functions. (Interestingly, scheme doesn't have the 'symbol-value accessor function of lisp's.) If lisp didn't have a way to rebind symbols (i.e., if it were purely functional and had no side effects), they wouldn't be so much variables as substitution spots in the code. > For an (interpreted?) language like python, rhs is naturally > value/object For a C like language it is memory. Symbols in lisp are memory slots, conceptually and physically. Marko From lgabiot at hotmail.com Sun May 11 11:40:27 2014 From: lgabiot at hotmail.com (lgabiot) Date: Sun, 11 May 2014 17:40:27 +0200 Subject: Using threads for audio computing? In-Reply-To: References: <536f869c$0$2178$426a74cc@news.free.fr> Message-ID: <536f99eb$0$2109$426a74cc@news.free.fr> Le 11/05/14 16:40, Roy Smith a ?crit : > In article <536f869c$0$2178$426a74cc at news.free.fr>, > lgabiot wrote: > >> Hello, >> Le 11/05/14 16:40, Roy Smith a ?crit : > If you are going to use threads, the architecture you describe seems > perfectly reasonable. It's a classic producer-consumer pattern. > > But, I wonder if you even need anything this complicated. Using a queue > to buffer work between threads makes sense if the workload presented is > uneven. Sometimes you'll get a burst of work all at once and don't have > the capacity to process it in real-time, so you want to buffer it up. > > I would think sampling audio would be a steady stream. Every x ms, you > get another chunk of samples, like clockwork. Is this not the case? > Thanks for your answer, yes, I guess I can consider audio as a steady stream. PyAudio gives me the audio samples by small chunks (2048 samples at a time for instance, while the sound card gives 48 000 samples/seconds). I accumulate the samples into a numpy array, and once the numpy array has reached the needed size (for instance 5 seconds of audio), I put this numpy array in the queue. So I think you are right in thinking that every 5 seconds I get a new chunk of audio to work on. Then I perform a calculation on this 5 seconds of audio (which needs to be done in less than 5 seconds, so that it will be ready to process the next 5 second chunk), but meanwhile, I need to still constantly get from Pyaudio a new 5 second chunk of audio. Hence my system. I guess if my calculation had to be performed on a small number of samples (i.e. under the value of the Pyaudio buffer size (2048 samples for instance), and that the calculation would last less than the time it takes to get the next 2048 samples from Pyaudio, I wouldn't need the Queue and Thread system. But in my case where I need a large buffer, it might not work? Unless I ask pyaudio to feed me directly with 5 seconds chunks (instead of the usual buffer sizes: 1024, 2048, etc...), which I didn't try, because I hadn't though of it. From marko at pacujo.net Sun May 11 11:46:51 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 11 May 2014 18:46:51 +0300 Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> <3fb2d95e-2fb6-43a5-a725-c6d38444b80c@googlegroups.com> <87ppjksum0.fsf@elektro.pacujo.net> <455a3dc0-c492-498b-9593-d30b8a967898@googlegroups.com> Message-ID: <87a9aos4gk.fsf@elektro.pacujo.net> Jussi Piitulainen : > The claim was that Lisp variables are symbols. What do you write in > Common Lisp in place of the "..." to have the following evaluate to > the the value of the variable x? > > (let ((x (f)) (y 'x)) (... y ...)) > > No, (eval y) is not an answer, and (symbol-value y) is not an answer: > these do not do the thing at all. I must admit I have never used Common Lisp. I can only guess from your question its symbol-value fetches the value from the global symbol table -- even if you replaced let with let* (the two x's are not the same symbol when let is used). I don't see any practical reason for that limitation. If you allow setq/setf/set!, you have no reason to disallow symbol-value on a local variable. Marko From rtomek at ceti.pl Sun May 11 12:09:53 2014 From: rtomek at ceti.pl (Tomasz Rola) Date: Sun, 11 May 2014 18:09:53 +0200 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140511160952.GA5383@tau1.ceti.pl> On Sun, May 11, 2014 at 07:09:27AM +0000, Steven D'Aprano wrote: > On Sun, 11 May 2014 01:17:55 -0500, Mark H Harris wrote: > > > On 5/10/14 8:42 AM, Roy Smith wrote: > >> Ars Technica article a couple of days ago, about Fortran, and what is > >> likely to replace it: > >> > >> http://tinyurl.com/mr54p96 > >> > >> > > uhm, yeeah! > > > > 'Julia' is going to give everyone a not so small run for competition; > > justifiably so, not just against FORTRAN. > > That and two hundred other languages. > Given that Fortran is here for almost 60 years and lot of effort has been spent to keep it backwards compatible (AFAIK), I wouldn't hold my breath. Something may look like cool and great, but wait ten years and see if after major language revision you can still (more or less) easily run your existing huge projects with it. Does it require to give another option to compiler or does it require spending hours or weeks deep in the code (possibly introducing subtle bugs, too)? So far, in my opinion, very few languages can stand this test (or perhaps none at all). Strong candidates are C, Fortran, Common Lisp, and unfortunately, Java (I can only talk about those which I happened to use and checked a bit, but not extensively). I'm not really sure about Python, haven't had time/energy to check yet (but going 1.5->2.x was painless to me). > Good languages (for some definition of "good") are a dime a dozen. > Miranda, Rust, Go, D, Ceylon, Coffeescript, F#, Scala, Lua, Erlang, > Eiffel, Ocaml, Haskell, Kotlin, Grovy, Clojure, Dart, Mercury, ML... the > list of "amazing", "astounding" languages is never ending. Very few of > them take over the world, and those that do rarely do so due to technical > excellence. (BASIC, Java, PHP, Javascript ...) ... and Perl... Even if it's not as bad as I sometimes think. BTW, after seeing "@" and "$" in Julia manual, I think I will stay aside for a while. > Some of them, like Haskell, influence other languages without ever > being popular themselves. Interestingly, Haskell developers seem to not care much about old codebases in their own language (but I didn't make systematic research of the subject). I hope others will not be influenced by such attitude :-). Neglecting someone's effort to make working flawless code, forcing people into periodic rewrites of things that used to work, such events always blink red in my head. -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From marko at pacujo.net Sun May 11 12:27:38 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 11 May 2014 19:27:38 +0300 Subject: Fortran References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871tw0s2kl.fsf@elektro.pacujo.net> Tomasz Rola : > Given that Fortran is here for almost 60 years and lot of effort has > been spent to keep it backwards compatible (AFAIK), I wouldn't hold my > breath. I have seen a glimpse of the so-called scientific computing and Fortran programming. I can't help but think that Fortran is successful with people who don't know how to program and don't care. That's fine. If I were to build a cyclotron, I bet the Fortran coders would smile at my clumsy efforts. Marko From rosuav at gmail.com Sun May 11 12:42:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 May 2014 02:42:13 +1000 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: <20140511160952.GA5383@tau1.ceti.pl> References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <20140511160952.GA5383@tau1.ceti.pl> Message-ID: On Mon, May 12, 2014 at 2:09 AM, Tomasz Rola wrote: > Given that Fortran is here for almost 60 years and lot of effort has > been spent to keep it backwards compatible (AFAIK), I wouldn't hold my > breath. Something may look like cool and great, but wait ten years and > see if after major language revision you can still (more or less) > easily run your existing huge projects with it. The Unix pipe system is still working beautifully, and will continue to do so for the next few decades. Build your system as a number of separate processes that pipe data from one into another, keep your old interpreters and compilers around, and you'll be fine. But retaining that backward compatibility is a huge cost. Sixty years ago's hardware wasn't the same as we have today. You can't simply run the exact same compiler and get the same bytes of output and run them. Someone has to maintain that old compiler, make sure it works with the latest toolchain and hardware, etc. Probably make sure it's bug-for-bug compatible with the original, too. How long do you want to keep that up? It's a huge trade-off. If a language basically says "That code you wrote two years ago? Not gonna work now", then I'd see that as a big blinking red light. But "Ten years ago's code will probably work on today's interpreter, unless it uses as identifiers what's now a keyword, or it might be unintentionally treading on now-fixed bugs in which case it might have to be fixed", that's not as big a problem. Yes, you'd need to 2to3 that old Python 2.3 code to get it to run on Python 3.4, but chances are it'll run mostly-unchanged on 2.7 (modulo string exceptions, maybe). I'm cheating a bit by citing Python 2.7, given that it's now four years old, but it's also going to be supported for a good few more years. Not sixty, presumably, but a good while. ChrisA From alain at dpt-info.u-strasbg.fr Sun May 11 13:05:22 2014 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sun, 11 May 2014 19:05:22 +0200 Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mweotfe5.fsf@dpt-info.u-strasbg.fr> Mark H Harris writes: > On 5/10/14 8:42 AM, Roy Smith wrote: >> http://tinyurl.com/mr54p96 > 'Julia' is going to give everyone a not so small run for competition; > justifiably so, not just against FORTRAN. > > Julia is Matlab and R, Python, Lisp, Scheme; all rolled together on > steroids. Its amazing as a dynamic language, and its fast, like > lightning fast as well as multiprocessing (parallel processing) at its > core. Its astounding, really. Hmmm... > Its number concept is unified, What exactly is unified? There is no implicit promotion between primitive types and BigInt/Float. Conversion happens because all arithmetic is overloaded for various types, and julia does multi-dispatch. There is little chance number-crunching applications will shine in julia, unless everything is statically typed. > BigFloats are by default arbitrary precision with full scientific and > transcendental functions built-in, everything complex just works, and > did I mention its fast? Yes, julia wraps GMP and MPFR, just like many compilers already do (e.g., gcc). Very good, but nothing specific to julia here. And for linear algebra, julia uses... BLAS and LAPACK. And fftw for FFT. And so on. Nothing new for a Fortran programmer, really. > The bench-marks are within 2x of C across the boards; makes Matlab > look like a rock, and is well ahead of python (NumPy SciPy) for > technical computing. 2x for syntactic sugar is a lot. But yes, numpy/scipy developers should watch out... > Julia is still very much beta in my opinion but its maturing fast. Its > open free (libre) and cross platform and did I mention it flatout > screams? Not only will it replace FORTRAN completely if things keep > progressing, but also Matlab, Mathematica, NumPy, & SciPy (and > others). Keep your eye on her fellows. Well, Fortran experts around me are skeptic. -- Alain. From roy at panix.com Sun May 11 13:51:21 2014 From: roy at panix.com (Roy Smith) Date: Sun, 11 May 2014 13:51:21 -0400 Subject: Fortran References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> Message-ID: In article <871tw0s2kl.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > Tomasz Rola : > > > Given that Fortran is here for almost 60 years and lot of effort has > > been spent to keep it backwards compatible (AFAIK), I wouldn't hold my > > breath. > > I have seen a glimpse of the so-called scientific computing and Fortran > programming. I can't help but think that Fortran is successful with > people who don't know how to program and don't care. > > That's fine. If I were to build a cyclotron, I bet the Fortran coders > would smile at my clumsy efforts. It is fine. Computers are tools. The sign of a good tool is that you can pick it up and use it without having to read the instruction manual. I can jump into pretty much any car, start the engine, and drive it, without any learning curve. There's a lot of complicated organic chemistry and thermodynamics going on inside the engine's combustion chambers, but I don't need to know any of that to make use of the tool. From rtomek at ceti.pl Sun May 11 14:04:23 2014 From: rtomek at ceti.pl (Tomasz Rola) Date: Sun, 11 May 2014 20:04:23 +0200 Subject: Fortran In-Reply-To: References: <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <20140511160952.GA5383@tau1.ceti.pl> Message-ID: <20140511180423.GB5383@tau1.ceti.pl> On Mon, May 12, 2014 at 02:42:13AM +1000, Chris Angelico wrote: > On Mon, May 12, 2014 at 2:09 AM, Tomasz Rola wrote: > > Given that Fortran is here for almost 60 years and lot of effort has > > been spent to keep it backwards compatible (AFAIK), I wouldn't hold my > > breath. Something may look like cool and great, but wait ten years and > > see if after major language revision you can still (more or less) > > easily run your existing huge projects with it. > > The Unix pipe system is still working beautifully, and will continue [...] > > But retaining that backward compatibility is a huge cost. Sixty years > ago's hardware wasn't the same as we have today. You can't simply run > the exact same compiler and get the same bytes of output and run them. [...] > > If a language basically says "That code you wrote two years ago? Not > gonna work now", then I'd see that as a big blinking red light. But > "Ten years ago's code will probably work on today's interpreter, > unless it uses as identifiers what's now a keyword, or it might be > unintentionally treading on now-fixed bugs in which case it might have > to be fixed", that's not as big a problem. Yes, you'd need to 2to3 > that old Python 2.3 code to get it to run on Python 3.4, but chances > are it'll run mostly-unchanged on 2.7 (modulo string exceptions, > maybe). I'm cheating a bit by citing Python 2.7, given that it's now > four years old, but it's also going to be supported for a good few > more years. Not sixty, presumably, but a good while. > > ChrisA I can easily agree to your points. Personally I don't really care much about decades-old codes (unless I want to play with them inside some emulator). There was indeed a lot of change in OSes and hardware, and languages should keep up with it, if possible. And the "pipe extention" is one of the things I'd consider - as well as other similar means, like SOAP or REST. However, obsoleting code younger than five years does not feel good to me. AFAIK big projects take years to be written, polished up, debugged and sometimes refactored (during this time they may also be used and go throu their own big version changes), so it is really big pain to see how after all this work someone's decision changes ground under one's feet. As of remark by Marko Rauhamaa, that "Fortran is successful with people who don't know how to program and don't care" - I wrote maybe two Fortran programs so far, both very simple. I tried to obey so called rules, inserted comment lines, checked for return values and issued warnings/errors when needed, didn't use goto excessively (AFAIR), didn't make stupid things like changing index variable inside loop (other than by predefined step in one and only one place, be it by hand or by compiler). For one program I got max points to get (uni course) and for the other I have been presented with a basket of strawberries. Was I successful - or my use of Fortran :-)? OTOH I once had to work with someone else's Java code, a huge class in huge file and I found it too borked to repair so I rewrote from the scratch. Will I write some more code in Fortran - maybe, or maybe not. I don't feel any urgent need to do this. There is still a lot of things I'd like to learn and a day has only so many hours. I consider Fortran a useful tool which may possibly outlive me (but let's wait and see :-) ). As of quality of its users, sure, I consider programming a full time activity and it is very hard to find people who want to be good at it *and* in their supposed domain at the same time. Heck, I keep reading it is hard to find people who would like to be good in anything at all. Perhaps part of the problem is unwillingness to tackle it. I think majority of people would like to do things better, especially if it only requires small changes in behaviour. But they simply don't know there is better way, because nobody cared to tell them or show by example. Or nobody knew there were some people who would have been happy to hear a word of advice. Well, at least it is nice to believe in this. -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From rosuav at gmail.com Sun May 11 14:12:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 May 2014 04:12:34 +1000 Subject: Fortran In-Reply-To: <20140511180423.GB5383@tau1.ceti.pl> References: <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <20140511160952.GA5383@tau1.ceti.pl> <20140511180423.GB5383@tau1.ceti.pl> Message-ID: On Mon, May 12, 2014 at 4:04 AM, Tomasz Rola wrote: > And the "pipe > extention" is one of the things I'd consider - as well as other > similar means, like SOAP or REST. Yep. My point was, keep the processes separate and it's easy. There are myriad ways of doing the glue. ChrisA From rosuav at gmail.com Sun May 11 14:08:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 May 2014 04:08:15 +1000 Subject: Fortran In-Reply-To: References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> Message-ID: On Mon, May 12, 2014 at 3:51 AM, Roy Smith wrote: > It is fine. Computers are tools. The sign of a good tool is that you > can pick it up and use it without having to read the instruction manual. > I can jump into pretty much any car, start the engine, and drive it, > without any learning curve. There's a lot of complicated organic > chemistry and thermodynamics going on inside the engine's combustion > chambers, but I don't need to know any of that to make use of the tool. Err, I don't know that the analogy is really fair. Either you know how to drive a car, or you don't; if you do, what you really mean is that cars are sufficiently standardized that, even though you trained on an X, you can drive a Y without reading its instruction manual - but if you don't, then you're basically at the dangerous level of "hey look, I can type these commands and stuff happens", without knowing the rather important safety implications of what you're doing. Can you use a hammer without an instruction manual? Sure! Can you use a circular saw without reading the instructions? Quite probably, but will you know how to do it safely? The organic chemistry and thermodynamics are the car's equivalent of refcounting and garbage collection. They're absolutely critical if you're building a car, but in driving one, you almost never need to care about those details - and it's entirely possible to have a car that doesn't work the same way (electric, perhaps). I would expect the instruction manual to be more about things like how to check the oil, so you don't blow your engine up. (Caveat: I don't drive, so I might have the details of the analogy facepalmingly wrong.) ChrisA From ethan at stoneleaf.us Sun May 11 14:05:20 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 11 May 2014 11:05:20 -0700 Subject: Fortran In-Reply-To: References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> Message-ID: <536FBBE0.9040902@stoneleaf.us> On 05/11/2014 10:51 AM, Roy Smith wrote: > In article <871tw0s2kl.fsf at elektro.pacujo.net>, > Marko Rauhamaa wrote: > >> Tomasz Rola : >> >>> Given that Fortran is here for almost 60 years and lot of effort has >>> been spent to keep it backwards compatible (AFAIK), I wouldn't hold my >>> breath. >> >> I have seen a glimpse of the so-called scientific computing and Fortran >> programming. I can't help but think that Fortran is successful with >> people who don't know how to program and don't care. >> >> That's fine. If I were to build a cyclotron, I bet the Fortran coders >> would smile at my clumsy efforts. > > It is fine. Computers are tools. The sign of a good tool is that you > can pick it up and use it without having to read the instruction manual. > I can jump into pretty much any car, start the engine, and drive it, > without any learning curve. There's a lot of complicated organic > chemistry and thermodynamics going on inside the engine's combustion > chambers, but I don't need to know any of that to make use of the tool. That is an excellent example. For the most part cars are very similar, yet in some circumstances (such as a vehicle in front of you suddenly stopping) the exact details (such as the precise location and size and shape of the brake pedal) become excruciatingly important (having your foot stomp the floor just to the right of the current break pedal, because that's where the brake was in your last vehicle, is not going to help here). How the lights and/or windshield wipers turn on/off is also an important detail. -- ~Ethan~ From rosuav at gmail.com Sun May 11 14:33:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 May 2014 04:33:25 +1000 Subject: Fortran In-Reply-To: <536FBBE0.9040902@stoneleaf.us> References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <536FBBE0.9040902@stoneleaf.us> Message-ID: On Mon, May 12, 2014 at 4:05 AM, Ethan Furman wrote: > For the most part cars are very similar, yet in some circumstances (such as > a vehicle in front of you suddenly stopping) the exact details (such as the > precise location and size and shape of the brake pedal) become > excruciatingly important (having your foot stomp the floor just to the right > of the current break pedal, because that's where the brake was in your last > vehicle, is not going to help here). Some things are more standardized than others. A piano keyboard is incredibly standard, to make it possible to play without having to look at your fingers (even when jumping your hands around, which doesn't happen as much on a computer keyboard); mobile phones are anything but, so you really need to get to know your particular phone (there may or may not even be brand similarities). But that's really tangential to the question of using something without gaining any skill in it; it's more a matter of how well skill gained on one device in a class translates to other devices in that class. ChrisA From ned at nedbatchelder.com Sun May 11 14:40:24 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 11 May 2014 14:40:24 -0400 Subject: Values and objects In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eea59$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/11/14 9:46 AM, Rotwang wrote: > On 11/05/2014 04:11, Steven D'Aprano wrote: >> [...] >> >> And try running >> this function in both 2.7 and 3.3 and see if you can explain the >> difference: >> >> def test(): >> if False: x = None >> exec("x = 1") >> return x > > I must confess to being baffled by what happens in 3.3 with this > example. Neither locals() nor globals() has x = 1 immediately before the > return statement, so what is exec("x = 1") actually doing? > The same happens if you try to modify locals(): >>> def test(): ... if 0: x = 1 ... locals()['x'] = 13 ... return x ... >>> test() Traceback (most recent call last): File "", line 1, in File "", line 4, in test UnboundLocalError: local variable 'x' referenced before assignment The doc for exec says: Note: The default locals act as described for function locals() below: modifications to the default locals dictionary should not be attempted. Pass an explicit locals dictionary if you need to see effects of the code on locals after function exec() returns. The doc for locals says: Note: The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter. This is a tradeoff of practicality for purity: the interpreter runs faster if you don't make locals() a modifiable dict. -- Ned Batchelder, http://nedbatchelder.com From roy at panix.com Sun May 11 14:43:19 2014 From: roy at panix.com (Roy Smith) Date: Sun, 11 May 2014 14:43:19 -0400 Subject: Fortran References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <536FBBE0.9040902@stoneleaf.us> Message-ID: In article , Chris Angelico wrote: > Some things are more standardized than others. A piano keyboard is > incredibly standard, to make it possible to play without having to > look at your fingers (even when jumping your hands around, which > doesn't happen as much on a computer keyboard) Speaking of which, here's a trivia question. Without looking at your keyboard, describe how the "F" and "J" keys (assuming a US-English key layout) differ from, say, the "G" and "K" keys. From harrismh777 at gmail.com Sun May 11 14:54:31 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 11 May 2014 13:54:31 -0500 Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> Message-ID: On 5/11/14 12:05 PM, Alain Ketterlin wrote: >> Julia is Matlab and R, Python, Lisp, Scheme; all rolled together on >> steroids. Its amazing as a dynamic language, and its fast, like >> lightning fast as well as multiprocessing (parallel processing) at its >> core. Its astounding, really. > > Hmmm... > >> Its number concept is unified, > > What exactly is unified? There is no implicit promotion between > primitive types and BigInt/Float. The built-in math functions (extensive, by the way) just work, and they work consistently the way you might expect across types. Consider sqrt(): > julia> sqrt(-1+0im) > 0.0 + 1.0im > julia> sqrt(complex(-1)) > 0.0 + 1.0im > julia> sqrt(2) > 1.4142135623730951 >julia> sqrt(2.0) > 1.4142135623730951 > julia> sqrt(BigFloat(2.0)) >1.414213562373095048801688724209698078569671875376948073176679737990732478462102 >e+00 with 256 bits of precision >julia> with_bigfloat_precision(1024) do > sqrt(BigFloat(2.0)) > end >1.414213562373095048801688724209698078569671875376948073176679737990732478462107 >03885038753432764157273501384623091229702492483605585073721264412149709993583141 >32226659275055927557999505011527820605714701095599716059702745345968620147285174 >18640889198609552329230484308714321450839762603627995251407989687253402e+00 >with 1024 bits of precision You'll notice that I did not need to import anything to use sqrt(), and sqrt() takes all types and does something meaningful with them. The following code will produce over 100,000 digits of ? (pi) in less than 2 seconds on a low-end processor, like my mac mini dual core 2Ghz: >julia> prec=524288 >524288 >julia> with_bigfloat_precision(prec) do > println(atan(BigFloat(1)/5)*16 - atan(BigFloat(1)/239)*4) > end The scientific and transcendental functions (built-ins) just work. The coder sets the precision in floating point bits, and the functions just work --- at that precision. Nothing needs to be imported, and special functions are not necessary. The maths are unified, and they are fast; yet, the coder has the flexibility and ease of python coding, with a very useful repl. But, like lisp, Julia's internal structures are lists, so, it can create and modify its own code on-the-fly. Unicode characters above code point \u00A0 can be used as symbols, and constants ARE their unicode characters: >julia> sin(?/4) > 0.7071067811865475 >julia> cos(?/4) > 0.7071067811865476 >julia> sin(BigFloat(?/4)) > 7.0710678118654750275194295621751674626154323953749278952436611913748 > 20215180412e-01 with 256 bits of precision marcus From rosuav at gmail.com Sun May 11 14:59:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 May 2014 04:59:41 +1000 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> Message-ID: On Mon, May 12, 2014 at 4:54 AM, Mark H Harris wrote: > The following code will produce over 100,000 digits of ? (pi) in less than 2 > seconds on a low-end processor, like my mac mini dual core 2Ghz: > >>julia> prec=524288 >>524288 > >>julia> with_bigfloat_precision(prec) do >> println(atan(BigFloat(1)/5)*16 - atan(BigFloat(1)/239)*4) >> end Would it be quicker (and no less accurate) to represent pi as atan(BigFloat(1))*4 instead? That's how I originally met a pi-calculation (as opposed to "PI = 3.14" extended to however much accuracy someone cared to do). ChrisA From musicalhacksaw at yahoo.co.uk Sun May 11 15:05:13 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Sun, 11 May 2014 12:05:13 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> Message-ID: <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> Thank you everyone who replied, for your help. Using the command prompt console, it accepts the first line of code, but doesn't seem to accept the second line. I have altered it a little, but it is not having any of it, I quote my console input and output here, as it can probably explain things better than I :- -------------------------------------------------------------------------------- Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Intel Atom>cd"c:\Beautiful Soup" The filename, directory name, or volume label syntax is incorrect. C:\Users\Intel Atom>cd "c:\Beautiful Soup" c:\Beautiful Soup>python setup.py install. File "setup.py", line 22 print "Unit tests have failed!" ^ SyntaxError: invalid syntax c:\Beautiful Soup>python setup.py install" File "setup.py", line 22 print "Unit tests have failed!" ^ SyntaxError: invalid syntax c:\Beautiful Soup> -------------------------------------------------------------------------------- I have tried writing "python setup.py install" ie putting the statement in inverted commas, but the console still seems to reject it re:- -------------------------------------------------------------------------------- c:\Beautiful Soup>"python setup. py install" '"python setup. py install"' is not recognized as an internal or external comman d, operable program or batch file. c:\Beautiful Soup> -------------------------------------------------------------------------------- Again I hope you python practitioners can help. I am only on page 12, and have another 99 pages to go, so can only hope it gets easier. From harrismh777 at gmail.com Sun May 11 15:14:10 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 11 May 2014 14:14:10 -0500 Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> Message-ID: On 5/11/14 1:59 PM, Chris Angelico wrote: >>> julia> prec=524288 >>> 524288 >> >>> julia> with_bigfloat_precision(prec) do >>> println(atan(BigFloat(1)/5)*16 - atan(BigFloat(1)/239)*4) >>> end > > Would it be quicker (and no less accurate) to represent pi as > atan(BigFloat(1))*4 instead? That's how I originally met a > pi-calculation (as opposed to "PI = 3.14" extended to however much > accuracy someone cared to do). No. Simple experiment will show you. The atan(x<=1) will converge faster. For 524288 bits atan(1) formula converged in 3 seconds, and Machin's formula atan(x<1) converged in 2 seconds. Where it becomes very apparent is 10K and 100K or above. Also, the difference is much more noticeable in Python than in Julia, but it is there no-the-less. But here is the cool part: what if your ? function could be broken down into three very fast converging atan(x<1) functions like this one: > pi = 24*atan(1/8) + 8*atan(1/57) + 4*atan(1/239) (Shanks used this) ... and then, you have julia send each piece to a separate processor|core (it does this at its center) and they converge together, then julia pieces them together at the end. Then things get incredibly faster. From rosuav at gmail.com Sun May 11 15:17:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 May 2014 05:17:33 +1000 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> Message-ID: On Mon, May 12, 2014 at 5:05 AM, Simon Evans wrote: > Thank you everyone who replied, for your help. Using the command prompt console, it accepts the first line of code, but doesn't seem to accept the second line. I have altered it a little, but it is not having any of it, I quote my console input and output here, as it can probably explain things better than I :- > -------------------------------------------------------------------------------- Thank you. This sort of transcript does make it very easy to see what's going on! > Microsoft Windows [Version 6.1.7601] > Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > C:\Users\Intel Atom>cd"c:\Beautiful Soup" > The filename, directory name, or volume label syntax is incorrect. Command line syntax is always to put a command first (one word), and then its arguments (zero, one, or more words). You put quotes around a logical word when it has spaces in it. So, for instance, "foo bar" is one logical word. In this case, you omitted the space between the command and its argument, so Windows couldn't handle it. [1] > C:\Users\Intel Atom>cd "c:\Beautiful Soup" And this is correct; you put quotes around the argument, and execute the "cd" command with an argument of "c:\Beautiful Soup". It then works, as is shown by the change of prompt in your subsequent lines. > c:\Beautiful Soup>python setup.py install. > File "setup.py", line 22 > print "Unit tests have failed!" > ^ > SyntaxError: invalid syntax This indicates that you've installed a 3.x version of Python as the default, and setup.py is expecting a 2.x Python. Do you have multiple Pythons installed? Try typing this: c:\Python27\python setup.py install (That will work only if you have Python 2.7 installed into the default location.) Hope that helps! ChrisA [1] Windows lets you be a bit sloppy; for instance, cd\ works without a space between the command and the argument. (AFAIK this is true if and only if the path name starts with a backslash.) But normally, you separate command and argument(s) with a space. From marko at pacujo.net Sun May 11 15:56:14 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 11 May 2014 22:56:14 +0300 Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eebc1$0$29980$c3e8da3$5496439d@news.astraweb.com> <536f069b$0$29980$c3e8da3$5496439d@news.astraweb.com> <3fb2d95e-2fb6-43a5-a725-c6d38444b80c@googlegroups.com> <87ppjksum0.fsf@elektro.pacujo.net> <455a3dc0-c492-498b-9593-d30b8a967898@googlegroups.com> <87a9aos4gk.fsf@elektro.pacujo.net> Message-ID: <87vbtcqech.fsf@elektro.pacujo.net> Marko Rauhamaa : > I don't see any practical reason for that limitation. If you allow > setq/setf/set!, you have no reason to disallow symbol-value on a local > variable. In fact, the reason probably is practical and analogous to the locals() caveat in Python. If the language made local variables available indirectly, I'm guessing some optimizations would be much harder or impossible. In my own lisp implementation, where performance is not a concern at all, the local variables are both lexically scoped and offer access to symbol-value. Marko From musicalhacksaw at yahoo.co.uk Sun May 11 16:03:27 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Sun, 11 May 2014 13:03:27 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> Message-ID: <51368e56-35ee-4120-aacd-c759b01a45e5@googlegroups.com> Dear Chris Angelico, Yes, you are right, I did install Python 3.4 as well as 2.7. I have removed Python 3.4, and input the code you suggested and it looks like it has installed properly, returning the following code:- -------------------------------------------------------------------------------- Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Intel Atom>cd "c:\Beautiful Soup" c:\Beautiful Soup>c:\Python27\python setup.py install running install running build running build_py creating build creating build\lib copying BeautifulSoup.py -> build\lib copying BeautifulSoupTests.py -> build\lib running install_lib copying build\lib\BeautifulSoup.py -> c:\Python27\Lib\site-packages copying build\lib\BeautifulSoupTests.py -> c:\Python27\Lib\site-packages byte-compiling c:\Python27\Lib\site-packages\BeautifulSoup.py to BeautifulSoup.p yc byte-compiling c:\Python27\Lib\site-packages\BeautifulSoupTests.py to BeautifulS oupTests.pyc running install_egg_info Writing c:\Python27\Lib\site-packages\BeautifulSoup-3.2.1-py2.7.egg-info c:\Beautiful Soup> -------------------------------------------------------------------------------- Would that things were as straightforward as they are in the books, but anyway thank you much for your assistance, I'd still be typing the zillionth variation on the first line without your help. I don't doubt though that I will be coming unstuck in the not distant future. Until then, again thank you for your selfless help. From python at mrabarnett.plus.com Sun May 11 16:19:34 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 11 May 2014 21:19:34 +0100 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <51368e56-35ee-4120-aacd-c759b01a45e5@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <51368e56-35ee-4120-aacd-c759b01a45e5@googlegroups.com> Message-ID: <536FDB56.2040907@mrabarnett.plus.com> On 2014-05-11 21:03, Simon Evans wrote: > Dear Chris Angelico, > Yes, you are right, I did install Python 3.4 as well as 2.7. I have removed Python 3.4, and input the code you suggested and it looks like it has installed properly, returning the following code:- > -------------------------------------------------------------------------------- > Microsoft Windows [Version 6.1.7601] > Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > C:\Users\Intel Atom>cd "c:\Beautiful Soup" > > c:\Beautiful Soup>c:\Python27\python setup.py install > running install > running build > running build_py > creating build > creating build\lib > copying BeautifulSoup.py -> build\lib > copying BeautifulSoupTests.py -> build\lib > running install_lib > copying build\lib\BeautifulSoup.py -> c:\Python27\Lib\site-packages > copying build\lib\BeautifulSoupTests.py -> c:\Python27\Lib\site-packages > byte-compiling c:\Python27\Lib\site-packages\BeautifulSoup.py to BeautifulSoup.p > yc > byte-compiling c:\Python27\Lib\site-packages\BeautifulSoupTests.py to BeautifulS > oupTests.pyc > running install_egg_info > Writing c:\Python27\Lib\site-packages\BeautifulSoup-3.2.1-py2.7.egg-info > > c:\Beautiful Soup> > -------------------------------------------------------------------------------- > Would that things were as straightforward as they are in the books, but anyway thank you much for your assistance, I'd still be typing the zillionth variation on the first line without your help. I don't doubt though that I will be coming unstuck in the not distant future. Until then, again thank you for your selfless help. > You didn't need to remove Python 3.4. When you typed: python setup.py install it defaulted to Python 3.4, presumably because that was the last one you installed. You just needed to be explicit instead: C:\Python27\python.exe setup.py install From tjreedy at udel.edu Sun May 11 16:31:37 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 11 May 2014 16:31:37 -0400 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> Message-ID: On 5/11/2014 3:17 PM, Chris Angelico wrote: > On Mon, May 12, 2014 at 5:05 AM, Simon Evans wrote: >> c:\Beautiful Soup>python setup.py install. There is no need for a standalone Beautiful Soup directory. See below. >> File "setup.py", line 22 >> print "Unit tests have failed!" >> ^ >> SyntaxError: invalid syntax > > This indicates that you've installed a 3.x version of Python as the > default, and setup.py is expecting a 2.x Python. Do you have multiple > Pythons installed? Try typing this: > > c:\Python27\python setup.py install > > (That will work only if you have Python 2.7 installed into the default > location.) Please do not advise people to unnecessarily downgrade to 2.7 ;-). Simon just needs the proper current version of BeautifulSoup. BeautifulSoup3 does not work with 3.x. BeautifulSoup4 works with 2.6+ and 3.x. http://www.crummy.com/software/BeautifulSoup/ Installation (of the latest version on PyPI) is trivial with 3.4: C:\Programs\Python34>pip install beautifulsoup4 Downloading/unpacking beautifulsoup4 Running setup.py (path:C:\Users\Terry\AppData\Local\Temp\pip_build_Terry\beautifulsoup4\setup.py) egg_info for package beautifulsoup4 Installing collected packages: beautifulsoup4 Running setup.py install for beautifulsoup4 Skipping implicit fixer: buffer Skipping implicit fixer: idioms Skipping implicit fixer: set_literal Skipping implicit fixer: ws_comma Successfully installed beautifulsoup4 Cleaning up... --- Adding the '4' is necessary as >pip install beautifulsoup tries to install beautifulsoup3 as a py3.4 package and that fails with the SyntaxError message Simon got. With '4', there is now an entry in lib/site-packages you are ready to go. Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32 >>> from bs4 import BeautifulSoup # from the bs4 online doc >>> BeautifulSoup -- Terry Jan Reedy From musicalhacksaw at yahoo.co.uk Sun May 11 18:03:47 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Sun, 11 May 2014 15:03:47 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> Message-ID: <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> I have downloaded Beautiful Soup 3, I am using Python 2.7. I understand from your message that I ought to use Python 2.6 or Python 3.4 with Beautiful Soup 4, the book I am using 'Getting Started with Beautiful Soup' is for Beautiful Soup 4. Therefore I gather I must re-download Beautiful Soup and get the 4 version, dispose of my Python 2.7 and reinstall Python 3.4. I am sure I can do this, but doesn't the above information suggest that the only Python grade left that might work with Beautiful Soup 3 would by Python 2.7 - which is the configuration I have at present, though I am not perfectly happy, as it is not taking code in the book (meant for BS4) such as the following on page 16 : helloworld = "

Hello World

" re:- -------------------------------------------------------------------------------- c:\Beautiful Soup>helloworld = "

Hello World

" 'helloworld' is not recognized as an internal or external command, operable program or batch file. -------------------------------------------------------------------------------- I take it that this response is due to using code meant for BS4 with Python 2.6/ 3.4, rather than BS3 with Python 2.7 which is what I am currently using. If so I will change the configurations. From python at mrabarnett.plus.com Sun May 11 18:10:35 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 11 May 2014 23:10:35 +0100 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> Message-ID: <536FF55B.7020900@mrabarnett.plus.com> On 2014-05-11 23:03, Simon Evans wrote: > I have downloaded Beautiful Soup 3, I am using Python 2.7. I understand from your message that I ought to use Python 2.6 or Python 3.4 with Beautiful Soup 4, the book I am using 'Getting Started with Beautiful Soup' is for Beautiful Soup 4. Therefore I gather I must re-download Beautiful Soup and get the 4 version, dispose of my Python 2.7 and reinstall Python 3.4. I am sure I can do this, but doesn't the above information suggest that the only Python grade left that might work with Beautiful Soup 3 would by Python 2.7 - which is the configuration I have at present, though I am not perfectly happy, as it is not taking code in the book (meant for BS4) such as the following on page 16 : > > helloworld = "

Hello World

" > > re:- > -------------------------------------------------------------------------------- > c:\Beautiful Soup>helloworld = "

Hello World

" > 'helloworld' is not recognized as an internal or external command, > operable program or batch file. > -------------------------------------------------------------------------------- > I take it that this response is due to using code meant for BS4 with Python 2.6/ 3.4, rather than BS3 with Python 2.7 which is what I am currently using. If so I will change the configurations. > That's the Windows command prompt, not the Python command prompt. From sg552 at hotmail.co.uk Sun May 11 19:06:29 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Mon, 12 May 2014 00:06:29 +0100 Subject: Values and objects In-Reply-To: References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> <536eea59$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/05/2014 19:40, Ned Batchelder wrote: > On 5/11/14 9:46 AM, Rotwang wrote: >> On 11/05/2014 04:11, Steven D'Aprano wrote: >>> [...] >>> >>> And try running >>> this function in both 2.7 and 3.3 and see if you can explain the >>> difference: >>> >>> def test(): >>> if False: x = None >>> exec("x = 1") >>> return x >> >> I must confess to being baffled by what happens in 3.3 with this >> example. Neither locals() nor globals() has x = 1 immediately before the >> return statement, so what is exec("x = 1") actually doing? >> > > The same happens if you try to modify locals(): > > >>> def test(): > ... if 0: x = 1 > ... locals()['x'] = 13 > ... return x > ... > >>> test() > Traceback (most recent call last): > File "", line 1, in > File "", line 4, in test > UnboundLocalError: local variable 'x' referenced before assignment > > The doc for exec says: > > Note: The default locals act as described for function locals() > below: modifications to the default locals dictionary should not be > attempted. Pass an explicit locals dictionary if you need to see > effects of the code on locals after function exec() returns. > > The doc for locals says: > > Note: The contents of this dictionary should not be modified; > changes may not affect the values of local and free variables used > by the interpreter. > > This is a tradeoff of practicality for purity: the interpreter runs > faster if you don't make locals() a modifiable dict. Thanks. From steve+comp.lang.python at pearwood.info Sun May 11 19:15:32 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2014 23:15:32 GMT Subject: Fortran References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <536FBBE0.9040902@stoneleaf.us> Message-ID: <53700493$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 May 2014 14:43:19 -0400, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> Some things are more standardized than others. A piano keyboard is >> incredibly standard, to make it possible to play without having to look >> at your fingers (even when jumping your hands around, which doesn't >> happen as much on a computer keyboard) > > Speaking of which, here's a trivia question. Without looking at your > keyboard, describe how the "F" and "J" keys (assuming a US-English key > layout) differ from, say, the "G" and "K" keys. The F and J keys have "F" and "J" printed on them instead of "G" and "K". They're also in slightly different positions, offset one position to the left. Otherwise they are identical, to the limits of my vision and touch. (I haven't tried measuring them with a micrometer, or doing chemical analysis of the material they are made of.) -- Steven D'Aprano http://import-that.dreamwidth.org/ From musicalhacksaw at yahoo.co.uk Sun May 11 19:19:24 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Sun, 11 May 2014 16:19:24 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> Message-ID: <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> Yeah well at no point does the book say to start inputting the code mentioned in Python command prompt rather than the Windows command prompt, but thank you for your guidance anyway. I have downloaded the latest version of Beautiful Soup 4, but am again facing problems with the second line of code, re:- ------------------------------------------------------------------------------- Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Intel Atom>cd "c:\Beautiful Soup" c:\Beautiful Soup>c:\Python27\python setup.py install c:\Python27\python: can't open file 'setup.py': [Errno 2] No such file or direct ory -------------------------------------------------------------------------------- though that was the code I used before which installed okay see above). Can anyone tell me where I am going wrong ? Thanks. From musicalhacksaw at yahoo.co.uk Sun May 11 19:22:30 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Sun, 11 May 2014 16:22:30 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> Message-ID: On Monday, May 12, 2014 12:19:24 AM UTC+1, Simon Evans wrote: > Yeah well at no point does the book say to start inputting the code mentioned in Python command prompt rather than the Windows command prompt, but thank you for your guidance anyway. > > I have downloaded the latest version of Beautiful Soup 4, but am again facing problems with the second line of code, re:- > > ------------------------------------------------------------------------------- > > Microsoft Windows [Version 6.1.7601] > > Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > > > C:\Users\Intel Atom>cd "c:\Beautiful Soup" > > > > c:\Beautiful Soup>c:\Python27\python setup.py install > > c:\Python27\python: can't open file 'setup.py': [Errno 2] No such file or direct > > ory > > -------------------------------------------------------------------------------- > > though that was the code I used before which installed okay see above). Can anyone tell me where I am going wrong ? Thanks. Oh I think I see - I should be using Python 3.4 now, with BS4 ? From musicalhacksaw at yahoo.co.uk Sun May 11 19:37:35 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Sun, 11 May 2014 16:37:35 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> Message-ID: <6913d181-8a7a-457d-a55f-63557b399d9f@googlegroups.com> - but wait a moment 'BeautifulSoup4 works with 2.6+ and 3.x'(Terry Reedy) - doesn't 2.6 + = 2.7, which is what I'm using with BeautifulSoup4. From ian.g.kelly at gmail.com Sun May 11 19:47:17 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 11 May 2014 17:47:17 -0600 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> Message-ID: On Sun, May 11, 2014 at 5:19 PM, Simon Evans wrote: > Yeah well at no point does the book say to start inputting the code mentioned in Python command prompt rather than the Windows command prompt, but thank you for your guidance anyway. > I have downloaded the latest version of Beautiful Soup 4, but am again facing problems with the second line of code, re:- > ------------------------------------------------------------------------------- > Microsoft Windows [Version 6.1.7601] > Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > C:\Users\Intel Atom>cd "c:\Beautiful Soup" > > c:\Beautiful Soup>c:\Python27\python setup.py install > c:\Python27\python: can't open file 'setup.py': [Errno 2] No such file or direct > ory > -------------------------------------------------------------------------------- > though that was the code I used before which installed okay see above). Can anyone tell me where I am going wrong ? Thanks. The error message is telling you that the file setup.py that you're trying to run is missing. That would seem to indicate that Beautiful Soup hasn't been downloaded or unzipped correctly. What do you have in the Beautiful Soup directory? Also, use Python 3.4 as Terry Reedy suggested, unless the book is using 2.7 in which case you should probably use the same version as the book. From tjreedy at udel.edu Sun May 11 19:49:20 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 11 May 2014 19:49:20 -0400 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> Message-ID: On 5/11/2014 6:03 PM, Simon Evans wrote: > I have downloaded Beautiful Soup 3, I am using Python 2.7. I > understand from your message that I ought to use Python 2.6or Python > 3.4 with Beautiful Soup 4, I wrote "BeautifulSoup4 works with 2.6+ and 3.x.". '2.6+' means 2.6 or 2.7. '3.x' should mean 3.1 to 3.4 but the range might start later. It does not matter because you should download and use 3.4 unless you *really* need to use something earlier. But also note that Windows has no problem with multiple version of python installed in different pythonxy directories. One of the things 3.4 does for you is make sure that pip is installed. It is now the more or less 'official' python package installer. To install BS4, do what the authors recommend on their web page http://www.crummy.com/software/BeautifulSoup/ and what I did: 'pip install beautifulsoup4' in a python34 directory. It took me less than a minute, far less that it took you to report that doing something else did not work. -- Terry Jan Reedy From python at mrabarnett.plus.com Sun May 11 19:51:01 2014 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 May 2014 00:51:01 +0100 Subject: Fortran In-Reply-To: <53700493$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <536FBBE0.9040902@stoneleaf.us> <53700493$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53700CE5.4000406@mrabarnett.plus.com> On 2014-05-12 00:15, Steven D'Aprano wrote: > On Sun, 11 May 2014 14:43:19 -0400, Roy Smith wrote: > >> In article , >> Chris Angelico wrote: >> >>> Some things are more standardized than others. A piano keyboard is >>> incredibly standard, to make it possible to play without having to look >>> at your fingers (even when jumping your hands around, which doesn't >>> happen as much on a computer keyboard) >> >> Speaking of which, here's a trivia question. Without looking at your >> keyboard, describe how the "F" and "J" keys (assuming a US-English key >> layout) differ from, say, the "G" and "K" keys. > > The F and J keys have "F" and "J" printed on them instead of "G" and "K". > They're also in slightly different positions, offset one position to the > left. Otherwise they are identical, to the limits of my vision and touch. > (I haven't tried measuring them with a micrometer, or doing chemical > analysis of the material they are made of.) > Maybe keyboards are different where you are! :-) Mine have an little ridge on the keytop of those keys. From steve+comp.lang.python at pearwood.info Sun May 11 19:51:11 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2014 23:51:11 GMT Subject: Fortran References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> Message-ID: <53700cef$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 12 May 2014 04:08:15 +1000, Chris Angelico wrote: > On Mon, May 12, 2014 at 3:51 AM, Roy Smith wrote: >> It is fine. Computers are tools. The sign of a good tool is that you >> can pick it up and use it without having to read the instruction >> manual. I can jump into pretty much any car, start the engine, and >> drive it, without any learning curve. There's a lot of complicated >> organic chemistry and thermodynamics going on inside the engine's >> combustion chambers, but I don't need to know any of that to make use >> of the tool. > > Err, I don't know that the analogy is really fair. Either you know how > to drive a car, or you don't; if you do, what you really mean is that > cars are sufficiently standardized that, even though you trained on an > X, you can drive a Y without reading its instruction manual Correct. It's a terrible analogy. Cars are relatively simple things, they basically have three functions: speed up, turn, slow down. And yet look at how many people manage to kill themselves, and others, by doing it wrong. In the US, more people die *each year* due to faulty driving than American soldiers died in the entire Vietnam war. (The one exception was 1968.) Programming languages, on the other hand, have effectively an infinite number of functions: most languages come built-in with dozens or hundreds, and the programmer then extends them with whatever functions they need. Cars are standardized -- there are basically two types, manuals and automatics. Programming languages are not, and thank goodness, because they whole point of having multiple programming languages is that they have different semantic models and different syntax so as to specialise on different tasks. I'm a critic of C the language, but only for application development -- it makes a grand high-level assembly language for low-level programming by experts where fine control and efficiency is more important than simplicity and programmer efficiency. Fortran is excellent for long-lasting numeric work, and Inform-7 is excellent for writing interactive fiction. I wouldn't write an 3D shooter game in bash, and I wouldn't write a throw-away admin script in Java. > - but if you > don't, then you're basically at the dangerous level of "hey look, I can > type these commands and stuff happens", without knowing the rather > important safety implications of what you're doing. Can you use a hammer > without an instruction manual? Sure! Can you use a circular saw without > reading the instructions? Quite probably, but will you know how to do it > safely? Circular saws have only a few functions: start spinning, and stop spinning. There's a few "gotchas" to learn, related to physical properties (momentum, energy transfer, the relative hardness and sharpness of the blade versus the softness of your fingers...) and maybe a couple of bells and whistles (e.g. can you cut on angles?). It's not within an order of magnitude of the complexity of a programming language. A better comparison would be with one of these: http://www.wisegeek.org/what-are-cnc-machines.htm And no surprise, to operate a CNC machine, the operator typically has to program it using a programming language (G-code). -- Steven D'Aprano http://import-that.dreamwidth.org/ From ian.g.kelly at gmail.com Sun May 11 20:02:46 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 11 May 2014 18:02:46 -0600 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> Message-ID: On Sun, May 11, 2014 at 5:47 PM, Ian Kelly wrote: > Also, use Python 3.4 as Terry Reedy suggested, unless the book is > using 2.7 in which case you should probably use the same version as > the book. Following up on that, if this is the book you are using: http://www.amazon.com/Getting-Started-Beautiful-Soup-Vineeth/dp/1783289554 then it says to use Python 2.7.5 or greater. There is no indication that the book is targeted at Python 3, and in fact I see at least one line that won't work in Python 3 ("import urllib2"), so I definitely recommend sticking with a 2.7 release. From roy at panix.com Sun May 11 20:14:14 2014 From: roy at panix.com (Roy Smith) Date: Sun, 11 May 2014 20:14:14 -0400 Subject: Fortran References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <536FBBE0.9040902@stoneleaf.us> <53700493$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , MRAB wrote: > On 2014-05-12 00:15, Steven D'Aprano wrote: > > On Sun, 11 May 2014 14:43:19 -0400, Roy Smith wrote: > > > >> In article , > >> Chris Angelico wrote: > >> > >>> Some things are more standardized than others. A piano keyboard is > >>> incredibly standard, to make it possible to play without having to look > >>> at your fingers (even when jumping your hands around, which doesn't > >>> happen as much on a computer keyboard) > >> > >> Speaking of which, here's a trivia question. Without looking at your > >> keyboard, describe how the "F" and "J" keys (assuming a US-English key > >> layout) differ from, say, the "G" and "K" keys. > > > > The F and J keys have "F" and "J" printed on them instead of "G" and "K". > > They're also in slightly different positions, offset one position to the > > left. Otherwise they are identical, to the limits of my vision and touch. > > (I haven't tried measuring them with a micrometer, or doing chemical > > analysis of the material they are made of.) > > > Maybe keyboards are different where you are! :-) > > Mine have an little ridge on the keytop of those keys. Yup. Long before the days of computers, the F/J keys have had some sort of tactile feedback (a raised dot or whatever) so you can tell when you hands are in the home position by feel. Pyjrteodr upi vsm rmf i[ yu[omh ;olr yjod/ From breamoreboy at yahoo.co.uk Sun May 11 20:27:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 12 May 2014 01:27:17 +0100 Subject: Fortran In-Reply-To: <53700cef$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <53700cef$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/05/2014 00:51, Steven D'Aprano wrote: > > Cars are standardized -- there are basically two types, manuals and > automatics. > Sadly they can still go wrong due to modern engineering practices. In my neck of the woods some years ago people were killed when standing at a bus stop, because the car driver was desperately pressing down on the automatic's brake but EMI overrode the engine controls and the car simply went faster. At least that is what the defence claimed at the trial. With no expert on the prosecution to refute the claim "not guilty" was the verdict. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Sun May 11 21:11:41 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 May 2014 01:11:41 GMT Subject: Fortran References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <536FBBE0.9040902@stoneleaf.us> <53700493$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53701fcd$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 12 May 2014 00:51:01 +0100, MRAB wrote: > On 2014-05-12 00:15, Steven D'Aprano wrote: >> On Sun, 11 May 2014 14:43:19 -0400, Roy Smith wrote: >>> Speaking of which, here's a trivia question. Without looking at your >>> keyboard, describe how the "F" and "J" keys (assuming a US-English key >>> layout) differ from, say, the "G" and "K" keys. >> >> The F and J keys have "F" and "J" printed on them instead of "G" and >> "K". They're also in slightly different positions, offset one position >> to the left. Otherwise they are identical, to the limits of my vision >> and touch. (I haven't tried measuring them with a micrometer, or doing >> chemical analysis of the material they are made of.) >> > Maybe keyboards are different where you are! :-) Certainly not. However they may be different where *you* are :-P I'm using an IBM keyboard, model SK-8820. > Mine have an little ridge on the keytop of those keys. I've seen keyboards with those, but not many. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sun May 11 21:40:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 May 2014 11:40:30 +1000 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> Message-ID: On Mon, May 12, 2014 at 6:31 AM, Terry Reedy wrote: > Please do not advise people to unnecessarily downgrade to 2.7 ;-). > Simon just needs the proper current version of BeautifulSoup. > BeautifulSoup3 does not work with 3.x. > BeautifulSoup4 works with 2.6+ and 3.x. > http://www.crummy.com/software/BeautifulSoup/ > Installation (of the latest version on PyPI) is trivial with 3.4: Oh, I'm glad of that! But without digging into the details of BS, all I could say for sure was that setup.py was expecting 2.x. :) Sticking with 3.4 and upgrading to BS4 is a much better solution. ChrisA From steve+comp.lang.python at pearwood.info Sun May 11 22:28:22 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 May 2014 02:28:22 GMT Subject: Fortran References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <53700cef$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <537031c6$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 12 May 2014 01:27:17 +0100, Mark Lawrence wrote: > On 12/05/2014 00:51, Steven D'Aprano wrote: >> >> Cars are standardized -- there are basically two types, manuals and >> automatics. >> >> > Sadly they can still go wrong due to modern engineering practices. In > my neck of the woods some years ago people were killed when standing at > a bus stop, because the car driver was desperately pressing down on the > automatic's brake Perhaps (s)he should have steered the car away from the people. Or I suppose the steering wheel failed as well? > but EMI overrode the engine controls EMI? The record company? Wow, I knew they were evil, but I didn't realise they were *that* evil. > and the car > simply went faster. At least that is what the defence claimed at the > trial. With no expert on the prosecution to refute the claim "not > guilty" was the verdict. Sounds like the prosecution were just going through the motions. They should have either had an expert able to refute the claim, or not prosecuted in the first place. Personally, I'm rather skeptical about claims of "I kept pushing the brake but the car just accelerated". There is a long and inglorious history of people stepping on the wrong pedal when in a panic, or drunk, or distracted. I've even done it myself. (I expect *every* driver has, at some point.) And a not-quite-as-long but even more inglorious history of lawyers inventing nonsense links between the brake pedal and the accelerator in order to extort money from car manufacturers. E.g. see "Galileo's Revenge" by Peter W Huber and the case of the mythical, but amazingly profitable for the lawyers involved, Audi Sudden Acceleration Syndrome. For me personally, perhaps the most despicable part of the whole sordid story was the case of Wende Gatts, who ran over Darlene Norris, causing $300,000 in damages. Not only did she got off scot-free, thanks to the junk science invented by her "expert witness", but actual victim Norris was ordered to pay Gatts' legal fees of $64K. Of course, that was in the late 1980s, when even luxury cars still had mechanical linkage between the user and the brakes. These days, when nearly everything in the car is computer controlled, I wouldn't be *quite* so skeptical. Nevertheless, chances are almost certain that by far the majority of unexpected acceleration cases are PEBCAP errors. http://www.caranddriver.com/features/its-all-your-fault-the-dot-renders-its-verdict-on-toyotas-unintended-acceleration-scare-feature http://www.caranddriver.com/news/toyota-recall-scandal-media-circus-and-stupid-drivers-editorial -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Sun May 11 22:47:14 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 11 May 2014 19:47:14 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> Message-ID: On Saturday, May 10, 2014 10:28:18 PM UTC+5:30, Simon Evans wrote: > I am new to Python, but my main interest is to use it to Webscrape. I guess you've moved on from this specific problem. However here is some general advice: To use beautiful soup you need to use python. To use python you need to know python. Some people spend months on that, or weeks or days. Maybe you are clever and can reduce that to hours but not further :-) So start with this https://docs.python.org/2/tutorial/ or https://docs.python.org/3.4/tutorial/ [depending on which python you need] It may take a bit longer; but you will suffer less. From d at davea.name Sun May 11 23:27:12 2014 From: d at davea.name (Dave Angel) Date: Sun, 11 May 2014 23:27:12 -0400 Subject: Fortran In-Reply-To: <53701fcd$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <536FBBE0.9040902@stoneleaf.us> <53700493$0$29980$c3e8da3$5496439d@news.astraweb.com> <53701fcd$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53703F90.2050400@davea.name> On 05/11/2014 09:11 PM, Steven D'Aprano wrote: > On Mon, 12 May 2014 00:51:01 +0100, MRAB wrote: > > > Certainly not. However they may be different where *you* are :-P > > I'm using an IBM keyboard, model SK-8820. > > >> Mine have an little ridge on the keytop of those keys. > > I've seen keyboards with those, but not many. > > My experience has been the exact opposite. Except for very cheap keyboards, I believe the standard marks have been on F and J on every keyboard I've encountered (USA) in the past 30 years. They certainly are on my two Thinkpads, two Toshibas, a Dell, and an IOGear keyboard. They're also on the 5 key of the keypads for a credit card machine and remotes from Sony and Samsung. Not all Sony's, though; some are defective. I had a close friend who is blind and deaf, and counted on those marks to touch type. -- DaveA From davea at davea.name Sun May 11 23:10:38 2014 From: davea at davea.name (Dave Angel) Date: Sun, 11 May 2014 23:10:38 -0400 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> Message-ID: <53703BAE.7050300@davea.name> On 05/11/2014 02:54 PM, Mark H Harris wrote: > > >julia> sin(BigFloat(?/4)) > > 7.0710678118654750275194295621751674626154323953749278952436611913748 > > 20215180412e-01 with 256 bits of precision > That answer doesn't seem to come anywhere near 256 bits of precision. Using Python 3.2, >>> x=70710678118654750275194295621751674626154323953749278952436611913748 >>> x*x 4999999999999999693838300213161705693483516931249926767981110058185818806614907837502621065882204197129973479350206261627418690991407504 Not that this is surprising, but it does make a terrible ad for how great Julia is. -- DaveA From harrismh777 at gmail.com Mon May 12 00:10:49 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 11 May 2014 23:10:49 -0500 Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> Message-ID: On 5/11/14 10:10 PM, Dave Angel wrote: > On 05/11/2014 02:54 PM, Mark H Harris wrote: > >> >> >julia> sin(BigFloat(?/4)) >> > 7.0710678118654750275194295621751674626154323953749278952436611913748 >> > 20215180412e-01 with 256 bits of precision >> > > That answer doesn't seem to come anywhere near 256 bits of precision. > > Using Python 3.2, > > >>> x=70710678118654750275194295621751674626154323953749278952436611913748 > >>> x*x > 4999999999999999693838300213161705693483516931249926767981110058185818806614907837502621065882204197129973479350206261627418690991407504 > > > Not that this is surprising, but it does make a terrible ad for how > great Julia is. > Dave, you get the golden egg! I expected D'Aprano to catch it first! Yes, BigFloat does the same dumb thing Python's Decimal does. ?/4 is not a BigFloat, and BigFloat simply makes the 16 digit float into a 256 bit float, the sin of which will only be 16 digits accurate (more or less). It has nothing to do with the language (Python vs. Julia) it has to do with the way the BigFloat is formed. So let's fix it by forming the ? constant as a BigFloat constant: >julia> n = BigFloat(1) >1e+00 with 256 bits of precision >julia> ? = atan(n/5)*16 - atan(n/239)*4 >3.141592653589793238462643383279502884197169399375105820974944592307816406286198e+00 >with 256 bits of precision >julia> S = sin(?/4) >7.07106781186547524400844362104849039284835937688474036588339868995366239231051e-01 >with 256 bits of precision >julia> S * S >4.999999999999999999999999999999999999999999999999999999999999999999999999999957e-01 >with 256 bits of precision Not too bad... marcus From percy.tambunan at gmail.com Mon May 12 00:12:43 2014 From: percy.tambunan at gmail.com (Percy Tambunan) Date: Sun, 11 May 2014 21:12:43 -0700 (PDT) Subject: parsing multiple root element XML into text In-Reply-To: References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> Message-ID: On Friday, May 9, 2014 4:02:42 PM UTC+7, Chris Angelico wrote: > On Fri, May 9, 2014 at 6:59 PM, Percy Tambunan wrote: > > > Hai, I would like to parse this multiple root element XML > > > > Easy fix might be to wrap it in and , which will give > > you a new root. Would that help? > > > > ChrisA Thanks chris for the idea. Any suggestion to make it print like this: create enumdnsched 4.1.0.1.4.7.3.4.3.2.6.e164.arpa -set naptrFlags=nu create enumdnsched 5.1.0.1.4.7.3.4.3.2.6.e164.arpa -set naptrFlags=nu From harrismh777 at gmail.com Mon May 12 00:26:53 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 11 May 2014 23:26:53 -0500 Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> Message-ID: On 5/11/14 11:10 PM, Mark H Harris wrote: > On 5/11/14 10:10 PM, Dave Angel wrote: >> On 05/11/2014 02:54 PM, Mark H Harris wrote: >> >>> >>> >julia> sin(BigFloat(?/4)) >>> > 7.0710678118654750275194295621751674626154323953749278952436611913748 >>> > 20215180412e-01 with 256 bits of precision >>> >> >> That answer doesn't seem to come anywhere near 256 bits of precision. >> >> Using Python 3.2, >> >> >>> >> x=70710678118654750275194295621751674626154323953749278952436611913748 >> >>> x*x >> 4999999999999999693838300213161705693483516931249926767981110058185818806614907837502621065882204197129973479350206261627418690991407504 >> >> >> >> Not that this is surprising, but it does make a terrible ad for how >> great Julia is. >> > > Dave, you get the golden egg! I expected D'Aprano to catch it first! > > Yes, BigFloat does the same dumb thing Python's Decimal does. ?/4 is > not a BigFloat, and BigFloat simply makes the 16 digit float into a 256 > bit float, the sin of which will only be 16 digits accurate (more or less). > > It has nothing to do with the language (Python vs. Julia) it has to do > with the way the BigFloat is formed. So let's fix it by forming the ? > constant as a BigFloat constant: > > >julia> n = BigFloat(1) > >1e+00 with 256 bits of precision > > >julia> ? = atan(n/5)*16 - atan(n/239)*4 > >3.141592653589793238462643383279502884197169399375105820974944592307816406286198e+00 >with 256 bits of precision > > >julia> S = sin(?/4) > >7.07106781186547524400844362104849039284835937688474036588339868995366239231051e-01 >with 256 bits of precision > > >julia> S * S > >4.999999999999999999999999999999999999999999999999999999999999999999999999999957e-01 >with 256 bits of precision Having said that, the accuracy was not my point; in the first place. My point is that the sin() function is built-in, takes standard floats (32 bit, 64 bit, 128 bit) and BigFloats of arbitrary precision (and does something meaningful with it). Let's take a look at Python Deciaml: >>> =================== RESTART =============== >>> from decimal import * (first I have to import) >>> from math import * (than I have to import again) >>> ? Traceback (most recent call last): File "", line 1, in ? NameError: name '?' is not defined (whoops, don't know ? ) >>> ?=4*atan(1) (let's create it) >>> sin(Decimal(?/4)) 0.7071067811865475 (whoops sin doesn't do Decimals) >>> from pdeclib import sin (let's get a sin that does do Decimals) >>> sin(Decimal(?/4)) Decimal('0.707106781186547502751942956217516746261543') >>> S=sin(Decimal(?/4)) (Whoops has the same problem as BigFloat) >>> S**2 Decimal('0.499999999999999969383830021316170569348351') >>> Now let's fix it: >>> >>> from pdeclib import d >>> n=d(1) >>> from pdeclib import * >>> n=d(1) >>> ?=atan(n/5)*16 - atan(n/239)*4 >>> S=sin(?/4) >>> S**2 > Decimal('0.500000000000000000000000000000000000000000') >>> Also not bad, but slower. ;-) marcus From rosuav at gmail.com Mon May 12 00:53:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 May 2014 14:53:17 +1000 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> Message-ID: On Mon, May 12, 2014 at 2:26 PM, Mark H Harris wrote: > Having said that, the accuracy was not my point; in the first place. My > point is that the sin() function is built-in... So what? Built-in just means that there's no namespacing of mathematical functions. ChrisA From lgabiot at hotmail.com Mon May 12 01:33:40 2014 From: lgabiot at hotmail.com (lgabiot) Date: Mon, 12 May 2014 07:33:40 +0200 Subject: Using threads for audio computing? In-Reply-To: <536f99eb$0$2109$426a74cc@news.free.fr> References: <536f869c$0$2178$426a74cc@news.free.fr> <536f99eb$0$2109$426a74cc@news.free.fr> Message-ID: <53705d34$0$2374$426a74cc@news.free.fr> Le 11/05/14 17:40, lgabiot a ?crit : > I guess if my calculation had to be performed on a small number of > samples (i.e. under the value of the Pyaudio buffer size (2048 samples > for instance), and that the calculation would last less than the time it > takes to get the next 2048 samples from Pyaudio, I wouldn't need the > Queue and Thread system. > But in my case where I need a large buffer, it might not work? > Unless I ask pyaudio to feed me directly with 5 seconds chunks (instead > of the usual buffer sizes: 1024, 2048, etc...), which I didn't try, > because I hadn't though of it. I guess this solution might probably not work, since it would mean that the calculation should be quick enough so it wouldn't last longer than 1 sample (1/48000 s for instance), since while doing the calculation, no audio would be ingested (unless pyAudio possess some kind of internal concurrency system). Which leads me to think that a buffer (queue) and separate threads (producer and consumer) are necessary for this task. But AFAIK the python GIL (and in smaller or older computers that have only one core) does not permit true paralell execution of two threads. I believe it is quite like the way multiple processes are handled by an OS on a single CPU computer: process A has x CPU cycles, then process B has y CPU cycles, etc... So in my case, I must have a way to make sure that: thread 1 (which gets audio from Pyaudio and put() it in the Queue) is not interrupted long enough to miss a sample. If I suppose a worst case scenario for the computer, like a raspberry-pi, the CPU speed is 700MHz, which gives approx 14 000 CPU cycles between each audio samples (at 48 kHz FS). I don't know if 14 000 CPU cycle is a lot or not for the tasks at hands. Well, at least, it is what I understand, but since I'm really both a beginner and an hobbyist, I might be totally wrong... From rosuav at gmail.com Mon May 12 01:41:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 May 2014 15:41:17 +1000 Subject: Using threads for audio computing? In-Reply-To: <53705d34$0$2374$426a74cc@news.free.fr> References: <536f869c$0$2178$426a74cc@news.free.fr> <536f99eb$0$2109$426a74cc@news.free.fr> <53705d34$0$2374$426a74cc@news.free.fr> Message-ID: On Mon, May 12, 2014 at 3:33 PM, lgabiot wrote: > But AFAIK the python GIL (and in smaller or older computers that have only > one core) does not permit true paralell execution of two threads. I believe > it is quite like the way multiple processes are handled by an OS on a single > CPU computer: process A has x CPU cycles, then process B has y CPU cycles, > etc... > So in my case, I must have a way to make sure that: > thread 1 (which gets audio from Pyaudio and put() it in the Queue) is not > interrupted long enough to miss a sample. > If I suppose a worst case scenario for the computer, like a raspberry-pi, > the CPU speed is 700MHz, which gives approx 14 000 CPU cycles between each > audio samples (at 48 kHz FS). I don't know if 14 000 CPU cycle is a lot or > not for the tasks at hands. > > Well, at least, it is what I understand, but since I'm really both a > beginner and an hobbyist, I might be totally wrong... The GIL is almost completely insignificant here. One of your threads will be blocked practically the whole time (waiting for more samples; collecting them into a numpy array doesn't take long), and the other is, if I understand correctly, spending most of its time inside numpy, which releases the GIL. You should be able to thread just fine. ChrisA From lgabiot at hotmail.com Mon May 12 01:54:24 2014 From: lgabiot at hotmail.com (lgabiot) Date: Mon, 12 May 2014 07:54:24 +0200 Subject: Using threads for audio computing? In-Reply-To: References: <536f869c$0$2178$426a74cc@news.free.fr> <536f99eb$0$2109$426a74cc@news.free.fr> <53705d34$0$2374$426a74cc@news.free.fr> Message-ID: <53706210$0$2921$426a74cc@news.free.fr> Le 12/05/14 07:41, Chris Angelico a ?crit : > > The GIL is almost completely insignificant here. One of your threads > will be blocked practically the whole time (waiting for more samples; > collecting them into a numpy array doesn't take long), and the other > is, if I understand correctly, spending most of its time inside numpy, > which releases the GIL. You should be able to thread just fine. > > ChrisA > Thanks Chris for your answer. So back to my original question: A Queue and two threads (producer/consumer) seems a good answer to my problem, or is there a better way to solve it? (again, I'm really a beginner, so I made up this solution, but really wonder if I do not miss a well known obvious much better idea). From rosuav at gmail.com Mon May 12 01:58:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 May 2014 15:58:29 +1000 Subject: Using threads for audio computing? In-Reply-To: <53706210$0$2921$426a74cc@news.free.fr> References: <536f869c$0$2178$426a74cc@news.free.fr> <536f99eb$0$2109$426a74cc@news.free.fr> <53705d34$0$2374$426a74cc@news.free.fr> <53706210$0$2921$426a74cc@news.free.fr> Message-ID: On Mon, May 12, 2014 at 3:54 PM, lgabiot wrote: > So back to my original question: A Queue and two threads (producer/consumer) > seems a good answer to my problem, or is there a better way to solve it? > (again, I'm really a beginner, so I made up this solution, but really wonder > if I do not miss a well known obvious much better idea). Well, the first thing I'd try is simply asking for more data when you're ready for it - can you get five seconds' of data all at once? Obviously this won't work if your upstream buffers only a small amount, in which case your thread is there to do that buffering; also, if you can't absolutely *guarantee* that you can process the data quickly enough, every time, then you need to use the queue to buffer that. But otherwise, it sounds like a quite reasonable way to do things. ChrisA From lgabiot at hotmail.com Mon May 12 02:02:01 2014 From: lgabiot at hotmail.com (lgabiot) Date: Mon, 12 May 2014 08:02:01 +0200 Subject: Using threads for audio computing? In-Reply-To: References: <536f869c$0$2178$426a74cc@news.free.fr> <536f99eb$0$2109$426a74cc@news.free.fr> <53705d34$0$2374$426a74cc@news.free.fr> <53706210$0$2921$426a74cc@news.free.fr> Message-ID: <537063d9$0$2291$426a74cc@news.free.fr> Le 12/05/14 07:58, Chris Angelico a ?crit : > Well, the first thing I'd try is simply asking for more data when > you're ready for it - can you get five seconds' of data all at once? > Obviously this won't work if your upstream buffers only a small > amount, in which case your thread is there to do that buffering; also, > if you can't absolutely *guarantee* that you can process the data > quickly enough, every time, then you need to use the queue to buffer > that. > > But otherwise, it sounds like a quite reasonable way to do things. > > ChrisA > Ok, thanks a lot! From stefan_ml at behnel.de Mon May 12 02:13:32 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 12 May 2014 08:13:32 +0200 Subject: Using threads for audio computing? In-Reply-To: <53705d34$0$2374$426a74cc@news.free.fr> References: <536f869c$0$2178$426a74cc@news.free.fr> <536f99eb$0$2109$426a74cc@news.free.fr> <53705d34$0$2374$426a74cc@news.free.fr> Message-ID: lgabiot, 12.05.2014 07:33: > Le 11/05/14 17:40, lgabiot a ?crit : > >> I guess if my calculation had to be performed on a small number of >> samples (i.e. under the value of the Pyaudio buffer size (2048 samples >> for instance), and that the calculation would last less than the time it >> takes to get the next 2048 samples from Pyaudio, I wouldn't need the >> Queue and Thread system. >> But in my case where I need a large buffer, it might not work? >> Unless I ask pyaudio to feed me directly with 5 seconds chunks (instead >> of the usual buffer sizes: 1024, 2048, etc...), which I didn't try, >> because I hadn't though of it. > > I guess this solution might probably not work, since it would mean that the > calculation should be quick enough so it wouldn't last longer than 1 sample > (1/48000 s for instance), since while doing the calculation, no audio would > be ingested (unless pyAudio possess some kind of internal concurrency system). > Which leads me to think that a buffer (queue) and separate threads > (producer and consumer) are necessary for this task. This sounds like a use case for double buffering. Use two buffers, start filling one. When it's full, switch buffers, start filling the second and process the first. When the second is full, switch again. Note that you have to make sure that the processing always terminates within the time it takes to fill the other buffer. If you can't assure that, however, you have a problem anyway and should see if there's a way to improve your algorithm. If the "fill my buffer" call in PyAudio is blocking (i.e. if it returns only after filling the buffer), then you definitely need two threads for this. > But AFAIK the python GIL (and in smaller or older computers that have only > one core) does not permit true paralell execution of two threads. Not for code that runs in the *interpreter", but it certainly allows I/O and low-level NumPy array processing to happen in parallel, as they do not need the interpreter. Stefan From leslie.polzer at googlemail.com Mon May 12 04:04:08 2014 From: leslie.polzer at googlemail.com (leslie.polzer at googlemail.com) Date: Mon, 12 May 2014 01:04:08 -0700 (PDT) Subject: ANN: Cerridwen 1.0c4 (initial release) Message-ID: <363f44d6-7ddd-4b30-9d47-dd6348f944ea@googlegroups.com> Dear Python friends, today I'm proud to be ANNOUNCING: The initial release of a new package, named Cerridwen (1.0c4). PyPI entry: https://pypi.python.org/pypi/cerridwen What gives? The author perceives a lack of modern open source software providing high quality planetary data that is suitable for astronomical and astrological purposes. So, to start amending that situation I wrote Cerridwen. Cerridwen is a moon data API relying on pyswisseph and numpy to provide accurate and comprehensive data on the moon. With its help you will, for example, be able to get the moon's current tropical sign, the dates of the next new and full moons and its current absolute and relative diameter. Cerridwen offers a JSON HTTP API and comes a simple command-line tool. These are built on a library module that you can use to develop your own applications. And you're invited too! Please try it if you're interested! :-) I've also set up a test server for the API here: http://cerridwen.viridian-project.de/api/v1/moon You can load it in your browser too for a quick peek! Please note that the given information may be up to 10 seconds old, due to efficiency considerations in the current version of Cerridwen. All feedback and participation is welcome, including forks and patches. Cerridwen's code is on Github. Need more information? Please do take a look at the PyPI page, it contains more detailed information. Also feel free to write to me at . Thanks for reading! With Cerridwen I'm trying to give something back to the Python community. This is my first publicly released Python package. Cheers, Leslie From lgabiot at hotmail.com Mon May 12 04:14:42 2014 From: lgabiot at hotmail.com (lgabiot) Date: Mon, 12 May 2014 10:14:42 +0200 Subject: Using threads for audio computing? In-Reply-To: References: <536f869c$0$2178$426a74cc@news.free.fr> <536f99eb$0$2109$426a74cc@news.free.fr> <53705d34$0$2374$426a74cc@news.free.fr> Message-ID: <537082f2$0$2141$426a74cc@news.free.fr> Le 12/05/14 08:13, Stefan Behnel a ?crit : > This sounds like a use case for double buffering. Use two buffers, start > filling one. When it's full, switch buffers, start filling the second and > process the first. When the second is full, switch again. > > Note that you have to make sure that the processing always terminates > within the time it takes to fill the other buffer. If you can't assure > that, however, you have a problem anyway and should see if there's a way to > improve your algorithm. > > If the "fill my buffer" call in PyAudio is blocking (i.e. if it returns > only after filling the buffer), then you definitely need two threads for this. > > >> But AFAIK the python GIL (and in smaller or older computers that have only >> one core) does not permit true paralell execution of two threads. > > Not for code that runs in the *interpreter", but it certainly allows I/O > and low-level NumPy array processing to happen in parallel, as they do not > need the interpreter. > > Stefan > > Thanks for your answer. If I follow your explanations, I guess I have to review my understanding of python execution model (I have to admit it is quite crude anyway). In my understanding, without threads, I would have two functions: - get_audio() would get the 5 seconds of audio from Pyaudio - process_audio() would process the 5 seconds of audio the main code would be roughly executing this: while(True) get_audio() process_audio() so since the audio is a live feed (which makes a difference, say, with an audio file analyser program), the get_audio() part must take 5 seconds to execute. (but most probably the processor stays still most of the time during the get_audio() part). then once get_audio() is done, process_audio() begins. Process_audio will take some time. If that time is greater that the times it takes for the next audio sample to arrive, I have a problem. (which you already explained differently maybe with: > If the "fill my buffer" call in PyAudio is blocking (i.e. if it returns > only after filling the buffer), then you definitely need two threads for this. ) So if I follow you, if the Pyaudio part is "Non-blocking" there would be a way to make it work without the two threads things. I'm back to the Pyaudio doc, and try to get my head around the callback method, which might be the good lead. From __peter__ at web.de Mon May 12 04:22:00 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 12 May 2014 10:22 +0200 Subject: parsing multiple root element XML into text References: <0e5e9a24-3663-4293-a530-239486cf28fc@googlegroups.com> Message-ID: Percy Tambunan wrote: > On Friday, May 9, 2014 4:02:42 PM UTC+7, Chris Angelico wrote: >> On Fri, May 9, 2014 at 6:59 PM, Percy Tambunan >> wrote: >> >> > Hai, I would like to parse this multiple root element XML >> >> >> >> Easy fix might be to wrap it in and , which will give >> >> you a new root. Would that help? >> >> >> >> ChrisA > > Thanks chris for the idea. > Any suggestion to make it print like this: > > create enumdnsched 4.1.0.1.4.7.3.4.3.2.6.e164.arpa -set naptrFlags=nu > create enumdnsched 5.1.0.1.4.7.3.4.3.2.6.e164.arpa -set naptrFlags=nu [Stefan Behnel] > ElementTree's XMLParser() can be use efficiently for this. Something like > this should work: > > from xml.etree.ElementTree import XMLParser > > parser = XMLParser() > parser.feed(b'') > parser.feed(real_input_data) > parser.feed(b'') > root = parser.close() > > for subtree in root: > ... Have you tried to integrate Stefan's example into your script? If so, what is the current state of your code, and what problems prevented you from completing it? Expect help to fix these problems, but not necessarily a ready-to-run solution. If you have not made an attempt yet look here for ideas on how you can use XPath to extract interesting data from the subtree: https://docs.python.org/dev/library/xml.etree.elementtree.html#example From alain at dpt-info.u-strasbg.fr Mon May 12 04:44:42 2014 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 12 May 2014 10:44:42 +0200 Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> Message-ID: <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> Mark H Harris writes: > On 5/11/14 12:05 PM, Alain Ketterlin wrote: >>> Julia is Matlab and R, Python, Lisp, Scheme; all rolled together on >>> steroids. Its amazing as a dynamic language, and its fast, like >>> lightning fast as well as multiprocessing (parallel processing) at its >>> core. Its astounding, really. >> >> Hmmm... >> >>> Its number concept is unified, >> >> What exactly is unified? There is no implicit promotion between >> primitive types and BigInt/Float. > > > The built-in math functions (extensive, by the way) just work, and > they work consistently the way you might expect across types. Consider > sqrt(): [...] > You'll notice that I did not need to import anything to use sqrt(), > and sqrt() takes all types and does something meaningful with them. Sorry, i wasn't clear enough: "doing something meaningful with them" is precisely where the problem is. Every single operation requires multiple-dispatch (i.e., dynamically testing types, converting to a common type, and selecting the version of sqrt to use). That's probably more than the time it takes to actually perform the computation, a bit like what happens with x+y on integers with Python, where only a fraction of time is spent on adding integers. When you are doing scientific computation, this overhead is unacceptable, because you'll have zillions of computations to perform. Julia provides a way to make things fast: typing. If you provide explicit types, the dynamic typing part obviously disappears, and the overhead is removed. But then, you're not too far from Fortran, or C/C++. > The following code will produce over 100,000 digits of ? (pi) in less > than 2 seconds on a low-end processor, like my mac mini dual core > 2Ghz: You seem to be discovering the power of the libraries that are behind all this (MPFR in that case)... [...] > But, like lisp, Julia's internal structures are lists, so, it can > create and modify its own code on-the-fly. [...] Sorry, I was comparing to Fortran, and it's use in scientific computing. Self modifying code is totally irrelevant there. -- Alain. From s.c.wouters at gmail.com Mon May 12 04:56:24 2014 From: s.c.wouters at gmail.com (s.c.wouters at gmail.com) Date: Mon, 12 May 2014 01:56:24 -0700 (PDT) Subject: Plotting multiple datasets with gnuplot In-Reply-To: References: <0c9f0c8b-30fb-4358-aed2-a5ed4dcdcb5c@d10g2000yqh.googlegroups.com> Message-ID: <9d24b871-0553-45f5-b9a4-77fc82d23cb3@googlegroups.com> On Friday, October 9, 2009 12:12:54 PM UTC+2, Gabriel Genellina wrote: > En Fri, 09 Oct 2009 06:36:45 -0300, Rob Garrett > escribi??oe: > > > I'm trying to get gnuplot to display multiple data series on a single > > plot using gnuplot in python. I've searched around and haven't found > > a solution to how to do this when I have a variable-length list of > > plots to add. > > > > For example, the following code will work: > > > > plotData1 = Gnuplot.PlotItems.Data(data1, title="title1") > > plotData2 = Gnuplot.PlotItems.Data(data2, title="title2") > > g.plot( plotData1, plotData2 ) > > > > [I've removed the rest of the code for clarity] > > > > But how can I do the following instead: > > > > data = [] > > ... > > # Populate data > > ... > > plots = [] > > for dataSet in data: > > plots.append(dataSet) > > g.plot(plots) > > g.plot(*plots) should work; it's like calling g.plot(plots[0], plots[1], > plots[2]...) > > See http://docs.python.org/reference/expressions.html#calls for the gory > details. > > -- > Gabriel Genellina I just spend an hour searching the web for a similar problem and finally found your answer. Thank you, it works great! From breamoreboy at yahoo.co.uk Mon May 12 05:05:08 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 12 May 2014 10:05:08 +0100 Subject: Fortran In-Reply-To: <537031c6$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <53700cef$0$29980$c3e8da3$5496439d@news.astraweb.com> <537031c6$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/05/2014 03:28, Steven D'Aprano wrote: > On Mon, 12 May 2014 01:27:17 +0100, Mark Lawrence wrote: > >> On 12/05/2014 00:51, Steven D'Aprano wrote: >>> >>> Cars are standardized -- there are basically two types, manuals and >>> automatics. >>> >>> >> Sadly they can still go wrong due to modern engineering practices. In >> my neck of the woods some years ago people were killed when standing at >> a bus stop, because the car driver was desperately pressing down on the >> automatic's brake > > Perhaps (s)he should have steered the car away from the people. Or I > suppose the steering wheel failed as well? The entire vehicle was perfectly sound after the event, including the brake and accelerator controls. It was only during the accident that the interference played havoc. Pure coincidence of course. > > >> but EMI overrode the engine controls > > EMI? The record company? Wow, I knew they were evil, but I didn't realise > they were *that* evil. Ho, ho, ho :) > > >> and the car >> simply went faster. At least that is what the defence claimed at the >> trial. With no expert on the prosecution to refute the claim "not >> guilty" was the verdict. > > Sounds like the prosecution were just going through the motions. They > should have either had an expert able to refute the claim, or not > prosecuted in the first place. Can't do that if you don't know in advance what the defence is :( > > Personally, I'm rather skeptical about claims of "I kept pushing the > brake but the car just accelerated". There is a long and inglorious > history of people stepping on the wrong pedal when in a panic, or drunk, > or distracted. I've even done it myself. (I expect *every* driver > has, at some point.) And a not-quite-as-long but even more inglorious > history of lawyers inventing nonsense links between the brake pedal and > the accelerator in order to extort money from car manufacturers. E.g. see > "Galileo's Revenge" by Peter W Huber and the case of the mythical, but > amazingly profitable for the lawyers involved, Audi Sudden Acceleration > Syndrome. > > For me personally, perhaps the most despicable part of the whole sordid > story was the case of Wende Gatts, who ran over Darlene Norris, causing > $300,000 in damages. Not only did she got off scot-free, thanks to the > junk science invented by her "expert witness", but actual victim Norris > was ordered to pay Gatts' legal fees of $64K. > > Of course, that was in the late 1980s, when even luxury cars still had > mechanical linkage between the user and the brakes. These days, when > nearly everything in the car is computer controlled, I wouldn't be > *quite* so skeptical. Nevertheless, chances are almost certain that by > far the majority of unexpected acceleration cases are PEBCAP errors. > > http://www.caranddriver.com/features/its-all-your-fault-the-dot-renders-its-verdict-on-toyotas-unintended-acceleration-scare-feature > > http://www.caranddriver.com/news/toyota-recall-scandal-media-circus-and-stupid-drivers-editorial > I hadn't heard about ASAS, another to add to my list of syndromes :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From lgabiot at hotmail.com Mon May 12 05:17:09 2014 From: lgabiot at hotmail.com (lgabiot) Date: Mon, 12 May 2014 11:17:09 +0200 Subject: Using threads for audio computing? In-Reply-To: <537082f2$0$2141$426a74cc@news.free.fr> References: <536f869c$0$2178$426a74cc@news.free.fr> <536f99eb$0$2109$426a74cc@news.free.fr> <53705d34$0$2374$426a74cc@news.free.fr> <537082f2$0$2141$426a74cc@news.free.fr> Message-ID: <53709196$0$2074$426a74cc@news.free.fr> Le 12/05/14 10:14, lgabiot a ?crit : > So if I follow you, if the Pyaudio part is "Non-blocking" there would be > a way to make it work without the two threads things. I'm back to the > Pyaudio doc, and try to get my head around the callback method, which > might be the good lead. So far, if I understand correctly PyAudio, the callback method is a way to do some sort of computing on a Pyaudio stream, by declaring a function (the "callback" one) at stream opening time, the callback function being executed in a separate thread (as per the Pyaudio documentation)... Still investigating. From preethidasa at gmail.com Mon May 12 05:17:57 2014 From: preethidasa at gmail.com (Preethi) Date: Mon, 12 May 2014 02:17:57 -0700 (PDT) Subject: Error while calling round() from future.builtins In-Reply-To: <536e1408$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <591c2939-7648-47f5-854e-ad254a8a732f@googlegroups.com> <536e1408$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, May 10, 2014 5:26:56 PM UTC+5:30, Steven D'Aprano wrote: > On Sat, 10 May 2014 04:39:05 -0700, Preethi wrote: > > > > > Hi, > > > > > > I am new to python. I am getting an error "AttributeError: type object > > > 'Decimal' has no attribute 'from_float'" when I run the following in > > > python prompt: > > > > > >>>> from future.builtins import int, round > > > > I get an error when I try that: > > > > > > py> from future.builtins import int, round > > Traceback (most recent call last): > > File "", line 1, in > > ImportError: No module named future.builtins > > > > > > Perhaps you are using the third-party library "future"? > > > > https://pypi.python.org/pypi/future > > > > If so, then I believe the library is buggy and you should report it to > > the Centos package maintainer. You might also manually install a more > > recent version of future. > > > > Decimal.from_float was only added in 2.7, it is not available in 2.6. > > > > https://docs.python.org/2/library/decimal.html#decimal.Decimal.from_float > > > > > > > > > > -- > > Steven D'Aprano > > http://import-that.dreamwidth.org/ Yes, I upgraded to 0.12.0 and it worked! Thanks a lot! From srikrishnamohan at gmail.com Mon May 12 05:38:39 2014 From: srikrishnamohan at gmail.com (km) Date: Mon, 12 May 2014 15:08:39 +0530 Subject: PyPy updated In-Reply-To: References: Message-ID: I tried compiling pandas on pypy 2.3 but it gave error as follows numpy/core/src/multiarray/scalarapi.c:742:16: error: 'PyUnicodeObject' has no member named 'str' uni->str[length] = 0; ^ numpy/core/src/multiarray/scalarapi.c:743:16: error: 'PyUnicodeObject' has no member named 'length' uni->length = length; Cleaning up... Command /home/user/test101/bin/pypy-c -c "import setuptools, tokenize;__file__='/home/user/test101/build/numpy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-d2Eg7e-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/user/test101/include/site/python2.7 failed with error code 1 in /home/user/test101/build/numpy Storing debug log for failure in /home/user/.pip/pip.log Regards, Krishna On Fri, May 9, 2014 at 7:18 PM, Mark Lawrence wrote: > Might interest some of you fine folk out there :- > > http://morepypy.blogspot.co.uk/2014/05/pypy-23-terrestrial-arthropod-trap. > html > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what > you can do for our language. > > Mark Lawrence > > --- > This email is free from viruses and malware because avast! Antivirus > protection is active. > http://www.avast.com > > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturla.molden at gmail.com Mon May 12 09:42:05 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Mon, 12 May 2014 15:42:05 +0200 Subject: What is the difference between 32 and 64 bit Python on Windows 7 64 bit? In-Reply-To: References: Message-ID: On 11/05/14 08:56, Ross Gayler wrote: > It looks to me as though 32 and 64 bit versions of Python on 64 bit > Windows are both really 32 bit Python, differing only in how they > interact with Windows. No! Pointers are 64 bit, Python integers (on Python 2.x) are 32 bit. Microsoft decided to use a 32 bit long in MSVC for backwards compatiblity, but also because the AMD64 (x86-64) architecture was designed to use a 64 address with a 32 bit offset. (A 64 bit long was originally slightly less efficient.) You can see the value of 64 bit Python e.g. if you allocate a lot of objects or if you try to mmap a huge file. With 32 bit Python you are limited to only 2 GB of virtual memory. In 64 bit Python you can in practice mmap as much as you want. The element size of what you try to index also matters. While a C long and a Python int is 32 bit on Windows, 64-bit Python will use a 64-bit offset internally (Py_ssize_t and Py_intptr_t) even on Windows. The 32 bit Python int just limits how many objects you can index from Python space before Python roll over to using long instead of int. It does not limit the amount of memory a Python int can index. In is only when you index an array of bytes you will see the roll-over from Python int to Python long at the 2 GB limit. Typically, object will be much larger than one byte. Here are two examples: - A one-dimensional NumPy array with dtype np.float64 can keep 16 GB of data before a 32 bit index is too small and Python starts to use long. A two-dimensional NumPy array with dtype np.float64 can keep 256 GB of data before a 32 bit index is too small. - A Python list stores internally an array of pointers, each of which is 64 bit. So just indexing those goes up to 16 GB of pointer data before the int rolls over. Then each of these pointers point to a Python object. A Python float on my computer (not Windows) is 24 bytes, which I got from sys.getsizeof(1.) So 2**32 of those are another 383 GB. So if I indexed a list of Python floats on this computer, Python could handle an almost 400 GB data structure with a 32 bit int as indexer without rolling over to long. This is obviously way beyond anything the 2 GB limit on 32 bit Python allows. Sturla From invalid at invalid.invalid Mon May 12 10:07:38 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 12 May 2014 14:07:38 +0000 (UTC) Subject: Fortran References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <536FBBE0.9040902@stoneleaf.us> <53700493$0$29980$c3e8da3$5496439d@news.astraweb.com> <53701fcd$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-05-12, Steven D'Aprano wrote: > On Mon, 12 May 2014 00:51:01 +0100, MRAB wrote: >> On 2014-05-12 00:15, Steven D'Aprano wrote: >>> The F and J keys have "F" and "J" printed on them instead of "G" and >>> "K". They're also in slightly different positions, offset one position >>> to the left. Otherwise they are identical, to the limits of my vision >>> and touch. (I haven't tried measuring them with a micrometer, or doing >>> chemical analysis of the material they are made of.) Really? No rised dots or ridges? >> Maybe keyboards are different where you are! :-) > > Certainly not. However they may be different where *you* are :-P > > I'm using an IBM keyboard, model SK-8820. > >> Mine have an little ridge on the keytop of those keys. > > I've seen keyboards with those, but not many. I would guess that at least 95% of the keyboards I've seen in the past 30 years have had them.... -- Grant Edwards grant.b.edwards Yow! One FISHWICH coming at up!! gmail.com From alister.nospam.ware at ntlworld.com Mon May 12 10:14:07 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Mon, 12 May 2014 14:14:07 GMT Subject: Fortran References: <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <536f2227$0$29980$c3e8da3$5496439d@news.astraweb.com> <871tw0s2kl.fsf@elektro.pacujo.net> <536FBBE0.9040902@stoneleaf.us> <53700493$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 11 May 2014 20:14:14 -0400, Roy Smith wrote: > In article , > MRAB wrote: > >> On 2014-05-12 00:15, Steven D'Aprano wrote: >> > On Sun, 11 May 2014 14:43:19 -0400, Roy Smith wrote: >> > >> >> In article , >> >> Chris Angelico wrote: >> >> >> >>> Some things are more standardized than others. A piano keyboard is >> >>> incredibly standard, to make it possible to play without having to >> >>> look at your fingers (even when jumping your hands around, which >> >>> doesn't happen as much on a computer keyboard) >> >> >> >> Speaking of which, here's a trivia question. Without looking at >> >> your keyboard, describe how the "F" and "J" keys (assuming a >> >> US-English key layout) differ from, say, the "G" and "K" keys. >> > >> > The F and J keys have "F" and "J" printed on them instead of "G" and >> > "K". >> > They're also in slightly different positions, offset one position to >> > the left. Otherwise they are identical, to the limits of my vision >> > and touch. >> > (I haven't tried measuring them with a micrometer, or doing chemical >> > analysis of the material they are made of.) >> > >> Maybe keyboards are different where you are! :-) >> >> Mine have an little ridge on the keytop of those keys. > > Yup. Long before the days of computers, the F/J keys have had some sort > of tactile feedback (a raised dot or whatever) so you can tell when you > hands are in the home position by feel. Pyjrteodr upi vsm rmf i[ yu[omh > ;olr yjod/ I once used an Osborn one where each key-cap was individually sculptured to fit the finger depending on its position on the keyboard. -- Bridge ahead. Pay troll. From breamoreboy at yahoo.co.uk Mon May 12 11:19:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 12 May 2014 16:19:17 +0100 Subject: Everything you did not want to know about Unicode in Python 3 Message-ID: This was *NOT* written by our resident unicode expert http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/ Posted as I thought it would make a rather pleasant change from interminable threads about names vs values vs variables vs objects. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From xs.nepaul at gmail.com Mon May 12 11:16:26 2014 From: xs.nepaul at gmail.com (xs.nepaul at gmail.com) Date: Mon, 12 May 2014 08:16:26 -0700 (PDT) Subject: a better way to operate svn with python(better than pysvn)? Message-ID: From musicalhacksaw at yahoo.co.uk Mon May 12 12:02:42 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Mon, 12 May 2014 09:02:42 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> Message-ID: Hi Ian, thank you for your help. Yes that is the book by Vineeth J Nair. At the top of page 12, at step 1 it says : 1.Download the latest tarball from https://pypi.python.org/packages/source/b/beautifulsoup4/. So yes, the version the book is dealing with is beautiful soup 4. I am using Pyhon 2.7, I have removed Python 3.4. Also on the bottom of page 10, Mr Nair states: Pick the path variagble and add the following section to the Path variable: ;C:\PythonXY for example C:\Python27 Which tells me that the Python version cited in the book must be 2.7 I downloaded beautiful soup 4 last night. I unzipped it with 'Just unzip it' to a folder I called Beautiful Soup, the same as I did with the previous beautiful soup download. The console return is as below, showing that I am now facing the same conundrum as yesterday, before changing my version of Beautiful Soup. re: -------------------------------------------------------------------------------- Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Intel Atom>cd "c:\Beautiful Soup" c:\Beautiful Soup>Beautiful Soup>c:\Python27\python setup.py install 'Beautiful' is not recognized as an internal or external command, operable program or batch file. c:\Beautiful Soup> From musicalhacksaw at yahoo.co.uk Mon May 12 12:17:22 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Mon, 12 May 2014 09:17:22 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> Message-ID: The version of Python the book seems to be referring to is 2.7, re: bottom of page 10- 'Pick the Path variable and add the following section to the Path variable: ;C:\PythonXY for example C:\Python 27' The version of Beautiful Soup seems to be Beautiful Soup 4 as at the top of page 12 it states: '1.Download the latest tarball from https://pypi.python.org/packages/source/b/beautifulsoup4/.' I have downloaded and unzipped to a folder called 'Beautiful Soup' on the C drive the Beautiful Soup 4 version. I am using the Python 2.7 console and IDLE, I have removed the 3.4 version. All the same I seem to be having difficulties again as console wont accept the code it did when it was the previous version of BS that I used yesterday. I realise I would not be having this problem if I proceeded to input the 'Hello World' code on the Python console, but as said, the text never specifically said 'change to Python 2.7 console'. I thought the problem was with the BS version and so changed it, but now can't even get as far as I had before changing it. Anyhow be that as it may, this is the console response to my input: -------------------------------------------------------------------------------- Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Intel Atom>cd "c:\Beautiful Soup" c:\Beautiful Soup>Beautiful Soup>c:\Python27\python setup.py install 'Beautiful' is not recognized as an internal or external command, operable program or batch file. c:\Beautiful Soup> From musicalhacksaw at yahoo.co.uk Mon May 12 12:23:48 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Mon, 12 May 2014 09:23:48 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> Message-ID: <1749a514-897f-47f7-9ca2-e04dc1afb885@googlegroups.com> Thank you for your advice. I did buy a book on Python, 'Hello Python' but the code in it wouldn't run, so I returned it to the shop for a refund. I am going to visit the local library to see if they have any books on Python. I am familiar with Java and Pascal, and looking at a few You tubes on the subject, thought it was not much different, and shares many of the oop concepts (variables, initializing, expressions, methods, and so on, but I realize there is no point in walking backwards in new territory. From musicalhacksaw at yahoo.co.uk Mon May 12 12:35:05 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Mon, 12 May 2014 09:35:05 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> Message-ID: Dear Ian, The book does recommend to use Python 2.7 (see bottom line of page 10). The book also recommends to use Beautiful Soup 4. You are right that in that I have placed the unzipped BS4 folder within a folder, and I therefore removed the contents of the inner folder and transferred them to the outer folder. The console now can access the contents of the Beautiful Soup folder, but it is still having problems with it as the last output to my console demonstrates : Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Intel Atom>cd "c:\Beautiful Soup" c:\Beautiful Soup>c:\Python27\python setup.py install running install running build running build_py error: package directory 'bs4' does not exist c:\Beautiful Soup> From joseph.martinot-lagarde at m4x.org Mon May 12 13:01:52 2014 From: joseph.martinot-lagarde at m4x.org (Joseph Martinot-Lagarde) Date: Mon, 12 May 2014 19:01:52 +0200 Subject: NumPy, SciPy, & Python 3X Installation/compatibility issues In-Reply-To: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> References: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> Message-ID: <5370FE80.5030909@m4x.org> Le 10/05/2014 19:07, esawiek at gmail.com a ?crit : > Hi All-- > > Let me state at the start that I am new to Python. I am moving away from Fortran and Matlab to Python and I use all different types of numerical and statistical recipes in my work. I have been reading about NumPy and SciPy and could not find any definitive answers to my questions, below. I had run into many mostly installation problems that I could never get NumPy or SciPy to work with Python 3.3 or newer. I am using Windows7 64 bit OS. > A few questions: > 1. What are the latest versions of NumPy and SciPy that are compatible with Python 3.3 or newer and Windows7 64 bit? > 2. What is the best source to download and install them on my computer? > 3. Are they all installable on my OS w/o any major problems/addition? > 4. In the long run, would it be better to use UNIX instead of Windows, if I were to use Python for all of my research? > Thanks in advance. EK > Building the scientific libraries on windows is very tricky because you need a compatible C and Fortran compiler, as well as some libraries. The usual and recommended route is to use python distributions where the most used libraries are installed. You can still use pip to install additionnal packages. You have a list over here: http://www.scipy.org/install.html --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com From joseph.martinot-lagarde at m4x.org Mon May 12 13:05:25 2014 From: joseph.martinot-lagarde at m4x.org (Joseph Martinot-Lagarde) Date: Mon, 12 May 2014 19:05:25 +0200 Subject: How can this assert() ever trigger? In-Reply-To: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> References: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <5370FF55.3080900@m4x.org> Le 10/05/2014 17:24, Albert van der Horst a ?crit : > I have the following code for calculating the determinant of > a matrix. It works inasfar that it gives the same result as an > octave program on a same matrix. > > / ---------------------------------------------------------------- > > def determinant( mat ): > ''' Return the determinant of the n by n matrix mat > i row j column > Destroys mat ! ''' > #print "getting determinat of", mat > n=len(mat) > nom = 1. > if n == 1: return mat[0][0] > lastr = mat.pop() > jx=-1 > for j in xrange(n): > if lastr[j]: > jx=j > break > if jx==-1: return 0. > result = lastr[jx] > assert(result<>0.) > # Make column jx zero by subtracting a multiple of the last row. > for i in xrange(n-1): > pivot = mat[i][jx] > if 0. == pivot: continue > assert(result<>0.) > nom *= result # Compenstate for multiplying a row. > for j in xrange(n): > mat[i][j] *= result > for j in xrange(n): > mat[i][j] -= pivot*lastr[j] > # Remove colunm jx > for i in xrange(n-1): > x= mat[i].pop(jx) > assert( x==0 ) > > if (n-1+jx)%2<>0: result = -result > det = determinant( mat ) > assert(nom<>0.) > return result*det/nom > > /----------------------------------------- > > Now on some matrices the assert triggers, meaning that nom is zero. > How can that ever happen? mon start out as 1. and gets multiplied > with a number that is asserted to be not zero. > > Any hints appreciated. > > Groetjes Albert > I know it's not the question, but if you want a replacement for octave did you try numpy (and scipy) ? The determinant would be computer faster and with less memory than with your function. --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com From scottcabit at gmail.com Mon May 12 13:35:53 2014 From: scottcabit at gmail.com (scottcabit at gmail.com) Date: Mon, 12 May 2014 10:35:53 -0700 (PDT) Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> On Friday, May 9, 2014 8:12:57 PM UTC-4, Steven D'Aprano wrote: > Good: > > > > fStr = re.sub(b'‒', b'-', fStr) > Doesn't work...the document has been verified to contain endash and emdash characters, but this does NOT replace them. > > > Better: > > > > fStr = fStr.replace(b'‒', b'-') > > Still doesn't work > > > > But having said that, you actually can make use of the nuclear-powered > > bulldozer, and do all the replacements in one go: > > > > Best: > > > > # Untested > > fStr = re.sub(b'&#x(201[2-5])|(2E3[AB])|(00[2A]D)', b'-', fStr) Still doesn't work. Guess whatever the code is for endash and mdash are not the ones I am using.... From alister.nospam.ware at ntlworld.com Mon May 12 13:47:48 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Mon, 12 May 2014 17:47:48 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: Message-ID: <8P7cv.78617$Sp6.8377@fx15.am4> On Mon, 12 May 2014 16:19:17 +0100, Mark Lawrence wrote: > This was *NOT* written by our resident unicode expert > http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/ > > Posted as I thought it would make a rather pleasant change from > interminable threads about names vs values vs variables vs objects. Surely those example programs are not the pythonoic way to do things or am i missing something? if those code samples are anything to go by this guy makes JMF look sensible. -- The Heineken Uncertainty Principle: You can never be sure how many beers you had last night. From ian.g.kelly at gmail.com Mon May 12 14:31:11 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 12 May 2014 12:31:11 -0600 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <8P7cv.78617$Sp6.8377@fx15.am4> References: <8P7cv.78617$Sp6.8377@fx15.am4> Message-ID: On Mon, May 12, 2014 at 11:47 AM, alister wrote: > On Mon, 12 May 2014 16:19:17 +0100, Mark Lawrence wrote: > >> This was *NOT* written by our resident unicode expert >> http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/ >> >> Posted as I thought it would make a rather pleasant change from >> interminable threads about names vs values vs variables vs objects. > > Surely those example programs are not the pythonoic way to do things or > am i missing something? The _is_binary_reader and _is_binary_writer functions look like they could be simplified by calling isinstance on the io object itself against io.TextIOBase, io.BufferedIOBase or io.RawIOBase, rather than doing those odd 0-length reads and writes. And then perhaps those exception-swallowing try-excepts wouldn't be necessary. But perhaps there's a non-obvious reason why it's written the way it is. And there appears to be a bug where everything *except* the filename '-' is treated as stdin, so the script probably hasn't been tested at all. > if those code samples are anything to go by this guy makes JMF look > sensible. This is an ad hominem. Just because his code sucks doesn't mean he's wrong about the state of Unicode and UNIX in Python 3. From musicalhacksaw at yahoo.co.uk Mon May 12 15:17:54 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Mon, 12 May 2014 12:17:54 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> Message-ID: <0f370792-1a98-4bb5-84e8-f0277bac4bed@googlegroups.com> I did download the latest version of Beautiful Soup 4 from the download site, as the book suggested. From python at mrabarnett.plus.com Mon May 12 15:42:22 2014 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 May 2014 20:42:22 +0100 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> Message-ID: <5371241E.10309@mrabarnett.plus.com> On 2014-05-12 19:31, Ian Kelly wrote: > On Mon, May 12, 2014 at 11:47 AM, alister > wrote: >> On Mon, 12 May 2014 16:19:17 +0100, Mark Lawrence wrote: >> >>> This was *NOT* written by our resident unicode expert >>> http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/ >>> >>> Posted as I thought it would make a rather pleasant change from >>> interminable threads about names vs values vs variables vs objects. >> >> Surely those example programs are not the pythonoic way to do things or >> am i missing something? > > The _is_binary_reader and _is_binary_writer functions look like they > could be simplified by calling isinstance on the io object itself > against io.TextIOBase, io.BufferedIOBase or io.RawIOBase, rather than > doing those odd 0-length reads and writes. And then perhaps those > exception-swallowing try-excepts wouldn't be necessary. But perhaps > there's a non-obvious reason why it's written the way it is. > How about checking sys.stdin.mode and sys.stdout.mode? > And there appears to be a bug where everything *except* the filename > '-' is treated as stdin, so the script probably hasn't been tested at > all. > >> if those code samples are anything to go by this guy makes JMF look >> sensible. > > This is an ad hominem. Just because his code sucks doesn't mean he's > wrong about the state of Unicode and UNIX in Python 3. > From sturla.molden at gmail.com Mon May 12 15:59:19 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Mon, 12 May 2014 19:59:19 +0000 (UTC) Subject: NumPy, SciPy, & Python 3X Installation/compatibility issues References: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> Message-ID: <407129721421615759.310945sturla.molden-gmail.com@news.gmane.org> wrote: > 4. In the long run, would it be better to use UNIX instead of Windows, if > I were to use Python for all of my research? > Thanks in advance. EK For scientific computing, a UNIX or Linux system is clearly preferable. Most of the scientific computing software is built around the UNIX ecosystem. This is the reason many scientists prefer to work on a Mac. I have a UNIX system ready to use in the terminal, developer tools are free, and it stills runs all the deskop apps I need (even Microsoft Office). Apple even provides us with highly optimized LAPACK, BLAS and FFT libraries as a part of the operating system (Accelerate Framework). Even the free NumPy and SciPy installers can link to Accelerate on a Mac. Matlab runs on Linux and Mac as well. That is not s reason to stay on Windows. An alternative to a Mac is to install Oracle Virtualbox and use it to run Windows or Linux. Windows as host tends to work best on a laptop. On a workstation it does not matter. If you are using Windows now and are happy with it, I would suggest you just install Ubuntu into an VM with Virtualbox and forget about Windows installers for Python, NumPy, SciPy, et al. Spend some money to buy an SSD drive and more RAM if you need. The performance with Virtualbox is excellent. Get a Python distro that uses MKL for faster linear algebra, such as Enthought or Anaconda. Windows can be a great desktop OS because of all the available applications. It sucks rocks for any coding or scientific computing. But there is no law that says you need to use either. You can have the best of both world's if you like. Sturla From glyph at twistedmatrix.com Mon May 12 15:21:47 2014 From: glyph at twistedmatrix.com (Glyph) Date: Mon, 12 May 2014 12:21:47 -0700 Subject: [Twisted-web] Twisted 14.0.0 Release Announcement In-Reply-To: <52611128-3708-40CE-86F5-C63FE9054A6B@atleastfornow.net> References: <52611128-3708-40CE-86F5-C63FE9054A6B@atleastfornow.net> Message-ID: <2B16A476-4F01-499A-8CF9-F7D3806DBD11@twistedmatrix.com> On May 12, 2014, at 4:07 AM, HawkOwl wrote: > Twisted Agent can also now do HTTPS hostname verification. I feel that it's important to note that Twisted Web's client Agent *does* do HTTPS hostname verification by default; you don't need to turn it on ;). -glyph -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon May 12 18:54:09 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 12 May 2014 16:54:09 -0600 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> Message-ID: On Mon, May 12, 2014 at 10:35 AM, Simon Evans wrote: > Dear Ian, > The book does recommend to use Python 2.7 (see bottom line of page 10). > The book also recommends to use Beautiful Soup 4. > You are right that in that I have placed the unzipped BS4 folder within a folder, and I therefore removed the contents of the inner folder and transferred them to the outer folder. > The console now can access the contents of the Beautiful Soup folder, but it is still having problems with it as the last output to my console demonstrates : > > > Microsoft Windows [Version 6.1.7601] > > Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > C:\Users\Intel Atom>cd "c:\Beautiful Soup" > > c:\Beautiful Soup>c:\Python27\python setup.py install > running install > running build > running build_py > error: package directory 'bs4' does not exist In the same folder where setup.py is, there should be a bs4 folder. You might want to just wipe your Beautiful Soup directory and do a clean unzip. From ian.g.kelly at gmail.com Mon May 12 18:16:22 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 12 May 2014 16:16:22 -0600 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <5371241E.10309@mrabarnett.plus.com> References: <8P7cv.78617$Sp6.8377@fx15.am4> <5371241E.10309@mrabarnett.plus.com> Message-ID: On Mon, May 12, 2014 at 1:42 PM, MRAB wrote: > How about checking sys.stdin.mode and sys.stdout.mode? Seems to work, but I notice that the docs only define the mode attribute for the FileIO class, which sys.stdin and sys.stdout are not instances of. From flebber.crue at gmail.com Mon May 12 19:34:55 2014 From: flebber.crue at gmail.com (flebber) Date: Mon, 12 May 2014 16:34:55 -0700 (PDT) Subject: SQLAlchemy - web framework ? Message-ID: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> If I want to use SQLAlchemy as my ORM what would be the best option for a web framework? It appears the general advice regarding Django is to do it the Django way and use the django ORM and change it out for SQLAlchemy. That to me limited knowledge leaves flask, pyramid and turbogears 2. So if I wanted to not build it all myself as with flask then potentially pyramid, turbogears is the best option? Is this true? I have completed the TG2 intro tutorial and have built several small things with flask although I feel offput by doing anything bigger in flask. See what I have done is got my python knowledge to a fair point where I can do useful things, good knowledge of web HTML/CSS, built a few small projects in flask to get an idea for python web, completed django tutorials, turogears tutorials and now looking to design out a bigger project I want to set myself and i am trying to compile the parts so I can see what I will need to use and gather info to cover what othe things I will need to know. Do I have a false fear of flask and doing bigger projects? So at this point I know I want SQLAlchemy, will use postgres(although mysql/maria would work fine). Any pratical advice warmly welcomed, I think I am thining too much aimlessly maybe. http://turbogears.org/ http://www.pylonsproject.org/ http://flask.pocoo.org/ https://www.djangoproject.com/ http://www.tornadoweb.org/en/stable/ From sturla.molden at gmail.com Mon May 12 19:41:14 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 13 May 2014 01:41:14 +0200 Subject: What is the difference between 32 and 64 bit Python on Windows 7 64 bit? In-Reply-To: References: Message-ID: On 12/05/14 15:42, Sturla Molden wrote: > - A one-dimensional NumPy array with dtype np.float64 can keep 16 GB of > data before a 32 bit index is too small and Python starts to use long. A > two-dimensional NumPy array with dtype np.float64 can keep 256 GB of > data before a 32 bit index is too small. Oops, the latter should be 34359738336 GB (that is, 32767 pentabytes) :) Sturla From rosuav at gmail.com Mon May 12 19:42:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 09:42:14 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> Message-ID: On Tue, May 13, 2014 at 4:31 AM, Ian Kelly wrote: > Just because his code sucks doesn't mean he's > wrong about the state of Unicode and UNIX in Python 3. Uhm... I think wrongness of code is generally fairly indicative of wrongness of thinking :) If I write a rant about how Python's list type sucks and it turns out my code is using it like a cons cell and never putting more than two elements into a list, then you would accurately conclude that I'm wrong about the state of data type support in Python. I don't have a problem with someone coming to the list here with misconceptions. That's what discussions are for. But rants like that, on blogs, I quickly get weary of reading. The tone is always "Look what's so wrong", not inviting dialogue, and I can't be bothered digging into the details to compose a full response. Chances are the author's (a) not looking at what 3.4 and what's happened to improve things (and certainly not 3.5 and what's going to happen), and (b) not listening to responses anyway. ChrisA From sturla.molden at gmail.com Mon May 12 20:05:45 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 13 May 2014 02:05:45 +0200 Subject: What is the difference between 32 and 64 bit Python on Windows 7 64 bit? In-Reply-To: References: Message-ID: On 11/05/14 08:56, Ross Gayler wrote: > Is that true?I have spent a couple of hours searching for a definitive > description of the difference between the 32 and 64 bit versions of > Python for Windows and haven't found anything. Why do you care if a Python int object uses 32 or 64 bits internally? Python 2.x will automatically switch to long when needed. The size of the Python integer is an internal implementation detail you will not notice. Python knows when to use a long instead of an int. Python 3.x does not even have a fixed-size integer. 64 bit Python is 64 bit Python, even on Windows. The difference between 32 bit and 64 bit Python is what you would expect: The size of a C pointer is 64 bits, and the virtual address space is much larger (in general not 2**63-1 bytes, but some OS dependent value). Sturla From python at mrabarnett.plus.com Mon May 12 20:07:12 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 13 May 2014 01:07:12 +0100 Subject: What is the difference between 32 and 64 bit Python on Windows 7 64 bit? In-Reply-To: References: Message-ID: <53716230.8080001@mrabarnett.plus.com> On 2014-05-13 00:41, Sturla Molden wrote: > On 12/05/14 15:42, Sturla Molden wrote: > >> - A one-dimensional NumPy array with dtype np.float64 can keep 16 GB of >> data before a 32 bit index is too small and Python starts to use long. A >> two-dimensional NumPy array with dtype np.float64 can keep 256 GB of >> data before a 32 bit index is too small. > > > Oops, the latter should be 34359738336 GB (that is, 32767 pentabytes) :) > Double oops, Sturla, it's petabyte (well, pebibyte actually). :-) From rosuav at gmail.com Mon May 12 20:09:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 10:09:58 +1000 Subject: What is the difference between 32 and 64 bit Python on Windows 7 64 bit? In-Reply-To: References: Message-ID: On Tue, May 13, 2014 at 10:05 AM, Sturla Molden wrote: > On 11/05/14 08:56, Ross Gayler wrote: > >> Is that true?I have spent a couple of hours searching for a definitive >> description of the difference between the 32 and 64 bit versions of >> Python for Windows and haven't found anything. > > > Why do you care if a Python int object uses 32 or 64 bits internally? Python > 2.x will automatically switch to long when needed. The size of the Python > integer is an internal implementation detail you will not notice. Python > knows when to use a long instead of an int. Python 3.x does not even have a > fixed-size integer. Sometimes you just want to confirm. :) Or maybe you want your program to be able to detect which it's on. There are ways of doing both, but sys.maxint isn't one of them, as it's specific to the int->long promotion of Py2. ChrisA From sturla.molden at gmail.com Mon May 12 20:18:49 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 13 May 2014 02:18:49 +0200 Subject: What is the difference between 32 and 64 bit Python on Windows 7 64 bit? In-Reply-To: References: Message-ID: On 13/05/14 02:09, Chris Angelico wrote: > Sometimes you just want to confirm. :) Or maybe you want your program > to be able to detect which it's on. There are ways of doing both, but > sys.maxint isn't one of them, as it's specific to the int->long > promotion of Py2. The OPs main mistake, I guess, was to assume that sys.maxint is the biggest integer value Python 2.x can use. Sturla From iurisilvio at gmail.com Mon May 12 20:44:08 2014 From: iurisilvio at gmail.com (Iuri) Date: Mon, 12 May 2014 21:44:08 -0300 Subject: SQLAlchemy - web framework ? In-Reply-To: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> References: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> Message-ID: I don't know what exactly you mean with "wanted to not build it all myself", but Flask is great with SQLAlchemy. You have the Flask-SQLAlchemy extension and it has a lot of other integrations, like Flask-Admin. You don't have to fear flask to bigger projects. To be honest, I prefer it instead of Django because I can grow the project the way I want, without framework strings. On Mon, May 12, 2014 at 8:34 PM, flebber wrote: > If I want to use SQLAlchemy as my ORM what would be the best option for a > web framework? > > It appears the general advice regarding Django is to do it the Django way > and use the django ORM and change it out for SQLAlchemy. > > That to me limited knowledge leaves flask, pyramid and turbogears 2. So if > I wanted to not build it all myself as with flask then potentially pyramid, > turbogears is the best option? > > Is this true? I have completed the TG2 intro tutorial and have built > several small things with flask although I feel offput by doing anything > bigger in flask. > > See what I have done is got my python knowledge to a fair point where I > can do useful things, good knowledge of web HTML/CSS, built a few small > projects in flask to get an idea for python web, completed django > tutorials, turogears tutorials and now looking to design out a bigger > project I want to set myself and i am trying to compile the parts so I can > see what I will need to use and gather info to cover what othe things I > will need to know. > > Do I have a false fear of flask and doing bigger projects? > > So at this point I know I want SQLAlchemy, will use postgres(although > mysql/maria would work fine). > > Any pratical advice warmly welcomed, I think I am thining too much > aimlessly maybe. > > http://turbogears.org/ > http://www.pylonsproject.org/ > http://flask.pocoo.org/ > https://www.djangoproject.com/ > http://www.tornadoweb.org/en/stable/ > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben at benfinney.id.au Mon May 12 20:55:08 2014 From: ben at benfinney.id.au (Ben Finney) Date: Tue, 13 May 2014 10:55:08 +1000 Subject: SQLAlchemy - web framework ? References: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> Message-ID: <85ha4ua45v.fsf@benfinney.id.au> flebber writes: > If I want to use SQLAlchemy as my ORM what would be the best option > for a web framework? > > It appears the general advice regarding Django is to do it the Django > way and use the django ORM and change it out for SQLAlchemy. You don't say any more about this. Have you evaluated this option? What leads you to believe it is not satisfactory (as implied by the rest of your message)? -- \ ?We are no more free to believe whatever we want about God than | `\ we are free to adopt unjustified beliefs about science or | _o__) history [?].? ?Sam Harris, _The End of Faith_, 2004 | Ben Finney From roy at panix.com Mon May 12 21:04:23 2014 From: roy at panix.com (Roy Smith) Date: Mon, 12 May 2014 21:04:23 -0400 Subject: SQLAlchemy - web framework ? References: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> Message-ID: In article <17149f49-bb71-4c97-9d07-d80766b93865 at googlegroups.com>, flebber wrote: > If I want to use SQLAlchemy as my ORM what would be the best option for a web > framework? > > It appears the general advice regarding Django is to do it the Django way and > use the django ORM and change it out for SQLAlchemy. I'm not quite sure how to parse that last sentence. In any case, if you're afraid of using a third-party ORM with django, don't worry about that. We make extensive use of django and do not use the supplied ORM layer. In our case, we couldn't, because we're using MongoDB (we use mongoengine as our ORM). Django is modular enough that there's really no problem swapping the ORM out for another component. From steve+comp.lang.python at pearwood.info Mon May 12 21:18:35 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 May 2014 01:18:35 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> Message-ID: <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 12 May 2014 17:47:48 +0000, alister wrote: > On Mon, 12 May 2014 16:19:17 +0100, Mark Lawrence wrote: > >> This was *NOT* written by our resident unicode expert >> http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/ >> >> Posted as I thought it would make a rather pleasant change from >> interminable threads about names vs values vs variables vs objects. > > Surely those example programs are not the pythonoic way to do things or > am i missing something? Feel free to show us your version of "cat" for Python then. Feel free to target any version you like. Don't forget to test it against files with names and content that: - aren't valid UTF-8; - are valid UTF-8, but not valid in the local encoding. > if those code samples are anything to go by this guy makes JMF look > sensible. Armin Ronacher is an extremely experienced and knowledgeable Python developer, and a Python core developer. He might be wrong, but he's not *obviously* wrong. Unicode is hard, not because Unicode is hard, but because of legacy problems. I can create a file on a machine that uses ISO-8859-7 for the file name, put JShift-JIS encoded text inside it, transfer it to a machine that uses Windows-1251 as the file system encoding, then SSH into that machine from a system using Big5, and try to make sense of it. If everybody used UTF-8 any time data touched a disk or network, we'd be laughing. It would all be so simple. Reading Armin's post, I think that all that is needed to simplify his Python 3 version is: - have a bytes version of sys.argv (bargv? argvb?) and read the file names from that; - have a simple way to write bytes to stdout and stderr. Most programs won't need either of those, but file system utilities will. -- Steven D'Aprano http://import-that.dreamwidth.org/ From flebber.crue at gmail.com Mon May 12 21:29:42 2014 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 13 May 2014 11:29:42 +1000 Subject: SQLAlchemy - web framework ? In-Reply-To: References: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> Message-ID: I am saying 'do it myself' in that with flask that provide a small base and then all functionality is added by me directly, with the assistance of community modules. Compared to Django whose developers have created an integrated set of defaults with more functionality standard, which is good if you like the defaults. Sayth On 13/05/2014 10:44 am, "Iuri" wrote: > I don't know what exactly you mean with "wanted to not build it all > myself", but Flask is great with SQLAlchemy. You have the Flask-SQLAlchemy > extension and it has a lot of other integrations, like Flask-Admin. > > You don't have to fear flask to bigger projects. To be honest, I prefer it > instead of Django because I can grow the project the way I want, without > framework strings. > > > > > On Mon, May 12, 2014 at 8:34 PM, flebber wrote: > >> If I want to use SQLAlchemy as my ORM what would be the best option for a >> web framework? >> >> It appears the general advice regarding Django is to do it the Django way >> and use the django ORM and change it out for SQLAlchemy. >> >> That to me limited knowledge leaves flask, pyramid and turbogears 2. So >> if I wanted to not build it all myself as with flask then potentially >> pyramid, turbogears is the best option? >> >> Is this true? I have completed the TG2 intro tutorial and have built >> several small things with flask although I feel offput by doing anything >> bigger in flask. >> >> See what I have done is got my python knowledge to a fair point where I >> can do useful things, good knowledge of web HTML/CSS, built a few small >> projects in flask to get an idea for python web, completed django >> tutorials, turogears tutorials and now looking to design out a bigger >> project I want to set myself and i am trying to compile the parts so I can >> see what I will need to use and gather info to cover what othe things I >> will need to know. >> >> Do I have a false fear of flask and doing bigger projects? >> >> So at this point I know I want SQLAlchemy, will use postgres(although >> mysql/maria would work fine). >> >> Any pratical advice warmly welcomed, I think I am thining too much >> aimlessly maybe. >> >> http://turbogears.org/ >> http://www.pylonsproject.org/ >> http://flask.pocoo.org/ >> https://www.djangoproject.com/ >> http://www.tornadoweb.org/en/stable/ >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon May 12 21:39:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 11:39:23 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 13, 2014 at 11:18 AM, Steven D'Aprano wrote: > Reading Armin's post, I think that all that is needed to simplify his > Python 3 version is: > > - have a bytes version of sys.argv (bargv? argvb?) and read > the file names from that; argb? :) > - have a simple way to write bytes to stdout and stderr. I'm not sure how that goes with I/O redirection, but sure. ChrisA From wuwei23 at gmail.com Mon May 12 21:45:27 2014 From: wuwei23 at gmail.com (alex23) Date: Tue, 13 May 2014 11:45:27 +1000 Subject: a better way to operate svn with python(better than pysvn)? In-Reply-To: References: Message-ID: On 13/05/2014 1:16 AM, xs.nepaul at gmail.com wrote: > ... Rather than just send an empty message, why not explain what you don't like about pysvn so that someone could provide more pertinant advice? But since you didn't: https://pypi.python.org/pypi?%3Aaction=search&term=svn&submit=search From harrismh777 at gmail.com Mon May 12 21:58:45 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 12 May 2014 20:58:45 -0500 Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/12/14 8:18 PM, Steven D'Aprano wrote: > Unicode is hard, not because Unicode is hard, but because of legacy > problems. Yes. To put a finer point on that, Unicode (which is only a specification constantly being improved upon) is harder to implement when it hasn't been on the design board from the ground up; Python in this case. Julia has Unicode support from the ground up, and it was easier for those guys to implement (in beta release) than for the Python crew when they undertook the Unicode work that had to be done for Python3.x (just an observation). Anytime there are legacy code issues, regression testing problems, and a host of domain issues that weren't thought through from the get-go there are going to be more problematic hurdles; not to mention bugs. Having said that, I still think Unicode is somewhat harder than you're admitting. marcus From harrismh777 at gmail.com Mon May 12 22:02:19 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 12 May 2014 21:02:19 -0500 Subject: a better way to operate svn with python(better than pysvn)? References: Message-ID: On 5/12/14 10:16 AM, xs.nepaul at gmail.com wrote: > {nothing} huh? From breamoreboy at yahoo.co.uk Mon May 12 22:33:02 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 13 May 2014 03:33:02 +0100 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 13/05/2014 02:18, Steven D'Aprano wrote: > On Mon, 12 May 2014 17:47:48 +0000, alister wrote: > >> On Mon, 12 May 2014 16:19:17 +0100, Mark Lawrence wrote: >> >>> This was *NOT* written by our resident unicode expert >>> http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/ >>> >>> Posted as I thought it would make a rather pleasant change from >>> interminable threads about names vs values vs variables vs objects. >> >> Surely those example programs are not the pythonoic way to do things or >> am i missing something? > > Feel free to show us your version of "cat" for Python then. Feel free to > target any version you like. Don't forget to test it against files with > names and content that: > > - aren't valid UTF-8; > > - are valid UTF-8, but not valid in the local encoding. > > > >> if those code samples are anything to go by this guy makes JMF look >> sensible. > > Armin Ronacher is an extremely experienced and knowledgeable Python > developer, and a Python core developer. He might be wrong, but he's not > *obviously* wrong. > > Unicode is hard, not because Unicode is hard, but because of legacy > problems. I can create a file on a machine that uses ISO-8859-7 for the > file name, put JShift-JIS encoded text inside it, transfer it to a > machine that uses Windows-1251 as the file system encoding, then SSH into > that machine from a system using Big5, and try to make sense of it. If > everybody used UTF-8 any time data touched a disk or network, we'd be > laughing. It would all be so simple. > > Reading Armin's post, I think that all that is needed to simplify his > Python 3 version is: > > - have a bytes version of sys.argv (bargv? argvb?) and read > the file names from that; > > - have a simple way to write bytes to stdout and stderr. > > Most programs won't need either of those, but file system utilities will. > I think http://bugs.python.org/issue8776 and http://bugs.python.org/issue8775 are relevant but both were placed in the small round filing cabinet. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rustompmody at gmail.com Mon May 12 23:00:49 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 12 May 2014 20:00:49 -0700 (PDT) Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> References: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> Message-ID: <9e710486-eed0-4ae1-a858-895c49881dd8@googlegroups.com> On Monday, May 12, 2014 11:05:53 PM UTC+5:30, scott... at gmail.com wrote: > On Friday, May 9, 2014 8:12:57 PM UTC-4, Steven D'Aprano wrote: > > fStr = fStr.replace(b'‒', b'-') > > Still doesn't work > > > > Best: > > > > > > # Untested > > > > fStr = re.sub(b'&#x(201[2-5])|(2E3[AB])|(00[2A]D)', b'-', fStr) > > Still doesn't work. > > Guess whatever the code is for endash and mdash are not the ones I am using.... What happens if you divide two string? >>> 'a' / 'b' Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for /: 'str' and 'str' Or multiply 2 lists? >>> [1,2]*[3,3] Traceback (most recent call last): File "", line 1, in TypeError: can't multiply sequence by non-int of type 'list' Trying to do a text operation like re.sub on a NON-text object like a doc-file is the same. Yes python may not be intelligent enough to give you such useful error messages outside its territory ie on contents of random files, however logically its the same -- an impossible operation. The options you have: 1. Use doc-specific tools eg MS/Libre office to work on doc files ie dont use python 2. Follow Tim Golden's suggestion, ie use win32com which is a doc-talking python API [BTW Thanks Tim for showing how easy it is] 3. Get out of the doc format to txt (export as plain txt) and then try what you are trying on the txt From harrismh777 at gmail.com Tue May 13 00:41:18 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 12 May 2014 23:41:18 -0500 Subject: Simple Function Decorator Sample Snippet Message-ID: hi folks, I've come up with a simple snippet that intends to explain the concept of decorations without an article (for on app help), while being succinct and concise, while not being overly complicated. Does this work? I have another one coming for args, similar, if this works... comments appreciated. thanks. > # BEGIN FUNCTION DECORATOR SIMPLE ################################ > # > # define the function decorator (wrapper function) > def enter_exit(f): > def new_f(): > print("entering", f.__name__) > f() > print(f.__name__, "exited !", end="\n\n") > return new_f > > # the above "function decoration" takes a 'callable' as an argument > # and returns a 'callable' new function that is used to > # replace the original function (function is decorated), which > # adds functionality to the original function being decorated ... > > # define the original function > def f1(): > print(" inside f1()") > > # replace the original function (above) with the new decorated > # 'wrapped' function using the function decoration 'enter_exit'... > f1 = enter_exit(f1) > > # (OR) accomplish the same thing with decoration lines as below: > > # functions wrapped with decoration lines syntax (annotations) > # as below, accomplish the same 'decoration' as above > # by using some 'syntactic sugar' to accomplish same ... > > @enter_exit > def f2(): > print(" inside f2()") > > @enter_exit > def f3(): > print(" inside f3()") > > # demo the new 'decorated' functions > f1() > f2() > f3() > > # END FUNCTION DECORATOR SIMPLE ################################## From rustompmody at gmail.com Tue May 13 01:10:00 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 12 May 2014 22:10:00 -0700 (PDT) Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> On Tuesday, May 13, 2014 6:48:35 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 12 May 2014 17:47:48 +0000, alister wrote: > > > Surely those example programs are not the pythonoic way to do things or > > am i missing something? > > > > Feel free to show us your version of "cat" for Python then. Feel free to > target any version you like. Don't forget to test it against files with > names and content that: > > > - aren't valid UTF-8; > > > - are valid UTF-8, but not valid in the local encoding. Thanks for a non-defensive appraisal! > > > > if those code samples are anything to go by this guy makes JMF look > > sensible. > > > > Armin Ronacher is an extremely experienced and knowledgeable Python > developer, and a Python core developer. He might be wrong, but he's not > *obviously* wrong. > > > > Unicode is hard, not because Unicode is hard, but because of legacy > problems. I can create a file on a machine that uses ISO-8859-7 for the > file name, put JShift-JIS encoded text inside it, transfer it to a > machine that uses Windows-1251 as the file system encoding, then SSH into > that machine from a system using Big5, and try to make sense of it. If > everybody used UTF-8 any time data touched a disk or network, we'd be > laughing. It would all be so simple. I think the most helpful way forward is to accept two things: a. Unicode is a headache b. No-unicode is a non-option > > > > Reading Armin's post, I think that all that is needed to simplify his > Python 3 version is: > > > > - have a bytes version of sys.argv (bargv? argvb?) and read > the file names from that; > > - have a simple way to write bytes to stdout and stderr. > > > Most programs won't need either of those, but file system utilities will. About the technical merits of Armin's post and your suggestions, Ive nothing to say, since I am an ignoramus on (the mechanics of) unicode [Consider me an eager, early, ignorant adopter :-) ] Its however good to note that unicode is rather unique in the history not just of IT/CS but of humanity, in the sense that no one (to the best of my knowledge) has ever tried to come up with an all-encompassing umbrella for all humanity's scripts/writing systems etc. So hiccups and mistakes are only to be expected. The absence of these would be much more surprising! From flebber.crue at gmail.com Tue May 13 01:28:34 2014 From: flebber.crue at gmail.com (flebber) Date: Mon, 12 May 2014 22:28:34 -0700 (PDT) Subject: SQLAlchemy - web framework ? In-Reply-To: References: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> Message-ID: Roy.that is interesting that you can use mongoengine. Recent google results such as seem to assert there are a lot of inherent risk in swapping out components, though I may be misinterpreting it. http://www.slideshare.net/daikeren/tradeoffs-of-replacing-core-components Sayth From harrismh777 at gmail.com Tue May 13 01:33:47 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 13 May 2014 00:33:47 -0500 Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> Message-ID: On 5/12/14 3:44 AM, Alain Ketterlin wrote: > multiple-dispatch (i.e., dynamically testing types, converting to a > common type, and selecting the version of sqrt to use). That's probably > more than the time it takes to actually perform the computation, a bit > like what happens with x+y on integers with Python, where only a > fraction of time is spent on adding integers. > > When you are doing scientific computation, this overhead is > unacceptable, because you'll have zillions of computations to perform. > I'm still trying to sort that out. I have not tested this yet, but it looks like Julia is fully dynamic (yes it has types too), and it does parallel processing at its core, so the zillions of computations are being handled all at once, depending on how many processors|cores you have. > Julia provides a way to make things fast: typing. If you provide > explicit types, the dynamic typing part obviously disappears, and > the overhead is removed. Julia is dynamic (depending on how far you want to go with that) but what makes it fast is the JIT. It is almost accomplishing C/C++ and FORTRAN speeds (even though dynamic) because it is compiling on-the-fly. > > But then, you're not too far from Fortran, or C/C++. > Right. Again, this is really about the design goals and the JIT. >> The following code will produce over 100,000 digits of ? (pi) in less >> than 2 seconds on a low-end processor, like my mac mini dual core >> 2Ghz: {snip} > > You seem to be discovering the power of the libraries that are behind > all this (MPFR in that case)... Yes, and more+ Gnu GMP & MPFR are not new to me, but the wrapper and repl are ! I am just realizing the power behind the libraries in this context, but I am very impressed with the functionality wrapped around the Gnu stuff... the interface is quite nice. > >> But, like lisp, Julia's internal structures are lists, so, it can >> create and modify its own code on-the-fly. [...] > > Sorry, I was comparing to Fortran, and it's use in scientific computing. > Self modifying code is totally irrelevant there. no, no, no... there has to be a value add for scientists to move away from R or Matlab, or from FORTRAN. Why go to the trouble? FORTRAN works well (its fast too), and there are zillions of lines of code cranking away on huge linear arrays. Enter Julia... over the next ten years; seriously. Because of the value adds! Why?, glad you asked. Enter self modifying code for one. The influence of Lisp|Scheme is potentially huge here. For scientific computing the reason for making the switch is that the array functions being calculated now in FORTRAN can be calculated (as fast) but more elegantly with Julia; because the language has the ease of use of Python, the stats of R, the array capabilities of MatLab (on steroids) and the almost speed of C/C++ (all together in one package). There is enough of a value add in this language to make FORTRAN users (also NumPy SciPy) take notice. Yes, its on a development curve right now (very much beta); but very much out there with some serious capability --- right now. It will take some time to mature, but I really think this language has the potential to be around for a long long time. There needs to be some serious bench marking on the parallel processing model, and there needs to be some uptake on the user base to find out what 'they' really need from it, but I think this dev group is on the ball. (maybe a little too smart for their own good, we'll see) I noticed from the MIT videos http://julialang.org/blog/2013/03/julia-tutorial-MIT/ from a year ago that the project has grown with leaps and bounds... but, there is very much an intellectual edge here vs. a usability edge... um, the computer scientists are still very much in control. It might be time for a larger user group to get involved with the development direction, and code base. I agree with D'Aprano that languages come and go. But I think Julia is different... like Python... for the scientific community; seriously. And, if they really are working together with certain Python group(s) to merge technologies, this could be big for years to come! I'm excited about it. Don't get me wrong anybody, I'm still a Pythonista! :) marcus From harrismh777 at gmail.com Tue May 13 01:39:06 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 13 May 2014 00:39:06 -0500 Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> Message-ID: On 5/13/14 12:10 AM, Rustom Mody wrote: > I think the most helpful way forward is to accept two things: > a. Unicode is a headache > b. No-unicode is a non-option QOTW (so far...) From steve at pearwood.info Tue May 13 01:48:43 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 13 May 2014 05:48:43 GMT Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> Message-ID: <5371b23a$0$11109$c3e8da3@news.astraweb.com> On Tue, 13 May 2014 00:33:47 -0500, Mark H Harris wrote: > there has to be a value add for scientists to move away from R or > Matlab, or from FORTRAN. Why go to the trouble? FORTRAN works well (its > fast too), and there are zillions of lines of code cranking away on huge > linear arrays. Enter Julia... over the next ten years; seriously. > Because of the value adds! > > Why?, glad you asked. Enter self modifying code for one. Self-modifying code is a nightmare inside the head of a Lovecraftian horror. There's a reason why almost the only people still using self- modifying code are virus writers, and the viruses they create are notorious for being buggy. -- Steven From gheskett at wdtv.com Tue May 13 01:45:05 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Tue, 13 May 2014 01:45:05 -0400 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> Message-ID: <201405130145.05995.gheskett@wdtv.com> On Tuesday 13 May 2014 01:39:06 Mark H Harris did opine And Gene did reply: > On 5/13/14 12:10 AM, Rustom Mody wrote: > > I think the most helpful way forward is to accept two things: > > a. Unicode is a headache > > b. No-unicode is a non-option > > QOTW (so far...) But its early yet, only Tuesday & its just barely started... :) Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From steve at pearwood.info Tue May 13 01:54:47 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 13 May 2014 05:54:47 GMT Subject: Simple Function Decorator Sample Snippet References: Message-ID: <5371b3a7$0$11109$c3e8da3@news.astraweb.com> On Mon, 12 May 2014 23:41:18 -0500, Mark H Harris wrote: > hi folks, I've come up with a simple snippet I don't think that this idea is original to you :-) I'm pretty sure many people have come up with the idea of a decorator that just announces when it runs and when it is called. I know I have :-) People keep independently inventing this because it's an obvious, and easy to understand, example. Nicely done. > that intends to explain the > concept of decorations without an article (for on app help), while being > succinct and concise, while not being overly complicated. > > Does this work? I have another one coming for args, similar, if this > works... comments appreciated. thanks. I tried to run your code, but every line is quoted with a > which causes a syntax error. Was there a reason you quoted the snippet? -- Steven From rosuav at gmail.com Tue May 13 01:56:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 15:56:50 +1000 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: <5371b23a$0$11109$c3e8da3@news.astraweb.com> References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <5371b23a$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Tue, May 13, 2014 at 3:48 PM, Steven D'Aprano wrote: > Self-modifying code is a nightmare inside the head of a Lovecraftian > horror. There's a reason why almost the only people still using self- > modifying code are virus writers, and the viruses they create are > notorious for being buggy. Hmm... what counts as self-modifying, though? When you decorate a function to modify its behaviour (eg add caching around it), all the modification happens at compile time, but it's still executing something other than what you see as the bald code. What about a microkernel that can load altered code from the disk, compile it into memory, and replace portions of itself? I've done that a number of times (not in Python as it has little support for it, but in Pike it's easy); is that self-modifying code? Or a JIT compiler. As you run something, it gets changed in form to be more streamlined. None of these is as horrible as the loop that fiddles with its own code on the fly, but any of them, if buggy, will have the same effect. And all are useful. ChrisA From harrismh777 at gmail.com Tue May 13 01:55:06 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 13 May 2014 00:55:06 -0500 Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <5371b23a$0$11109$c3e8da3@news.astraweb.com> Message-ID: <5371B3BA.1050600@gmail.com> On 5/13/14 12:48 AM, Steven D'Aprano wrote: > On Tue, 13 May 2014 00:33:47 -0500, Mark H Harris wrote: > >> there has to be a value add for scientists to move away from R or >> Matlab, or from FORTRAN. Why go to the trouble? FORTRAN works well (its >> fast too), and there are zillions of lines of code cranking away on huge >> linear arrays. Enter Julia... over the next ten years; seriously. >> Because of the value adds! >> >> Why?, glad you asked. Enter self modifying code for one. > > Self-modifying code is a nightmare inside the head of a Lovecraftian > horror. There's a reason why almost the only people still using self- > modifying code are virus writers, and the viruses they create are > notorious for being buggy. > > no, no, no... Steven don't think self-modifying (sorry I even used it) think meta-programming. Python accomplishes this kind of thing using Class and function decorations (sort-uv). Take a look at the video presentation of the concept before you turn it into a Friday the Thirteenth virus writing horror flick... its going to be as powerful as lisp was supposed to be with the user friendliness of python-like code-ability but 'without' the forced indentation rule (Julia uses 'ends' and white-space means nothing). marcus From ben at benfinney.id.au Tue May 13 02:03:43 2014 From: ben at benfinney.id.au (Ben Finney) Date: Tue, 13 May 2014 16:03:43 +1000 Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> Message-ID: <857g5q9pvk.fsf@benfinney.id.au> Gene Heskett writes: > On Tuesday 13 May 2014 01:39:06 Mark H Harris did opine > > QOTW (so far...) > > But its early yet, only Tuesday & its just barely started... :) Says who? For some of us, Tuesday is approaching sunset. (It's always a good day to remind people that the rest of the world exists.) -- \ ?Reality must take precedence over public relations, for nature | `\ cannot be fooled.? ?Richard P. Feynman, _Rogers' Commission | _o__) Report into the Challenger Crash_, 1986-06 | Ben Finney From harrismh777 at gmail.com Tue May 13 02:04:39 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 13 May 2014 01:04:39 -0500 Subject: Simple Function Decorator Sample Snippet References: <5371b3a7$0$11109$c3e8da3@news.astraweb.com> Message-ID: On 5/13/14 12:54 AM, Steven D'Aprano wrote: > I don't think that this idea is original to you :-) I'm pretty sure many > people have come up with the idea of a decorator that just announces when > it runs and when it is called. I know I have :-) oh, absolutely... every piece of that thing comes from somebody (about six somebodies to be exact) what makes it unique is that its compressed, in the right order (I think), and 'without' extraneous gibberish that confuses the whole dang thing. > > People keep independently inventing this because it's an obvious, and > easy to understand, example. Nicely done. Its obvious until you get to the @charater. In fact its taken so obviously by *everyone* that no one actually gets it explained without eight pages or twelve steps of something until its all confused. > I tried to run your code, but every line is quoted with a > which causes > a syntax error. Was there a reason you quoted the snippet? Yes, because depending on your interface the code can get mangled (the indentation thing breaks). the quoted paste seems to avoid this mostly with the downside that the quote characters need to be striped from the py file. by the way, any suggestions are welcome regarding that too... there doesn't really seem to be a good way to share code on the group consistently. marcus From rustompmody at gmail.com Tue May 13 02:09:04 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 12 May 2014 23:09:04 -0700 (PDT) Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> Message-ID: <72d4f4e7-1bbd-4ceb-8e7f-d8ca18e1c1b2@googlegroups.com> On Tuesday, May 13, 2014 11:09:06 AM UTC+5:30, Mark H. Harris wrote: > On 5/13/14 12:10 AM, Rustom Mody wrote: > > > I think the most helpful way forward is to accept two things: > > a. Unicode is a headache > > b. No-unicode is a non-option > > > QOTW (so far...) I said that getting unicode right straight off is unrealistic. I should have added this: Armin makes a (sarcastic?) dig about the fact that python (3) goofs because its mismatched with the assumptions of unix. | UNIX is bytes, has been defined that way and will always be that way. To | Unicode on UNIX is only madness if you force it on everything. But that's not | how Unicode on UNIX works. UNIX does not have a distinction between unicode | and byte APIs. They are one and the same which makes them easy to deal with.] | Python 3 takes a very difference stance on Unicode than UNIX does. Python 3 | says: everything is Unicode ... This may be right... Or it may be the other way round as I claim at http://blog.languager.org/2014/04/unicode-and-unix-assumption.html At this point I dont believe that anyone is very clear what is the right way and and wrong way From rosuav at gmail.com Tue May 13 02:18:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 16:18:40 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <857g5q9pvk.fsf@benfinney.id.au> References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> Message-ID: On Tue, May 13, 2014 at 4:03 PM, Ben Finney wrote: > (It's always a good day to remind people that the rest of the world > exists.) Ironic that this should come up in a discussion on Unicode, given that Unicode's fundamental purpose is to welcome that whole rest of the world instead of yelling "LALALALALA America is everything" and pretending that ASCII, or Latin-1, or something, is all you need. ChrisA Currently enjoying "Monday Night Flagging" on Threshold RPG... at 4pm on Tuesday. From wuwei23 at gmail.com Tue May 13 02:25:00 2014 From: wuwei23 at gmail.com (alex23) Date: Tue, 13 May 2014 16:25:00 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 13/05/2014 11:39 AM, Chris Angelico wrote: > On Tue, May 13, 2014 at 11:18 AM, Steven D'Aprano > wrote: >> - have a bytes version of sys.argv (bargv? argvb?) and read >> the file names from that; > > argb? :) I tried and failed to come up with an "argy bargy" joke here so decided to go for a meta-reference instead. From gheskett at wdtv.com Tue May 13 02:31:14 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Tue, 13 May 2014 02:31:14 -0400 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: <5371b23a$0$11109$c3e8da3@news.astraweb.com> References: <87tx91warf.fsf@elektro.pacujo.net> <5371b23a$0$11109$c3e8da3@news.astraweb.com> Message-ID: <201405130231.14585.gheskett@wdtv.com> On Tuesday 13 May 2014 01:48:43 Steven D'Aprano did opine And Gene did reply: > On Tue, 13 May 2014 00:33:47 -0500, Mark H Harris wrote: > > there has to be a value add for scientists to move away from R or > > Matlab, or from FORTRAN. Why go to the trouble? FORTRAN works well > > (its fast too), and there are zillions of lines of code cranking > > away on huge linear arrays. Enter Julia... over the next ten years; > > seriously. Because of the value adds! > > > > Why?, glad you asked. Enter self modifying code for one. > > Self-modifying code is a nightmare inside the head of a Lovecraftian > horror. There's a reason why almost the only people still using self- > modifying code are virus writers, and the viruses they create are > notorious for being buggy. People who write buggy self-modifying code aren't paying attention. And you don't want those people anywhere near your code in 107% of the cases. Stable, dead reliable self modifying code CAN be written, I have done it. And that code was still in use at the tv station that I wrote it for 15 years later. The only time it crashed was when there was a power failure, and the backup generator, which had to be started by hand, didn't get started soon enough to keep the battery backup, an old fried & dried 6 volt gel-cell from running down. An RCA 1802 device without an assembler even, just a hex monitor for code entry, and memory in those days (1980) was $400 for 4k of static ram when I built it. By using self modifying code, I was able to do about 10k worth of code, using about 2.5k of that 4k of ram. Its all in how you reset each location that is modified on your way back to the top of the program to await the next command. IMO, people who bad-mouth self-modifying code are folks who don't have the patience to do it right, because stable self-modifying code CAN most certainly be done. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From rosuav at gmail.com Tue May 13 02:32:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 16:32:08 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 13, 2014 at 4:25 PM, alex23 wrote: > On 13/05/2014 11:39 AM, Chris Angelico wrote: >> >> On Tue, May 13, 2014 at 11:18 AM, Steven D'Aprano >> wrote: >>> >>> - have a bytes version of sys.argv (bargv? argvb?) and read >>> the file names from that; >> >> >> argb? :) > > > I tried and failed to come up with an "argy bargy" joke here so decided to > go for a meta-reference instead. I'm just waiting for someone to have need for arguments in both network byte order and host byte order. The latter, of course, would be "argh". ChrisA From harrismh777 at gmail.com Tue May 13 02:32:23 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 13 May 2014 01:32:23 -0500 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> Message-ID: <5371BC77.4090106@gmail.com> On 5/13/14 1:18 AM, Chris Angelico wrote: > instead of yelling "LALALALALA America is everything" and > pretending that ASCII, or Latin-1, or something, is all you need. > ... it isn't? LALALALALALALALALA :)) From harrismh777 at gmail.com Tue May 13 02:32:23 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 13 May 2014 01:32:23 -0500 Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> Message-ID: <5371BC77.4090106@gmail.com> On 5/13/14 1:18 AM, Chris Angelico wrote: > instead of yelling "LALALALALA America is everything" and > pretending that ASCII, or Latin-1, or something, is all you need. > ... it isn't? LALALALALALALALALA :)) From hawkowl at atleastfornow.net Mon May 12 07:07:15 2014 From: hawkowl at atleastfornow.net (HawkOwl) Date: Mon, 12 May 2014 19:07:15 +0800 Subject: Twisted 14.0.0 Release Announcement Message-ID: <52611128-3708-40CE-86F5-C63FE9054A6B@atleastfornow.net> On behalf of Twisted Matrix Laboratories, I am honoured to announce the release of Twisted 14.0! It has been a long road to get here, but we?ve done it! The highlights of this release are: - Twisted Positioning (`twisted.positioning`) makes its entry into Twisted! It comes ready to talk with common GPS devices, and will supersede `twisted.protocols.gps`. - A wealth of SSL/TLS improvements, including ECDHE support, TLS Service Identity (with service_identity on PyPI), a stronger default set of ciphers, and strengthening against attacks such as CRIME. A Twisted Web server with pyOpenSSL 0.14 is capable of getting an A in Qualys SSL Labs tests out of the box, and A+ with small application modifications. Twisted Agent can also now do HTTPS hostname verification. - Python 3 improvements, including the ability for `pip install` to install all ported modules. - Twisted Pair?s TUN/TAP support has been overhauled, with documentation and full test coverage. - Significant documentation improvements, including more API documentation for Twisted Mail & Twisted Names, narrative documentation for Twisted Names, and a migration to Sphinx for building Twisted narrative docs. - Support is dropped for pyOpenSSL older than 0.10 and Windows XP. You can find the downloads at (or alternatively ) . Many thanks to everyone who had a part in this release - we?ve got some big things landed, and if it weren?t for the support of developers (both core and occasional), the Twisted Software Foundation, or people giving feedback and filing bugs, we?d have never got it done. Twisted Regards, HawkOwl -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 455 bytes Desc: Message signed with OpenPGP using GPGMail URL: From davea at davea.name Mon May 12 17:15:45 2014 From: davea at davea.name (Dave Angel) Date: Mon, 12 May 2014 17:15:45 -0400 Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> References: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> Message-ID: <53713A01.1000503@davea.name> On 05/12/2014 01:35 PM, scottcabit at gmail.com wrote: > On Friday, May 9, 2014 8:12:57 PM UTC-4, Steven D'Aprano wrote: > >> Good: >> >> >> >> # Untested >> >> fStr = re.sub(b'&#x(201[2-5])|(2E3[AB])|(00[2A]D)', b'-', fStr) > > Still doesn't work. > > Guess whatever the code is for endash and mdash are not the ones I am using.... > More likely, your MSWord document isn't a simple text file. Some encodings don't resemble ASCII or Unicode in the least. -- DaveA From ganesh1pal at gmail.com Tue May 13 03:07:24 2014 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Tue, 13 May 2014 12:37:24 +0530 Subject: PEP 8 : Maximum line Length : Message-ID: Hi Team , what would be the best way to intent the below line . I have few lines in my program exceeding the allowed maximum line Length of 79./80 characters Example 1 : p = Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) Iam running pylint and it says the above line is tool long how do I limit it to 79 character without violating any rules ************* Module isi_corrupt C: 14,0: Line too long (88/80) W: 19,0: Bad indentation. Found 6 spaces, expected 8 Regards, Ganesh -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Tue May 13 03:22:28 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 13 May 2014 07:22:28 GMT Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <5371b23a$0$11109$c3e8da3@news.astraweb.com> Message-ID: <5371c834$0$11109$c3e8da3@news.astraweb.com> On Tue, 13 May 2014 02:31:14 -0400, Gene Heskett wrote: > People who write buggy self-modifying code aren't paying attention. [...] > IMO, people who bad-mouth self-modifying code are folks who don't have > the patience to do it right, because stable self-modifying code CAN most > certainly be done. Many things *can* be done. The question is, is it worth the effort to do it? The simplest code that meets the functional requirements is usually the best. > Stable, dead reliable self modifying code CAN be written, I have done > it. And that code was still in use at the tv station that I wrote it > for 15 years later. Yep, and people have written stable, dead reliable unstructured code using GOTO and possibly even COMEFROM too. Nevertheless, nobody serious uses unstructured code these days. It takes much more effort to get it stable and reliable in the first place. Maintenance is ten or a hundred times harder and therefore more expensive. Chances are good that the software you wrote 15 years ago is now a black box: it damn well better work, because no-one knows how it works well enough to debug problems or add new functionality. And after 15 years, I daresay that includes you. -- Steven From gregor at ediwo.com Tue May 13 03:27:22 2014 From: gregor at ediwo.com (gregor) Date: Tue, 13 May 2014 09:27:22 +0200 Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140513092722.444c5a77@florenz> Am 13 May 2014 01:18:35 GMT schrieb Steven D'Aprano : > > - have a simple way to write bytes to stdout and stderr. there is the underlying binary buffer: https://docs.python.org/3/library/sys.html#sys.stdin greg From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sat May 10 11:16:50 2014 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sat, 10 May 2014 15:16:50 +0000 (UTC) Subject: ANN: verynice 0.3 - a nice(1) like utility for throttling processes Message-ID: verynice is a nice(1)-like command line utility for unix systems to throttle long running processes beyond what can be achieved by nice(1), by repeatedly suspending and resuming the process. Author: Radovan Garab?k URL: http://kassiopeia.juls.savba.sk/~garabik/software/verynice/ License: GPL (v3) -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From dfnsonfsduifb at gmx.de Tue May 13 04:08:45 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Tue, 13 May 2014 10:08:45 +0200 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 13.05.2014 03:18, Steven D'Aprano wrote: > Armin Ronacher is an extremely experienced and knowledgeable Python > developer, and a Python core developer. He might be wrong, but he's not > *obviously* wrong. He's correct about file name encodings. Which can be fixed really easily wihtout messing everything up (sys.argv binary variant, open accepting binary filenames). But that he suggests that Go would be superior: > Which uses an even simpler model than Python 2: everything is a byte string. The assumed encoding is UTF-8. End of the story. Is just a horrible idea. An obviously horrible idea, too. Having dealt with the UTF-8 problems on Python2 I can safely say that I never, never ever want to go back to that freaky hell. If I deal with strings, I want to be able to sanely manipulate them and I want to be sure that after manipulation they're still valid strings. Manipulating the bytes representation of unicode data just doesn't work. And I'm very very glad that some people felt the same way and implemented a sane, consistent way of dealing with Unicode in Python3. It's one of the reasons why I switched to Py3 very early and I love it. Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From marko at pacujo.net Tue May 13 04:25:22 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 13 May 2014 11:25:22 +0300 Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87tx8uccgd.fsf@elektro.pacujo.net> Johannes Bauer : > Having dealt with the UTF-8 problems on Python2 I can safely say that > I never, never ever want to go back to that freaky hell. If I deal > with strings, I want to be able to sanely manipulate them and I want > to be sure that after manipulation they're still valid strings. > Manipulating the bytes representation of unicode data just doesn't > work. Based on my background (network and system programming), I'm a bit suspicious of strings, that is, text. For example, is the stuff that goes to syslog bytes or text? Does an XML file contain bytes or (encoded) text? The answers are not obvious to me. Modern computing is full of ASCII-esque binary communication standards and formats. Python 2's ambiguity allows me not to answer the tough philosophical questions. I'm not saying it's necessarily a good thing, but it has its benefits. Marko From rosuav at gmail.com Tue May 13 04:38:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 18:38:03 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <87tx8uccgd.fsf@elektro.pacujo.net> References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <87tx8uccgd.fsf@elektro.pacujo.net> Message-ID: On Tue, May 13, 2014 at 6:25 PM, Marko Rauhamaa wrote: > Johannes Bauer : > >> Having dealt with the UTF-8 problems on Python2 I can safely say that >> I never, never ever want to go back to that freaky hell. If I deal >> with strings, I want to be able to sanely manipulate them and I want >> to be sure that after manipulation they're still valid strings. >> Manipulating the bytes representation of unicode data just doesn't >> work. > > Based on my background (network and system programming), I'm a bit > suspicious of strings, that is, text. For example, is the stuff that > goes to syslog bytes or text? Does an XML file contain bytes or > (encoded) text? The answers are not obvious to me. Modern computing is > full of ASCII-esque binary communication standards and formats. These are problems that Unicode can't solve. In theory, XML should contain text in a known encoding (defaulting to UTF-8). With syslog, it's problematic - I don't remember what it's meant to be, but I know there are issues. Same with other log files. > Python 2's ambiguity allows me not to answer the tough philosophical > questions. I'm not saying it's necessarily a good thing, but it has its > benefits. It's not a good thing. It means that you have the convenience of pretending there's no problem, which means you don't notice trouble until something happens... and then, in all probability, your app is in production and you have no idea why stuff went wrong. ChrisA From __peter__ at web.de Tue May 13 04:45:49 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 13 May 2014 10:45:49 +0200 Subject: PEP 8 : Maximum line Length : References: Message-ID: Ganesh Pal wrote: > Hi Team , > > > what would be the best way to intent the below line . > > I have few lines in my program exceeding the allowed maximum line Length > of 79./80 characters > > Example 1 : > > p = > Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) > > > Iam running pylint and it says the above line is tool long how do I limit > it to 79 character without violating any rules > > ************* Module isi_corrupt > C: 14,0: Line too long (88/80) > W: 19,0: Bad indentation. Found 6 spaces, expected 8 (1) Newlines are allowed inside an open (, [, or {. So: p = subprocess.Popen( shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) Other techniques: (2) Introduce helper variables: cmd = shlex.split(cmd) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (3) Import names: from subprocess import PIPE p = subprocess.Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE) (4) Use aliases: import subprocess as sp p = sp.Popen(shlex.split(cmd), stdout=sp.PIPE, stderr=sp.PIPE) From marko at pacujo.net Tue May 13 05:06:50 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 13 May 2014 12:06:50 +0300 Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <87tx8uccgd.fsf@elektro.pacujo.net> Message-ID: <87ppjicaj9.fsf@elektro.pacujo.net> Chris Angelico : > These are problems that Unicode can't solve. I actually think the problem has little to do with Unicode. Text is an abstract data type just like any class. If I have an object (say, a subprocess or a dictionary) in memory, I don't expect the object to have any existence independently of the Python virtual machine. I have the same feeling about Py3 strings: they only exist inside the Python virtual machine. An abstract object like a subprocess or dictionary justifies its existence through its behaviour (its quacking). Now, do strings quack or are they silent? I guess if you are writing a word processor they might quack to you. Otherwise, they are just an esoteric storage format. What I'm saying is that strings definitely have an important application in the human interface. However, I feel strings might be overused in the Py3 API. Case in point: are pathnames bytes objects or strings? The linux position is that they are bytes objects. Py3 supports both interpretations seemingly throughout: open(b"/bin/ls") vs open("/bin/ls") os.path.join(b"a", b"b") vs os.path.join("a", "b") Marko From ji.xia at nxp.com Tue May 13 04:45:14 2014 From: ji.xia at nxp.com (Ji Xia) Date: Tue, 13 May 2014 08:45:14 +0000 Subject: ctypes does not load .dll and generate windowsError 127 Message-ID: <46e1b559ed224fbfbc1c786739ce68c8@DBXPR04MB319.eurprd04.prod.outlook.com> Hi all, Could anybody help me out? I am trying to use python ctypes and load a .dll file. It works on my colleagues' machine, just does not work on mine Python on my machine is : python 2.7.6 OS: windows 7 Result is always: File "C:\Python27\Lib\ctypes\__init__.py", line 365, in __init__ self._handle = _dlopen(self._name, mode) WindowsError: [Error 127] The specified procedure could not be found Does anybody could help me out? Thanks Ji -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 13 05:29:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 19:29:33 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <87ppjicaj9.fsf@elektro.pacujo.net> References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <87tx8uccgd.fsf@elektro.pacujo.net> <87ppjicaj9.fsf@elektro.pacujo.net> Message-ID: On Tue, May 13, 2014 at 7:06 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> These are problems that Unicode can't solve. > > I actually think the problem has little to do with Unicode. Text is an > abstract data type just like any class. If I have an object (say, a > subprocess or a dictionary) in memory, I don't expect the object to have > any existence independently of the Python virtual machine. I have the > same feeling about Py3 strings: they only exist inside the Python > virtual machine. That's true; the only difference is that text is extremely prevalent. You can share a dict with another program, or store it in a file, or whatever, simply by agreeing on an encoding - for instance, JSON. As long as you and the other program know that this file is JSON encoded, you can write it and he can read it, and you'll get the right data at the far end. It's no different; there are encodings that are easy to handle and have limitations, and there are encodings that are elaborate and have lots of features (XML comes to mind, although technically you can't encode a dict in XML). > Case in point: are pathnames bytes objects or strings? The > linux position is that they are bytes objects. Py3 supports both > interpretations seemingly throughout: > > open(b"/bin/ls") vs open("/bin/ls") > os.path.join(b"a", b"b") vs os.path.join("a", "b") That's a problem that comes from the underlying file systems. If every FS in the world worked with Unicode file names, it would be easy. (Most would encode them onto the platters in UTF-8 or maybe UTF-16; some might choose to use a PEP 393 or Pike string structure, with the size_shift being a file mode just like the 'directory' bit; others might use a limited encoding for legacy reasons, storing uppercased CP437 on the disk, and returning an error if the desired name didn't fit.) But since they don't, we have to cope with that. What happens if you're running on Linux, and you have a mounted drive from an OS/2 share, and inside that, you access an aliased drive that represents a Windows share, on which you've mounted a remote-backup share? A single path name could have components parsed by each of those systems, so what's its encoding? How do you handle that? There's no solution. (Well, okay. There is a solution: don't do something so stupidly convoluted. But there's no law against cackling admins making circular mounts. In fact, I just mounted my own home directory as a subdirectory under my home directory, via sshfs. I can now encrypt my own file reads and writes exactly as many times as I choose to. I also cackled.) ChrisA From steve at pearwood.info Tue May 13 05:34:48 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 13 May 2014 09:34:48 GMT Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <5371b23a$0$11109$c3e8da3@news.astraweb.com> Message-ID: <5371e737$0$11109$c3e8da3@news.astraweb.com> On Tue, 13 May 2014 15:56:50 +1000, Chris Angelico wrote: > On Tue, May 13, 2014 at 3:48 PM, Steven D'Aprano > wrote: >> Self-modifying code is a nightmare inside the head of a Lovecraftian >> horror. There's a reason why almost the only people still using self- >> modifying code are virus writers, and the viruses they create are >> notorious for being buggy. > > Hmm... what counts as self-modifying, though? Code that modifies itself, as opposed to code that modifies other code. > When you decorate a > function to modify its behaviour (eg add caching around it), all the > modification happens at compile time, Not in Python it doesn't. Functions are created at runtime -- def is a statement, and it runs at runtime. But that's actually irrelevant. > but it's still executing something > other than what you see as the bald code. I don't think so. Whether I write: @cache def function(args): ... or even the old pre-decorator style: def function(args): ... function = cache(function) there's no *self-modification* going on. The trickiest thing about this is that the code for function is now split over two places, cache and function itself. But that's not much trickier than: def cache(x): ... def function(x): cache(x) ... or similar. You can write obfuscated code with decorators, but you can shoot yourself in the foot with just about any tool. Fundamentally, decorators are more or less just a way of doing function composition. > What about a microkernel that > can load altered code from the disk, compile it into memory, and replace > portions of itself? Now we're talking self-modification. But of course there are degrees of self-modification. This isn't too bad, because it's relatively simple to follow what happens next: def foo(x): global foo # Change me. foo = new_foo return bar(x) This is to self-modifying code what break and continue are to GOTO -- tamed, trained, on a leash, and pretty safe. > I've done that a number of times (not in Python as > it has little support for it, but in Pike it's easy); is that > self-modifying code? Yes. > Or a JIT compiler. As you run something, it gets > changed in form to be more streamlined. I wouldn't call that self-modifying code, because the compiler isn't modifying itself. It's modifying the code being run. But note that JIT compilers are optimizing compilers (there's little point, otherwise), and highly optimized code is notorious for being hard to debug and containing subtle, hard to find, harder to fix, bugs. Why are they hard to debug? Because the code that you read is not necessarily the same as the code being run. > None of these is as horrible as > the loop that fiddles with its own code on the fly, but any of them, if > buggy, will have the same effect. And all are useful. Many things are potentially useful, nevertheless we mostly avoid them because the cost is greater than the benefit. -- Steven From rosuav at gmail.com Tue May 13 05:35:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 19:35:00 +1000 Subject: ctypes does not load .dll and generate windowsError 127 In-Reply-To: <46e1b559ed224fbfbc1c786739ce68c8@DBXPR04MB319.eurprd04.prod.outlook.com> References: <46e1b559ed224fbfbc1c786739ce68c8@DBXPR04MB319.eurprd04.prod.outlook.com> Message-ID: On Tue, May 13, 2014 at 6:45 PM, Ji Xia wrote: > Could anybody help me out? I am trying to use python ctypes and load a .dll > file. It works on my colleagues? machine, just does not work on mine > > Python on my machine is : python 2.7.6 > > OS: windows 7 > > Result is always: > > File "C:\Python27\Lib\ctypes\__init__.py", line 365, in __init__ > > self._handle = _dlopen(self._name, mode) > > WindowsError: [Error 127] The specified procedure could not be found > > It would help to know what DLL you're loading. Are you copying the exact same DLL file from one computer to the other, or referencing something that's already there? It may be that the DLL you name is statically linked to another DLL, and it's the second one that's causing problems. In that case, even copying the file across won't solve the problem. Look for a DLL dependency tree program (you can find them at the other end of a web search) and see if you have versioning issues. This isn't actually a Python problem, it's all to do with the loading of that DLL. ChrisA From dfnsonfsduifb at gmx.de Tue May 13 05:38:40 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Tue, 13 May 2014 11:38:40 +0200 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <87tx8uccgd.fsf@elektro.pacujo.net> Message-ID: On 13.05.2014 10:38, Chris Angelico wrote: >> Python 2's ambiguity allows me not to answer the tough philosophical >> questions. I'm not saying it's necessarily a good thing, but it has its >> benefits. > > It's not a good thing. It means that you have the convenience of > pretending there's no problem, which means you don't notice trouble > until something happens... and then, in all probability, your app is > in production and you have no idea why stuff went wrong. Exactly. With Py2 "strings" you never know what encoding they are, if they already have been converted or something like that. And it's very well possible to mix already converted strings with other, not yet encoded strings. What a mess! All these issues are avoided by Py3. There is a very clear distinction between strings and string representation (data bytes), which is beautiful. Accidental mixing is not possible. And you have some thing *guaranteed* for the string type which aren't guaranteed for the bytes type (for example when doing string manipulation). Regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From alister.nospam.ware at ntlworld.com Tue May 13 05:44:15 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 13 May 2014 09:44:15 GMT Subject: PEP 8 : Maximum line Length : Message-ID: On Tue, 13 May 2014 10:45:49 +0200, Peter Otten wrote: > Ganesh Pal wrote: > >> Hi Team , >> >> >> what would be the best way to intent the below line . >> >> I have few lines in my program exceeding the allowed maximum line >> Length of 79./80 characters >> >> Example 1 : >> >> p = >> > Subprocess.Popen(shlex.split (cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) >> >> >> Iam running pylint and it says the above line is tool long how do I >> limit it to 79 character without violating any rules >> >> ************* Module isi_corrupt C: 14,0: Line too long (88/80) >> W: 19,0: Bad indentation. Found 6 spaces, expected 8 > > (1) Newlines are allowed inside an open (, [, or {. So: > > p = subprocess.Popen( > shlex.split(cmd), stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > > Other techniques: > > (2) Introduce helper variables: > > cmd = shlex.split(cmd) > p = subprocess.Popen(cmd, stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > > (3) Import names: > > from subprocess import PIPE p = subprocess.Popen(shlex.split(cmd), > stdout=PIPE, stderr=PIPE) > > (4) Use aliases: > > import subprocess as sp p = sp.Popen(shlex.split(cmd), stdout=sp.PIPE, > stderr=sp.PIPE) or simply leave it alone Pep 8 is a guide not a "Set in Stone" rule & even pep 8 does say that the 80 character limit can be exceeded if breaking the line would make the code less readable -- Catastrophic failure of the IDE cable???. What are you doing to the poor thing, jumping on it? - Beau Kuiper on linux-kernel From steve at pearwood.info Tue May 13 05:44:28 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 13 May 2014 09:44:28 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <87tx8uccgd.fsf@elektro.pacujo.net> <87ppjicaj9.fsf@elektro.pacujo.net> Message-ID: <5371e97b$0$11109$c3e8da3@news.astraweb.com> On Tue, 13 May 2014 12:06:50 +0300, Marko Rauhamaa wrote: > Chris Angelico : > >> These are problems that Unicode can't solve. > > I actually think the problem has little to do with Unicode. Text is an > abstract data type just like any class. If I have an object (say, a > subprocess or a dictionary) in memory, I don't expect the object to have > any existence independently of the Python virtual machine. I have the > same feeling about Py3 strings: they only exist inside the Python > virtual machine. And you would be correct. When you write them to a device (say, push them over a network, or write them to a file) they need to be serialized. If you're lucky, you have an API that takes a string and serializes it for you, and then all you have to deal with is: - am I happy with the default encoding? - if not, what encoding do I want? Otherwise you ought to have an API that requires bytes, not strings, and you have to perform your own serialization by encoding it. But abstractions leak, and this abstraction leaks because *right now* there isn't a single serialization for text strings. There are HUNDREDS, and sometimes you don't know which one is being used. [...] > What I'm saying is that strings definitely have an important application > in the human interface. However, I feel strings might be overused in the > Py3 API. Case in point: are pathnames bytes objects or strings? Yes. On POSIX systems, file names are sequences of bytes, with a very few restrictions. On recent Windows file systems (NTFS I believe?), file names are Unicode strings encoded to UTF-16, but with a whole lot of other restrictions imposed by the OS. > The > linux position is that they are bytes objects. Py3 supports both > interpretations seemingly throughout: > > open(b"/bin/ls") vs open("/bin/ls") os.path.join(b"a", b"b") > vs os.path.join("a", "b") Because it has to, otherwise there will be files that are unreachable on one platform or another. -- Steven From dfnsonfsduifb at gmx.de Tue May 13 05:46:17 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Tue, 13 May 2014 11:46:17 +0200 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <87tx8uccgd.fsf@elektro.pacujo.net> References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <87tx8uccgd.fsf@elektro.pacujo.net> Message-ID: On 13.05.2014 10:25, Marko Rauhamaa wrote: > Based on my background (network and system programming), I'm a bit > suspicious of strings, that is, text. For example, is the stuff that > goes to syslog bytes or text? Does an XML file contain bytes or > (encoded) text? The answers are not obvious to me. Modern computing is > full of ASCII-esque binary communication standards and formats. Traditional Unix programs (syslog for example) are notorious for being clear, ambiguous and/or ignorant of character encodings altogether. And this works, unfortunately, for the most time because many encodings share a common subset. If they wouldn't, the problems would be VERY apparent and people would be forced to handle the issues not so sloppily. Which is the route that Py3 chose. Don't be sloppy, make a great distinction between "text" (which handles naturally as strings) and its respective encoding. The only people who are angered by this now is people who always treated encodings sloppily and it "just worked". Well, there's a good chance it has worked by pure chance so far. It's a good thing that Python does this now more strictly as it gives developers *guarantees* about what they can and cannot do with text datatypes without having to deal with encoding issues in many places. Just one place: The interface where text is read or written, just as it should be. Regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From albert at spenarnc.xs4all.nl Tue May 13 05:56:00 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 13 May 2014 09:56:00 GMT Subject: How can this assert() ever trigger? References: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <5371ec30$0$27133$e4fe514c@dreader35.news.xs4all.nl> In article , Joseph Martinot-Lagarde wrote: >Le 10/05/2014 17:24, Albert van der Horst a ?crit : >> I have the following code for calculating the determinant of >> a matrix. It works inasfar that it gives the same result as an >> octave program on a same matrix. >> >> / ---------------------------------------------------------------- >> >> def determinant( mat ): .. >> result = lastr[jx] >> assert(result<>0.) ... >> assert(result<>0.) >> nom *= result # Compenstate for multiplying a row. ... >> assert(nom<>0.) .. >> >> /----------------------------------------- >> >> Now on some matrices the assert triggers, meaning that nom is zero. >> How can that ever happen? mon start out as 1. and gets multiplied >> with a number that is asserted to be not zero. >> >> Any hints appreciated. >> >> Groetjes Albert >> >I know it's not the question, but if you want a replacement for octave >did you try numpy (and scipy) ? The determinant would be computer faster >and with less memory than with your function. I'm using several programming languages in a mix to solve Euler problems. This is about learning how octave compares to python for a certain kind of problem as anything. The determinant program I had lying around, but it was infinite precision with integer only arithmetic. Then I made a simple modification and got mad because I didn't understand why it didn't work. I have used numpy and its det before, but I find it difficult to remember how to create a matrix in numpy. This is the kind of thing that is hard to find in the docs. Now I looked it up in my old programs: you start a matrix with the zeroes() function. I expect the built in determinant of octave to be on a par with corresponding python libraries. > >--- Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From marko at pacujo.net Tue May 13 05:59:28 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 13 May 2014 12:59:28 +0300 Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <87tx8uccgd.fsf@elektro.pacujo.net> Message-ID: <87iopac83j.fsf@elektro.pacujo.net> Johannes Bauer : > The only people who are angered by this now is people who always > treated encodings sloppily and it "just worked". Well, there's a good > chance it has worked by pure chance so far. It's a good thing that > Python does this now more strictly as it gives developers *guarantees* > about what they can and cannot do with text datatypes without having > to deal with encoding issues in many places. Just one place: The > interface where text is read or written, just as it should be. I'm not angered by text. I'm just wondering if it has any practical use that is not misuse... For example, Py3 should not make any pretense that there is a "default" encoding for strings. Locale's are an abhorrent invention from the early 8-bit days. IOW, you should never input or output text without explicit serialization. I get the feeling that Py3 would like to present a world where strings are first-class I/O objects that can exist in files, in filenames, inside pipes. You say, "text is read or written." I'm saying text is never read or written. It only exists as an abstraction (not even unicode) inside the virtual machine. Marko From rosuav at gmail.com Tue May 13 06:00:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 20:00:36 +1000 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: <5371e737$0$11109$c3e8da3@news.astraweb.com> References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <5371b23a$0$11109$c3e8da3@news.astraweb.com> <5371e737$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Tue, May 13, 2014 at 7:34 PM, Steven D'Aprano wrote: > On Tue, 13 May 2014 15:56:50 +1000, Chris Angelico wrote: > >> On Tue, May 13, 2014 at 3:48 PM, Steven D'Aprano >> wrote: >>> Self-modifying code is a nightmare inside the head of a Lovecraftian >>> horror. There's a reason why almost the only people still using self- >>> modifying code are virus writers, and the viruses they create are >>> notorious for being buggy. >> >> Hmm... what counts as self-modifying, though? > > Code that modifies itself, as opposed to code that modifies other code. Duh :) >> When you decorate a >> function to modify its behaviour (eg add caching around it), all the >> modification happens at compile time, > > Not in Python it doesn't. Functions are created at runtime -- def is a > statement, and it runs at runtime. But that's actually irrelevant. Yes, but that's still the "initialization phase" of the code. When I think of self-modifying code, I think of something that could do this: def some_func(x): if x<0: change_bottom_of_function x = -x result = calculate_stuff(x) return result # becomes "return -result" if change done Effectively, instead of using a stack or heap entry to record state, it uses its own code. (And the above example is buggy, too. That's part of why this is a bad idea - it's not obvious when there are bugs.) With a decorated function, the change happens at the time the def is executed. With the above example, the change happens when the function is called. That's what I meant by "compile time", although I did pick a poor term for it. Is there a better word for that? There's three phases, if you like - compilation, execution of def, and execution of function. >> but it's still executing something >> other than what you see as the bald code. > > I don't think so. ... there's no *self-modification* going on. > You can write obfuscated code with decorators, but you can > shoot yourself in the foot with just about any tool. Fundamentally, > decorators are more or less just a way of doing function composition. Right. I would agree here. It's confusing if it completely changes itself, but it's not really self-modifying. >> What about a microkernel that >> can load altered code from the disk, compile it into memory, and replace >> portions of itself? > > Now we're talking self-modification. Technically not - that's why I said microkernel. The kernel never changes *itself*, it just loads other code into memory (and can switch out submodules). It's not so clear-cut. The program, as a whole, is changing its own behaviour, but by separating "this bit can change" from "this bit manages the changes", you tame the self-modification - just as you say further down. > But of course there are degrees of > self-modification. This isn't too bad, because it's relatively simple to > follow what happens next: > > def foo(x): > global foo # Change me. > foo = new_foo > return bar(x) > > This is to self-modifying code what break and continue are to GOTO -- > tamed, trained, on a leash, and pretty safe. Yeah. It's safe because it's atomic and clean. >> Or a JIT compiler. As you run something, it gets >> changed in form to be more streamlined. > > I wouldn't call that self-modifying code, because the compiler isn't > modifying itself. It's modifying the code being run. Again, technically. But if the compiler is deemed to be part of the program (it often won't be - V8 with your JavaScript code and PyPy with your Python code are separate - but it would be possible to consider them to be the same effective unit), then it's exactly the same as the microkernel example above: tamed self-modification, with one piece modifying the other(s). > But note that JIT compilers are optimizing compilers (there's little > point, otherwise), and highly optimized code is notorious for being hard > to debug and containing subtle, hard to find, harder to fix, bugs. Why > are they hard to debug? Because the code that you read is not necessarily > the same as the code being run. Right, and that's exactly where the risk is. Every translation between you and what's run is a potential source of horribly insidious bugs. That's why it's absolutely essential to put bounds on the insatiable ambition for automutability. In the microkernel case, and also with a similar (but horribly less efficient) structure that I did a couple of times with DLLs, there's a clear protocol with "this file provides these public symbols", and that protocol doesn't much change with reloads. With a JIT compiler, the code should have the exact same effect before and after the change, and just be faster. And so on. By clearly delineating what can change and what can't, you divide any debugging job down to smaller pieces. Actually, even the file system can do some of this to you. I was checking lsof on one of my Linux systems a little while ago, and found that I had half a dozen old versions of a program, all with the same file name, all deleted. (When you unlink a running binary on Linux, the program keeps running the old version, and then you can put a new version in its place, with the same file name. Any new invocation will pick up the new binary; existing ones keep what they have.) So a program can unlink itself, write out a new version of itself, and happily keep going - letting new invocations take the changed version, safely. Again, not exactly self-modifying code... or is it? Again, tamed by boundaries. ChrisA From rustompmody at gmail.com Tue May 13 06:44:41 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 13 May 2014 03:44:41 -0700 (PDT) Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <5371b23a$0$11109$c3e8da3@news.astraweb.com> <5371e737$0$11109$c3e8da3@news.astraweb.com> Message-ID: <1bd9fc22-8d4b-4a9d-872f-d76591cfb205@googlegroups.com> On Tuesday, May 13, 2014 3:30:36 PM UTC+5:30, Chris Angelico wrote: > Actually, even the file system can do some of this to you. I was > checking lsof on one of my Linux systems a little while ago, and found > that I had half a dozen old versions of a program, all with the same > file name, all deleted. (When you unlink a running binary on Linux, > the program keeps running the old version, and then you can put a new > version in its place, with the same file name. Any new invocation will > pick up the new binary; existing ones keep what they have.) So a > program can unlink itself, write out a new version of itself, and > happily keep going - letting new invocations take the changed version, > safely. Again, not exactly self-modifying code... or is it? Again, > tamed by boundaries. Your lsof example looks like a rather typical case of ugly self-modifying code Self-modifying code has many flavours; consider: $ sudo apt-get upgrade apt-get relatively harmless but self-modifying nonetheless When its more invisible its more dangerous # apt-get upgrade linux-image My understanding of Mark Harris' original reference to 'self-modifying' is a more standard, ubiquitous, ugly but indispensable example -- the use of the interactive interpreter. I write a function: def foo()... ... recursive use of foo() I then rename the foo to FOO but forget to rename the internal call For normal file/module loading one would get a straightforward error message At the interactive interpreter one gets massive confusion. Does it mean we stop playing around in the interactive environment? Hopefully not! But there are pitfalls and its good to be straight about them. As far as I can see, recursivity is the foundation of our field; self-modifying code, self-reference (y-combinator) are just some of its many faces: http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html From rosuav at gmail.com Tue May 13 06:50:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 20:50:04 +1000 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: <1bd9fc22-8d4b-4a9d-872f-d76591cfb205@googlegroups.com> References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <5371b23a$0$11109$c3e8da3@news.astraweb.com> <5371e737$0$11109$c3e8da3@news.astraweb.com> <1bd9fc22-8d4b-4a9d-872f-d76591cfb205@googlegroups.com> Message-ID: On Tue, May 13, 2014 at 8:44 PM, Rustom Mody wrote: > On Tuesday, May 13, 2014 3:30:36 PM UTC+5:30, Chris Angelico wrote: >> Actually, even the file system can do some of this to you. I was >> checking lsof on one of my Linux systems a little while ago, and found >> that I had half a dozen old versions of a program, all with the same >> file name, all deleted. (When you unlink a running binary on Linux, >> the program keeps running the old version, and then you can put a new >> version in its place, with the same file name. Any new invocation will >> pick up the new binary; existing ones keep what they have.) So a >> program can unlink itself, write out a new version of itself, and >> happily keep going - letting new invocations take the changed version, >> safely. Again, not exactly self-modifying code... or is it? Again, >> tamed by boundaries. > > Your lsof example looks like a rather typical case of ugly self-modifying code > Self-modifying code has many flavours; consider: > > $ sudo apt-get upgrade apt-get > > relatively harmless but self-modifying nonetheless > Heh. Those are going to be exactly the same. (In actual fact, it was a "sudo make install" that created the situation I described.) The only difference is that you probably don't have any other instances of apt-get running, meaning the change takes place for the next run - but while that's running, you would see the old /usr/bin/apt-get as a deleted and open file. ChrisA From alister.nospam.ware at ntlworld.com Tue May 13 07:09:36 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 13 May 2014 11:09:36 GMT Subject: Simple Function Decorator Sample Snippet References: <5371b3a7$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Tue, 13 May 2014 01:04:39 -0500, Mark H Harris wrote: > Yes, because depending on your interface the code can get mangled (the > indentation thing breaks). the quoted paste seems to avoid this mostly > with the downside that the quote characters need to be striped from the > py file. by the way, any suggestions are welcome regarding > that too... there doesn't really seem to be a good way to share code on > the group consistently. use a news reader rather than Google groups BTW documenting decorators is a good idea even if only for your own use. it has taken me a long type to groc decorators & see any reason why I would use one rather than just modifying my function. (I finally got it when mucking about with wsgi where I used a couple of decorators to prepend & append header & footer files to various other functions, reducing code duplication significantly -- WHO sees a BEACH BUNNY sobbing on a SHAG RUG?! From roy at panix.com Tue May 13 07:11:29 2014 From: roy at panix.com (Roy Smith) Date: Tue, 13 May 2014 07:11:29 -0400 Subject: SQLAlchemy - web framework ? References: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> Message-ID: In article , flebber wrote: > Roy.that is interesting that you can use mongoengine. > > Recent google results such as seem to assert there are a lot of inherent risk > in swapping out components, though I may be misinterpreting it. > http://www.slideshare.net/daikeren/tradeoffs-of-replacing-core-components I wouldn't take every slideshow I find on the net as gospel. There is risk in doing anything. The only slide I find of much value in that deck is 22, but that's pretty much a requirement anyway. Most of the rest is just fear mongering. FWIW, we don't use any third-party packages, and we don't use the admin. If those things are important to you, then I agree, swapping out the ORM will be interesting. Mostly what we use from django are the middleware framework (we write a lot of our own middleware), url parsing, and view dispatch. From roy at panix.com Tue May 13 07:16:36 2014 From: roy at panix.com (Roy Smith) Date: Tue, 13 May 2014 07:16:36 -0400 Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <5371b23a$0$11109$c3e8da3@news.astraweb.com> <5371c834$0$11109$c3e8da3@news.astraweb.com> Message-ID: In article <5371c834$0$11109$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > And after 15 years, I daresay that includes you. Sometimes code is still running for 15 years because it's so wonderful nobody has been able to come up with anything better. Sometimes it's because nobody knows how it works anymore and everybody is afraid to touch it :-) From alister.nospam.ware at ntlworld.com Tue May 13 07:19:06 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 13 May 2014 11:19:06 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 13 May 2014 01:18:35 +0000, Steven D'Aprano wrote: > On Mon, 12 May 2014 17:47:48 +0000, alister wrote: > >> On Mon, 12 May 2014 16:19:17 +0100, Mark Lawrence wrote: >> >>> This was *NOT* written by our resident unicode expert >>> http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/ >>> >>> Posted as I thought it would make a rather pleasant change from >>> interminable threads about names vs values vs variables vs objects. >> >> Surely those example programs are not the pythonoic way to do things or >> am i missing something? > > Armin Ronacher is an extremely experienced and knowledgeable Python > developer, and a Python core developer. He might be wrong, but he's not > *obviously* wrong. > I am only an amateur python coder which is why I asked if I am missing something I could not see any reason to be using the shutil module if all that the programm is doing is opening a file, reading it & then printing it. is it python that causes the issue, the shutil module or just the OS not liking the data it is being sent? an explanation of why this approach is taken would be much appreciated. -- Revenge is a form of nostalgia. From rosuav at gmail.com Tue May 13 07:21:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 21:21:21 +1000 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <5371b23a$0$11109$c3e8da3@news.astraweb.com> <5371c834$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Tue, May 13, 2014 at 9:16 PM, Roy Smith wrote: > Sometimes code is still running for 15 years because it's so wonderful > nobody has been able to come up with anything better. Sometimes it's > because nobody knows how it works anymore and everybody is afraid to > touch it :-) And sometimes, both... ChrisA From roy at panix.com Tue May 13 07:20:34 2014 From: roy at panix.com (Roy Smith) Date: Tue, 13 May 2014 07:20:34 -0400 Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> Message-ID: In article , Chris Angelico wrote: > On Tue, May 13, 2014 at 4:03 PM, Ben Finney wrote: > > (It's always a good day to remind people that the rest of the world > > exists.) > > Ironic that this should come up in a discussion on Unicode, given that > Unicode's fundamental purpose is to welcome that whole rest of the > world instead of yelling "LALALALALA America is everything" and > pretending that ASCII, or Latin-1, or something, is all you need. ASCII *is* all I need. The problem is, it's not all that other people need, and I need to interact with those other people. From gheskett at wdtv.com Tue May 13 07:42:12 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Tue, 13 May 2014 07:42:12 -0400 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: <5371c834$0$11109$c3e8da3@news.astraweb.com> References: <87tx91warf.fsf@elektro.pacujo.net> <5371c834$0$11109$c3e8da3@news.astraweb.com> Message-ID: <201405130742.12274.gheskett@wdtv.com> On Tuesday 13 May 2014 03:22:28 Steven D'Aprano did opine And Gene did reply: > On Tue, 13 May 2014 02:31:14 -0400, Gene Heskett wrote: > > People who write buggy self-modifying code aren't paying attention. > > [...] > > > IMO, people who bad-mouth self-modifying code are folks who don't > > have the patience to do it right, because stable self-modifying code > > CAN most certainly be done. > > Many things *can* be done. The question is, is it worth the effort to > do it? The simplest code that meets the functional requirements is > usually the best. > > > Stable, dead reliable self modifying code CAN be written, I have done > > it. And that code was still in use at the tv station that I wrote it > > for 15 years later. > > Yep, and people have written stable, dead reliable unstructured code > using GOTO and possibly even COMEFROM too. Nevertheless, nobody serious > uses unstructured code these days. It takes much more effort to get it > stable and reliable in the first place. Maintenance is ten or a hundred > times harder and therefore more expensive. Chances are good that the > software you wrote 15 years ago is now a black box: it damn well better > work, because no-one knows how it works well enough to debug problems > or add new functionality. > > And after 15 years, I daresay that includes you. Actually, 34 years, but I have the advantage of having retained a copy on dead tree as well as a broadcast cart with a couple copies of it, on a shelf above where I am sitting. And, should tape machine ballistics change, I left an extensive tome on how to adjust it for that. The 1802 is a somewhat limited beast, but for all the processing it had to do on the falling edge of each vertical drive pulse (it drove the raw, homemade character generator to lay a new academy leader among other things), it had all the data constructed to generate those characters with 6 dma cycles per video field, and was all done in the middle of line 21 of an ntsc field, twiddling its thumbs until the next falling edge of house vertical drive. I also invented a drop frame version of the time code with half the error of the official version. Just because I could. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From rustompmody at gmail.com Tue May 13 07:52:26 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 13 May 2014 04:52:26 -0700 (PDT) Subject: PEP 8 : Maximum line Length : In-Reply-To: References: Message-ID: On Tuesday, May 13, 2014 12:37:24 PM UTC+5:30, Ganesh Pal wrote: > Hi Team , > > > what would be the best way to intent the below line . > > I have few lines in my program exceeding the allowed maximum line Length of 79./80 characters > > > Example 1 : > > > p = Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) First rule of python-list: Pay careful attention to Peter Otten. That said... 80-character limit?! Sheesh! A relic of the days when terminals were ASCII and 80x24 I wrote about this http://blog.languager.org/2012/10/layout-imperative-in-functional.html While its mostly haskell oriented, the comments are amusingly related to this question in any language: Comment: It is kind of ironic that the blog format wraps your wide code examples at 65 chars. What this goes to show is that while 80 is ridiculously low by most displays today, it is too high for many web/mailing-list fora. Of course a standard helps in removing superfluous variations. Still... its 2014 and 80-columns is as current and relevant as ASCII. PS. Last rule of python list: Always listen to Peter Otten. From musicalhacksaw at yahoo.co.uk Tue May 13 07:52:49 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Tue, 13 May 2014 04:52:49 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> Message-ID: I have removed the original Beautiful Soup 4 download, that I had unzipped to my Beautiful Soup directory on the C drive. I downloaded the latest version of Beautiful Soup 4 from the Crummy site. I unzipped it, and removed the contents of the unzipped directory and placed contents in my Beautiful Soup directory, and again had the same output to my console re: -------------------------------------------------------------------------------- Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Intel Atom>cd "c:\Beautiful Soup" c:\Beautiful Soup>c:\Python27\python setup.py install c:\Beautiful Soup> ------------------------------------------------------------------------------- I have made a note of all the contents of the downloaded and unzipped BS4,ie the contents of my Beautiful Soup folder on the C drive, which is as follows: ------------------------------------------------------------------------------- running install running build running build_py error: package directory 'bs4' does not existinit _html5lib _htmlparser _lxml 6.1 AUTHORS conf COPYING dammit demonstration_markup element index.rst Makefile NEWS PGK-INFO README setup test_builder_registry test_docs test_html5lib test_htmlparser text_lxml test_soup test_tree testing TODO -------------------------------------------------------------------------------- I can see no bs4 folder within the contents. I can not see any setup.py file either, but this is how I downloaded it. I am only following instructions as suggested. I do not understand why it is not working. I hope someone can direct me in the right direction, as I seem to be stuck, and I don't think it has much bearing on my fluency or lack of it with Python. From musicalhacksaw at yahoo.co.uk Tue May 13 07:59:24 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Tue, 13 May 2014 04:59:24 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> Message-ID: <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> Dear Ian, and other programmers, thank you for your advice. I am resending the last message because this twattish cut and paste facility on my computer has a knack of chopping off ones original message, I will try to convey the right message this time : I have removed the original Beautiful Soup 4 download, that I had unzipped to my Beautiful Soup directory on the C drive. I downloaded the latest version of Beautiful Soup 4 from the Crummy site. I unzipped it, and removed the contents of the unzipped directory and placed contents in my Beautiful Soup directory, and again had the same output to my console re: -------------------------------------------------------------------------------- Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Intel Atom>cd "c:\Beautiful Soup" c:\Beautiful Soup>c:\Python27\python setup.py install running install running build running build_py error: package directory 'bs4' does not exist c:\Beautiful Soup> ------------------------------------------------------------------------------- I have made a note of all the contents of the downloaded and unzipped BS4,ie the contents of my Beautiful Soup folder on the C drive, which is as follows: ------------------------------------------------------------------------------- running install running build running build_py error: package directory 'bs4' does not existinit _html5lib _htmlparser _lxml 6.1 AUTHORS conf COPYING dammit demonstration_markup element index.rst Makefile NEWS PGK-INFO README setup test_builder_registry test_docs test_html5lib test_htmlparser text_lxml test_soup test_tree testing TODO -------------------------------------------------------------------------------- I can see no bs4 folder within the contents. I can not see any setup.py file either, but this is how I downloaded it. I am only following instructions as suggested. I do not understand why it is not working. I hope someone can direct me in the right direction, as I seem to be stuck, and I don't think it has much bearing on my fluency or lack of it with Python. From roy at panix.com Tue May 13 08:09:37 2014 From: roy at panix.com (Roy Smith) Date: Tue, 13 May 2014 08:09:37 -0400 Subject: PEP 8 : Maximum line Length : References: Message-ID: In article , Ganesh Pal wrote: > Hi Team , > > > what would be the best way to intent the below line . > > I have few lines in my program exceeding the allowed maximum line Length of > 79./80 characters > > Example 1 : > > p = Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) The problem here is not so much that you've exceeded 80 columns, but that there's no logical structure which gives your eyes (and your brain) hints about how to parse this. I would start by adding some white space > p = Subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) now, at least, it's easier to see where each argument stops and the next one starts. But, I would really break this up into multiple lines > p = Subprocess.Popen(shlex.split(cmd), > stdout=subprocess.PIPE, > stderr=subprocess.PIPE) From ben at benfinney.id.au Tue May 13 08:10:11 2014 From: ben at benfinney.id.au (Ben Finney) Date: Tue, 13 May 2014 22:10:11 +1000 Subject: PEP 8 : Maximum line Length : References: Message-ID: <851tvxanh8.fsf@benfinney.id.au> Ganesh Pal writes: > what would be the best way to intent the below line . You'd need to define ?best? in order to get an objective answer. So my answer will be based on my preferences, and general rules I've observed for making code readable. > Example 1 : > > p = > Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) (Your example violates PEP 8 also in not having a space after the commas. I'll fix that in my response.) Breaking a long line after bracketing syntax is a good way to do it. Make sure to use sntadard indentation:: Subprocess.Popen( shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) Alternatively, if the statement line is indented further:: Subprocess.Popen( shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) > Iam running pylint and it says the above line is tool long how do I limit > it to 79 character without violating any rules * Break after bracketing syntax:: frobnicate( foo, bar, baz) * Keep all the inside-the-brackets contents at the same indentation level (preferably 8 columns, to differentiate from a block of statements) if worzel: fnoop(wibble, wobble, wubble) frobnicate( foo, bar, baz) while True: gezunk() Here's an answer I gave on StackOverflow for this question (). -- \ ?If you're a cowboy and you're dragging a guy behind your | `\ horse, I bet it would really make you mad if you looked back | _o__) and the guy was reading a magazine.? ?Jack Handey | Ben Finney From ben at benfinney.id.au Tue May 13 08:26:40 2014 From: ben at benfinney.id.au (Ben Finney) Date: Tue, 13 May 2014 22:26:40 +1000 Subject: PEP 8 : Maximum line Length : References: Message-ID: <85mwel985b.fsf@benfinney.id.au> Roy Smith writes: > > p = Subprocess.Popen(shlex.split(cmd), > > stdout=subprocess.PIPE, > > stderr=subprocess.PIPE) That is PEP 8 conformant, but I find it hurts maintainability: it is far too much indentation. Horizontal space is costly, because so much indentation severely limits the length of names etc. that you can use on the continuation lines. Worse, it is also needlessly tying all the continuation lines to the length of the text before the open paren. What if ?p? changes to some other name? With the style I've advocated:: p = Subprocess.Popen( shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) Changing the name on the first line doesn't entail changing any other line:: proc = Subprocess.Popen( shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) special_process_map[this_process] = Subprocess.Popen( shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) Whereas with your suggestion, every line would need to change simply because the first one did:: special_process_map[this_process] = Subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) Yes, that's contrived. But I prefer to use a style that doesn't need to deal with the issue of when the indentation has gone too far for a single statement. It's for both those reasons that I recommend avoiding the ?align with open bracket? style, and instead use a standard eight-column indentation for continuation lines. -- \ ?One bad programmer can easily create two new jobs a year. | `\ Hiring more bad programmers will just increase our perceived | _o__) need for them.? ?David Lorge Parnas, 1999-03 | Ben Finney From python.list at tim.thechases.com Tue May 13 08:52:06 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 13 May 2014 07:52:06 -0500 Subject: PEP 8 : Maximum line Length : In-Reply-To: <85mwel985b.fsf@benfinney.id.au> References: <85mwel985b.fsf@benfinney.id.au> Message-ID: <20140513075206.17ab7d1c@bigbox.christie.dr> On 2014-05-13 22:26, Ben Finney wrote: > Changing the name on the first line doesn't entail changing any > other line:: > > proc = Subprocess.Popen( > shlex.split(cmd), > stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > > special_process_map[this_process] = Subprocess.Popen( > shlex.split(cmd), > stdout=subprocess.PIPE, > stderr=subprocess.PIPE) I second the idea of just putting each-of-many-parameters on its own line. Not only that, I also like to tack on trailing commas and put the closing paren on its own line to make diffs easier to read: special_process_map[this_process] = Subprocess.Popen( shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) so that when I add the inevitable parameter, the diff merely reads like --- tim1.txt 2014-05-13 07:44:42.441754319 -0500 +++ tim2.txt 2014-05-13 07:45:35.753755858 -0500 @@ -2,4 +2,5 @@ shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, + bufsize=1024, ) which is quite clear that just one line was added, compared to --- ben1.txt 2014-05-13 07:44:51.033754566 -0500 +++ ben2.txt 2014-05-13 07:45:46.737756176 -0500 @@ -1,4 +1,5 @@ special_process_map[this_process] = Subprocess.Popen( shlex.split(cmd), stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stderr=subprocess.PIPE, + bufsize=1024) which makes me have to think/verify about whether anything else changed between insertion and deletion of lines. -tkc From rustompmody at gmail.com Tue May 13 09:18:49 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 13 May 2014 06:18:49 -0700 (PDT) Subject: PEP 8 : Maximum line Length : In-Reply-To: References: Message-ID: <8d2af187-96e9-4367-83f5-d95e7f435734@googlegroups.com> On Tuesday, May 13, 2014 2:15:49 PM UTC+5:30, Peter Otten wrote: > Ganesh Pal wrote: > > what would be the best way to intent the below line . > > p = Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) > (3) Import names: > > > from subprocess import PIPE > p = subprocess.Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE) Am I missing something basic that nobody has suggested the above technique iterated once more?? from subprocess import Popen, PIPE p = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE) From breamoreboy at yahoo.co.uk Tue May 13 09:23:52 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 13 May 2014 14:23:52 +0100 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> Message-ID: On 13/05/2014 12:59, Simon Evans wrote: I suggest that you follow the instructions here http://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows to get pip, then let pip do the work for you as that's what it's designed for :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Tue May 13 09:30:46 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 13 May 2014 14:30:46 +0100 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <87tx8uccgd.fsf@elektro.pacujo.net> Message-ID: On 13/05/2014 09:38, Chris Angelico wrote: > > It's not a good thing. It means that you have the convenience of > pretending there's no problem, which means you don't notice trouble > until something happens... and then, in all probability, your app is > in production and you have no idea why stuff went wrong. > Unless you're (un)lucky enough to be working on IIRC the 1/3 of major IT projects that deliver nothing :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Tue May 13 09:37:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 23:37:47 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <87tx8uccgd.fsf@elektro.pacujo.net> Message-ID: On Tue, May 13, 2014 at 11:30 PM, Mark Lawrence wrote: > On 13/05/2014 09:38, Chris Angelico wrote: >> >> >> It's not a good thing. It means that you have the convenience of >> pretending there's no problem, which means you don't notice trouble >> until something happens... and then, in all probability, your app is >> in production and you have no idea why stuff went wrong. >> > > Unless you're (un)lucky enough to be working on IIRC the 1/3 of major IT > projects that deliver nothing :) Been there, done that. At least, most likely so... there is a chance, albeit slim, that the boss/owner will either discover someone who'll finish the project for him, or find the time to finish it himself. I gather he's looking at ripping all my code out and replacing it with PHP of his own design, which should be fun. On the plus side, that does mean he can get any idiot straight out of a uni course to do the work; much easier than finding someone who knows Python, Pike, bash, and C++. The White King told Alice that cynicism is a disease that can be cured... but it can also be inflicted, and a promising-looking N-year project that collapses because the boss starts getting stupid with code formatting rules and then ends up firing his last remaining competent employee is a pretty effective means of instilling cynicism. ChrisA From steve+comp.lang.python at pearwood.info Tue May 13 09:39:13 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 May 2014 13:39:13 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> Message-ID: <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> On Tue, 13 May 2014 07:20:34 -0400, Roy Smith wrote: > ASCII *is* all I need. You've never needed to copyright something? Copyright ? Roy Smith 2014... I know some people use (c) instead, but that actually has no legal standing. (Not that any reasonable judge would invalidate a copyright based on a technicality like that, not these days.) Or price something in cents? I suppose the days of the 25? steak dinner are long gone, but you might need to sell something for 99? a pound... > The problem is, it's not all that other people > need, and I need to interact with those other people. True, true. -- Steven D'Aprano http://import-that.dreamwidth.org/ From breamoreboy at yahoo.co.uk Tue May 13 09:42:05 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 13 May 2014 14:42:05 +0100 Subject: Fortran (Was: The "does Python have variables?" debate) In-Reply-To: References: <87tx91warf.fsf@elektro.pacujo.net> <5371b23a$0$11109$c3e8da3@news.astraweb.com> <5371c834$0$11109$c3e8da3@news.astraweb.com> Message-ID: On 13/05/2014 12:21, Chris Angelico wrote: > On Tue, May 13, 2014 at 9:16 PM, Roy Smith wrote: >> Sometimes code is still running for 15 years because it's so wonderful >> nobody has been able to come up with anything better. Sometimes it's >> because nobody knows how it works anymore and everybody is afraid to >> touch it :-) > > And sometimes, both... > Or neither as you don't have the source :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Tue May 13 09:43:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 23:43:47 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 13, 2014 at 11:39 PM, Steven D'Aprano wrote: > You've never needed to copyright something? Copyright ? Roy Smith 2014... > I know some people use (c) instead, but that actually has no legal > standing. (Not that any reasonable judge would invalidate a copyright > based on a technicality like that, not these days.) Copyright Chris Angelico 2014. The full word "copyright" has legal standing. I tend to stick with that in my README files; staying ASCII makes it that bit safer for random text editors (*cough*Notepad*cough*) that might otherwise misinterpret it (only a bit, though [1]). > Or price something in cents? I suppose the days of the 25? steak dinner > are long gone, but you might need to sell something for 99? a pound... $0.99/lb? :) ChrisA [1] https://en.wikipedia.org/wiki/Bush_hid_the_facts From steve+comp.lang.python at pearwood.info Tue May 13 09:46:37 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 May 2014 13:46:37 GMT Subject: PEP 8 : Maximum line Length : References: Message-ID: <5372223c$0$29980$c3e8da3$5496439d@news.astraweb.com> On Tue, 13 May 2014 04:52:26 -0700, Rustom Mody wrote: > What this goes to show is that while 80 is ridiculously low by most > displays today, Not for people who like to has two (or three, or four) windows side-by- side. Or multiple views of the same document. > it is too high for many web/mailing-list fora. And smart phones. [...] > PS. > Last rule of python list: Always listen to Peter Otten. Yes. Peter is a treasure to the community, not just for his knowledge but for his patience and friendliness. -- Steven D'Aprano From steve+comp.lang.python at pearwood.info Tue May 13 09:49:12 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 May 2014 13:49:12 GMT Subject: Why isn't my re.sub replacing the contents of my MS Word file? References: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> Message-ID: <537222d8$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 12 May 2014 10:35:53 -0700, scottcabit wrote: > On Friday, May 9, 2014 8:12:57 PM UTC-4, Steven D'Aprano wrote: > >> Good: >> >> >> >> fStr = re.sub(b'‒', b'-', fStr) >> >> > Doesn't work...the document has been verified to contain endash and > emdash characters, but this does NOT replace them. You may have missed my follow up post, where I said I had not noticed you were operating on a binary .doc file. The text content of your doc file might look like: This ? is an n-dash. when viewed in Microsoft Word, but that is not the contents on disk. Word .doc files are a proprietary, secret binary format. Apart from the rest of the document structure and metadata, the text itself could be stored any old way. We don't know how. Microsoft surely knows how it is stored, but are unlikely to tell. A few open source projects like OpenOffice, LibreOffice and Abiword have reverse-engineered the file format. Taking a wild guess, I think it could be something like: This \xe2\x80\x93 is an n-dash. or possibly: \x00T\x00h\x00i\x00s\x00 \x13\x00 \x00i\x00s\x00 \x00a \x00n\x00 \x00n\x00-\x00d\x00a\x00s\x00h\x00. or: This {EN DASH} is an n-dash. or: x\x9c\x0b\xc9\xc8,V\xa8v\xf5Spq\x0c\xf6\xa8U\x00r\x12 \xf3\x14\xf2tS\x12\x8b3\xf4\x00\x82^\x08\xf8 (that last one is the text passed through the zlib compressor), but really I'm just making up vaguely conceivable possibilities. If you're not willing or able to use a full-blown doc parser, say by controlling Word or LibreOffice, the other alternative is to do something quick and dirty that might work most of the time. Open a doc file, or multiple doc files, in a hex editor and *hopefully* you will be able to see chunks of human-readable text where you can identify how en-dashes and similar are stored. -- Steven D'Aprano From invalid at invalid.invalid Tue May 13 09:49:43 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 13 May 2014 13:49:43 +0000 (UTC) Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> Message-ID: On 2014-05-13, Chris Angelico wrote: > On Tue, May 13, 2014 at 4:03 PM, Ben Finney wrote: >> (It's always a good day to remind people that the rest of the world >> exists.) > > Ironic that this should come up in a discussion on Unicode, given that > Unicode's fundamental purpose is to welcome that whole rest of the > world instead of yelling "LALALALALA America is everything" and > pretending that ASCII, or Latin-1, or something, is all you need. Well, strictly speaking, it ASCII or Latin-1 _is_ all I need. I will however admit to the existence of other people who might need something else... -- Grant Edwards grant.b.edwards Yow! How many retured at bricklayers from FLORIDA gmail.com are out purchasing PENCIL SHARPENERS right NOW?? From invalid at invalid.invalid Tue May 13 09:51:20 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 13 May 2014 13:51:20 +0000 (UTC) Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-05-13, Steven D'Aprano wrote: > On Tue, 13 May 2014 07:20:34 -0400, Roy Smith wrote: > >> ASCII *is* all I need. > > You've never needed to copyright something? Copyright ? Roy Smith 2014... Bah. You don't need the little copyright symbol at all. The statement without the symbol has the exact same legal weight. -- Grant Edwards grant.b.edwards Yow! World War Three can at be averted by adherence gmail.com to a strictly enforced dress code! From rosuav at gmail.com Tue May 13 09:55:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 May 2014 23:55:57 +1000 Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: <537222d8$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> <537222d8$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 13, 2014 at 11:49 PM, Steven D'Aprano wrote: > > This {EN DASH} is an n-dash. > > or: > > x\x9c\x0b\xc9\xc8,V\xa8v\xf5Spq\x0c\xf6\xa8U\x00r\x12 > \xf3\x14\xf2tS\x12\x8b3\xf4\x00\x82^\x08\xf8 > > > (that last one is the text passed through the zlib compressor) I had to decompress that just to see what "text" you passed through zlib, given that zlib is a *byte* compressor :) Turns out it's the braced notation given above, encoded as ASCII/UTF-8. ChrisA From skip at pobox.com Tue May 13 10:02:29 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 13 May 2014 09:02:29 -0500 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <87tx8uccgd.fsf@elektro.pacujo.net> Message-ID: On Tue, May 13, 2014 at 3:38 AM, Chris Angelico wrote: >> Python 2's ambiguity allows me not to answer the tough philosophical >> questions. I'm not saying it's necessarily a good thing, but it has its >> benefits. > > It's not a good thing. It means that you have the convenience of > pretending there's no problem, which means you don't notice trouble > until something happens... and then, in all probability, your app is > in production and you have no idea why stuff went wrong. BITD, when I still maintained and developed Musi-Cal (an early online concert calendar, long since gone), I faced a challenge when I first started encountering non-ASCII band names and cities. I resisted UTF-8. After all, if I printed a string containing an "?", it came out looking like What kind of mess was that??? I tried to ignore it, or assume Latin-1 would cover all the bases (my first non-ASCII inputs tended to come from Western Europe). If nothing else, at least "?" was legible. Needless to say, those approaches didn't work well. After perhaps six months or a year, I broke down and started converting everything coming in ? or going out? to UTF-8 at the boundaries of my system (making educated guesses at ?input encodings if necessary). My life got a whole lot easier after that. The distinction between bytes and text didn't really matter much, certainly not compared to the mess I had before where strings of unknown data leaked into my system and its database. Skip ?P.S. My apologies for the mess this message probably is. Amazing as it may seem, Gmail in Chrome does a crappy job editing anything other than plain text. Also, I'm surprised in this day and age that common tools like Gnome Terminal have little or no encoding support. I wound up having to pop up urxvt to get an encodings-flexible terminal emulator...? -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: e.png Type: image/png Size: 270 bytes Desc: not available URL: From rustompmody at gmail.com Tue May 13 10:30:18 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 13 May 2014 07:30:18 -0700 (PDT) Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2a5ac498-4bcc-4d39-a7bc-cd1bec3a77e4@googlegroups.com> On Tuesday, May 13, 2014 7:13:47 PM UTC+5:30, Chris Angelico wrote: > On Tue, May 13, 2014 at 11:39 PM, Steven D'Aprano > > Or price something in cents? I suppose the days of the 25? steak dinner > > are long gone, but you might need to sell something for 99? a pound... > > > $0.99/lb? :) Dollars Zeros Slashes Question marks Smileys... Just alphabets is enough I think... Come to think of it why have anything other than zeros and ones? From varun7rs at gmail.com Tue May 13 10:31:28 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Tue, 13 May 2014 07:31:28 -0700 (PDT) Subject: Need help to write data onto an XML file after reading data from another xml file Message-ID: <2c8cb313-50f6-439b-a979-bd320a2c7b2c@googlegroups.com> Hello Users, I am in dire need of your help. I have been working on this code for quite some time and it is making me restless. All I am trying to do is, 1. Read data from an xml file. Source: http://sndlib.zib.de/coredata.download.action?objectName=germany50&format=xml&objectType=network 2. The data I'm concerned about is the node ID, co-ordinates, capacity of the links, source and destination names. 3. I'm creating a topology with this information and the topology is same as the one given in the xml file. But, I'd like to add a few extra parameters and demands which I have mentioned in the .py file. 4. This is where I am faltering. I am just not able to create this topology. The file has also become really messy as I tried a lot of weird stuff and commented it out as it did not work. 5. I'll attach the relevant files and I'd like to write the output onto a new xml file. I'd be glad if any of you could help me out. I'm indebted to you guys. Oh I was not aware that I could attach files. Anyways, here is the link to the files I'm working on https://www.dropbox.com/sh/i8h321y7c9c60vt/AADzDj7oOM8YU76Ww6W4LIPYa Thanks a lot everyone From rosuav at gmail.com Tue May 13 10:36:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 May 2014 00:36:45 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <2a5ac498-4bcc-4d39-a7bc-cd1bec3a77e4@googlegroups.com> References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <2a5ac498-4bcc-4d39-a7bc-cd1bec3a77e4@googlegroups.com> Message-ID: On Wed, May 14, 2014 at 12:30 AM, Rustom Mody wrote: > Come to think of it why have anything other than zeros and ones? Obligatory: http://xkcd.com/257/ ChrisA From alister.nospam.ware at ntlworld.com Tue May 13 10:42:51 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 13 May 2014 14:42:51 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 13 May 2014 13:51:20 +0000, Grant Edwards wrote: > On 2014-05-13, Steven D'Aprano > wrote: >> On Tue, 13 May 2014 07:20:34 -0400, Roy Smith wrote: >> >>> ASCII *is* all I need. >> >> You've never needed to copyright something? Copyright ? Roy Smith >> 2014... > > Bah. You don't need the little copyright symbol at all. The statement > without the symbol has the exact same legal weight. You do not need any statements at all, copyright is automaticly assigned to anything you create (at least that is the case in UK Law) although proving the creation date my be difficult. -- Depends on how you define "always". :-) -- Larry Wall in <199710211647.JAA17957 at wall.org> From python at mrabarnett.plus.com Tue May 13 10:48:55 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 13 May 2014 15:48:55 +0100 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> Message-ID: <537230D7.2030801@mrabarnett.plus.com> On 2014-05-13 12:59, Simon Evans wrote: > Dear Ian, and other programmers, thank you for your advice. > I am resending the last message because this twattish cut and paste facility on my computer has a knack of chopping off ones original message, I will try to convey the right message this time : > > I have removed the original Beautiful Soup 4 download, that I had unzipped to my Beautiful Soup directory on the C drive. > I downloaded the latest version of Beautiful Soup 4 from the Crummy site. > I unzipped it, and removed the contents of the unzipped directory and placed contents in my Beautiful Soup directory, and again had the same output to my console re: > -------------------------------------------------------------------------------- > > Microsoft Windows [Version 6.1.7601] > Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > C:\Users\Intel Atom>cd "c:\Beautiful Soup" > > c:\Beautiful Soup>c:\Python27\python setup.py install > > running install > running build > running build_py > error: package directory 'bs4' does not exist > > > c:\Beautiful Soup> > ------------------------------------------------------------------------------- > I have made a note of all the contents of the downloaded and unzipped BS4,ie the contents of my Beautiful Soup folder on the C drive, which is as follows: > ------------------------------------------------------------------------------- > > running install > running build > running build_py > > error: package directory 'bs4' does not existinit > _html5lib > _htmlparser > _lxml > 6.1 > AUTHORS > conf > COPYING > dammit > demonstration_markup > element > index.rst > Makefile > NEWS > PGK-INFO > README > setup > test_builder_registry > test_docs > test_html5lib > test_htmlparser > text_lxml > test_soup > test_tree > testing > TODO > -------------------------------------------------------------------------------- > I can see no bs4 folder within the contents. > I can not see any setup.py file either, but this is how I downloaded it. > I am only following instructions as suggested. > I do not understand why it is not working. > I hope someone can direct me in the right direction, as I seem to be stuck, and I don't think it has much bearing on my fluency or lack of it with Python. > I think I see your problem: you've unpacked everything into a single folder instead of a folder hierarchy. (It also looks like you have Explorer configured to hide the file extensions. That's generally _not_ recommended.) Try this: #! python3.4 # -*- coding: utf-8 -*- from os.path import splitext import gzip import tarfile # The path of the downloaded file. tar_gz_path = r'C:\beautifulsoup4-4.3.2.tar.gz' # Unpack the .tar.gz file to a .tar file. tar_path, ext = splitext(tar_gz_path) with gzip.open(tar_gz_path, 'rb') as from_file: with open(tar_path, 'wb') as to_file: chunk = from_file.read() to_file.write(chunk) # Unpack the .tar file to a folder. folder, ext = splitext(tar_path) tar = tarfile.open(tar_path) tar.extractall(folder) tar.close() From invalid at invalid.invalid Tue May 13 11:21:15 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 13 May 2014 15:21:15 +0000 (UTC) Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-05-13, alister wrote: > On Tue, 13 May 2014 13:51:20 +0000, Grant Edwards wrote: > >> On 2014-05-13, Steven D'Aprano >> wrote: >>> On Tue, 13 May 2014 07:20:34 -0400, Roy Smith wrote: >>> >>>> ASCII *is* all I need. >>> >>> You've never needed to copyright something? Copyright ? Roy Smith >>> 2014... >> >> Bah. You don't need the little copyright symbol at all. The statement >> without the symbol has the exact same legal weight. > > You do not need any statements at all, copyright is automaticly assigned > to anything you create (at least that is the case in UK Law) > although proving the creation date my be difficult. Yep, it's the same in the US. -- Grant Edwards grant.b.edwards Yow! Hello. Just walk at along and try NOT to think gmail.com about your INTESTINES being almost FORTY YARDS LONG!! From wescpy at gmail.com Tue May 13 12:06:17 2014 From: wescpy at gmail.com (wesley chun) Date: Tue, 13 May 2014 09:06:17 -0700 Subject: ANN: Intro+Intermediate Python, San Francisco, Jul 30-31, Aug 1 Message-ID: Greetings! I'll be offering another hardcore Python course this summer near the San Francisco airport. If you're somewhat new to or have some Python experience under your belt already but want to fill-in the holes, this course is for you. Why take a real course when you can learn Python online or by reading books? Well, my goal isn't to teach Python syntax, which you can from any teacher, live or online, or from giant books. My job is to create great Python developers and removing the roadblocks that impede your path to getting there. This intensive course is based on my "Core Python" (http://corepython.com) books and is made up of 3 full days complete with lectures and several hands-on coding labs per day. t's also a great excuse to coming to beautiful Northern California for a summer vacation! Groups and development teams are welcome as well as individuals. I do more private gigs and fewer of these public courses lately, so please come join if you can... my next public intro/intermediate course may not be for awhile, so I'm hoping to meet some of you this time around! Sign up soon... there's a special earlybird rate for the rest of this month before going up to the regular rate after that. More details and registration at http://cyberwebconsulting.com as well as in the ad: http://goo.gl/pyJseQ I'm no fan of spam, so I'll only send out one last reminder as the date gets closer... say around the end of June. Cheers, -- Wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "A computer never does what you want... only what you tell it." +wesley chun : wescpy at gmail : @wescpy Python training & consulting : http://CyberwebConsulting.com "Core Python" books : http://CorePython.com Python blog: http://wescpy.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 13 12:33:43 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 13 May 2014 10:33:43 -0600 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> Message-ID: On Tue, May 13, 2014 at 5:59 AM, Simon Evans wrote: > I can see no bs4 folder within the contents. > I can not see any setup.py file either, but this is how I downloaded it. You do have a setup.py in there, but your Windows explorer is showing it to you without the .py extension. Something unusual is happening with the download/extraction process though and you're missing the correct folder structure. If you take a look here, you can see what you *should* have after unzipping: http://bazaar.launchpad.net/~leonardr/beautifulsoup/bs4/files This approach seems to be unproductive though, so I'm going to second Mark's suggestion to just use pip: 1) Go to pip-installer.org and download the single file get-pip.py 2) Open a command prompt and cd to the folder you downloaded that file into. 3) python get-pip.py 4) pip install beautifulsoup4 And then you should finally be ready to get started. Good luck! From ian.g.kelly at gmail.com Tue May 13 12:08:42 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 13 May 2014 10:08:42 -0600 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 13, 2014 at 5:19 AM, alister wrote: > I am only an amateur python coder which is why I asked if I am missing > something > > I could not see any reason to be using the shutil module if all that the > programm is doing is opening a file, reading it & then printing it. > > is it python that causes the issue, the shutil module or just the OS not > liking the data it is being sent? > > an explanation of why this approach is taken would be much appreciated. No, that part is perfectly fine. This is exactly what the shutil module is meant for: providing shell-like operations. Although in this case the copyfileobj function is quite simple (have yourself a look at the source -- it just reads from one file and writes to the other in a loop), in general the Pythonic thing is to avoid reinventing the wheel. And since it's so simple, it shouldn't be hard to see that the use of the shutil module has nothing to do with the Unicode woes here. The crux of the issue is that a general-purpose command like cat typically can't know the encoding of its input and can't assume anything about it. In fact, there may not even be an encoding; cat can be used with binary data. The only non-destructive approach then is to copy the binary data straight from the source to the destination with no decoding steps at all, and trust the user to ensure that the destination will be able to accommodate the source encoding. Because Python 3 presents stdin and stdout as text streams however, it makes them more difficult to use with binary data, which is why Armin sets up all that extra code to make sure his file objects are binary. From jcasale at activenetwerx.com Tue May 13 12:59:46 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Tue, 13 May 2014 16:59:46 +0000 Subject: Exception problem with module Message-ID: I am working with a module that I am seeing some odd behavior. A module.foo builds a custom exception, module.foo.MyError, its done right afaict. Another module, module.bar imports this and calls bar.__setattr__('a_new_name', MyError). Now, not in all but in some cases when I catch a_new_name, my code raises a new exception: During handling of the above exception, another exception occurred: File "C:/dir/test.py", line 12, in except a_new_name as exc: TypeError: catching classes that do not inherit from BaseException is not allowed So, I wont suggest the assignment in bar added anything, nor would I do this, but its what I am working with. Why might this happen? MyError subclasses Exception and calls super passing back args. This has something to do with the assignment in bar, catching MyError obviously works. Any ideas? jlc From rosuav at gmail.com Tue May 13 13:05:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 May 2014 03:05:49 +1000 Subject: Exception problem with module In-Reply-To: References: Message-ID: On Wed, May 14, 2014 at 2:59 AM, Joseph L. Casale wrote: > During handling of the above exception, another exception occurred: > > File "C:/dir/test.py", line 12, in > except a_new_name as exc: > TypeError: catching classes that do not inherit from BaseException is not allowed Best would be to print out what's in a_new_name to see if it really is what you think it is. If you think it is what you think it is, have a look at its __mro__ (method resolution order, it's an attribute of every class), to see what it's really inheriting. That should show you what's happening. ChrisA From jcasale at activenetwerx.com Tue May 13 13:16:21 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Tue, 13 May 2014 17:16:21 +0000 Subject: Exception problem with module In-Reply-To: References: , Message-ID: > Best would be to print out what's in a_new_name to see if it really is > what you think it is. If you think it is what you think it is, have a > look at its __mro__ (method resolution order, it's an attribute of > every class), to see what it's really inheriting. That should show you > what's happening. Lol, In a sea of frustration with this, I cant believe I didn't do that. Problem solved. Thanks, jlc From alain at dpt-info.u-strasbg.fr Tue May 13 13:33:32 2014 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 13 May 2014 19:33:32 +0200 Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> Message-ID: <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> Mark H Harris writes: > On 5/12/14 3:44 AM, Alain Ketterlin wrote: >> When you are doing scientific computation, this overhead is >> unacceptable, because you'll have zillions of computations to perform. > > I'm still trying to sort that out. I have not tested this yet, but > it looks like Julia is fully dynamic (yes it has types too), and it > does parallel processing at its core, so the zillions of computations > are being handled all at once, depending on how many processors|cores > you have. The amount of parallelism is a property of the program, not a property of the language... I hope you don't expect all your julia statements to execute in parallel. (And Fortan/C/C++ have leveraged OpenMP and MPI for years. Julia's distributed arrays and fork-join model may make things a bit easier for the programmer, but I doubt it will lead to better performance.) >> Julia provides a way to make things fast: typing. If you provide >> explicit types, the dynamic typing part obviously disappears, and >> the overhead is removed. > > Julia is dynamic (depending on how far you want to go with that) > but what makes it fast is the JIT. It is almost accomplishing C/C++ > and FORTRAN speeds (even though dynamic) because it is compiling > on-the-fly. JITing by itself has little impact on performance (as unladden-swallow has shown for python). For the JIT to produce code as fast as a Fortan/C/C++ compiler would, two conditions must be met: 1) the JIT has to have as much information about types as the statically-typed language compilers have, and 2) the time spent by the JIT compiler has to be negligible compared to the time spent executing the code. If your program is not statically typed, the code produced by the JIT is very unlikely to be more efficient than the code that would be executed by the virtual machine (or interpreter), because the jitted code needs to do everything the virtual machine does. And the JIT takes time. [...] > Yes, and more+ Gnu GMP & MPFR are not new to me, but the wrapper > and repl are ! I am just realizing the power behind the libraries in > this context, but I am very impressed with the functionality wrapped > around the Gnu stuff... the interface is quite nice. Good. I don't know mathlab enough to see how it compares. >> Sorry, I was comparing to Fortran, and it's use in scientific computing. >> Self modifying code is totally irrelevant there. > > no, no, no... there has to be a value add for scientists to move > away from R or Matlab, or from FORTRAN. Why go to the trouble? [...] > Why?, glad you asked. Enter self modifying code for one. The > influence of Lisp|Scheme is potentially huge here. I wouldn't bet a penny on this. (Probably because I have yet to see a real, convincing application of self-modifying code. I mean something which is not covered by JITs---GPU shaders, and things like that.) The real nice thing that makes Julia a different language is the optional static typing, which the JIT can use to produce efficient code. It's the only meaningful difference with the current state of python. -- Alain. From scottcabit at gmail.com Tue May 13 15:01:59 2014 From: scottcabit at gmail.com (scottcabit at gmail.com) Date: Tue, 13 May 2014 12:01:59 -0700 (PDT) Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: <537222d8$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> <537222d8$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <63051425-ec42-45b4-8a9e-53001625f32a@googlegroups.com> On Tuesday, May 13, 2014 9:49:12 AM UTC-4, Steven D'Aprano wrote: > > You may have missed my follow up post, where I said I had not noticed you > were operating on a binary .doc file. > > If you're not willing or able to use a full-blown doc parser, say by > controlling Word or LibreOffice, the other alternative is to do something > quick and dirty that might work most of the time. Open a doc file, or > multiple doc files, in a hex editor and *hopefully* you will be able to > see chunks of human-readable text where you can identify how en-dashes > and similar are stored. I created a .doc file and opened it with UltraEdit in binary (Hex) mode. What I see is that there are two characters, one for ndash and one for mdash, each a single byte long. 0x96 and 0x97. So I tried this: fStr = re.sub(b'\0x96',b'-',fStr) that did nothing in my file. So I tried this: fStr = re.sub(b'0x97',b'-',fStr) which also did nothing. So, for fun I also tried to just put these wildcards in my re.findall so I added |Part \0x96|Part \0x97 to no avail. Obviously 0x96 and 0x97 are NOT being interpreted in a re.findall or re.sub as hex byte values of 96 and 97 hexadecimal using my current syntax. So here's my question...if I want to replace all ndash or mdash values with regular '-' symbols using re.sub, what is the proper syntax to do so? Thanks! From breamoreboy at yahoo.co.uk Tue May 13 15:08:38 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 13 May 2014 20:08:38 +0100 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> Message-ID: On 13/05/2014 17:33, Ian Kelly wrote: > On Tue, May 13, 2014 at 5:59 AM, Simon Evans wrote: >> I can see no bs4 folder within the contents. >> I can not see any setup.py file either, but this is how I downloaded it. > > You do have a setup.py in there, but your Windows explorer is showing > it to you without the .py extension. Something unusual is happening > with the download/extraction process though and you're missing the > correct folder structure. If you take a look here, you can see what > you *should* have after unzipping: > > http://bazaar.launchpad.net/~leonardr/beautifulsoup/bs4/files > > This approach seems to be unproductive though, so I'm going to second > Mark's suggestion to just use pip: > > 1) Go to pip-installer.org and download the single file get-pip.py > 2) Open a command prompt and cd to the folder you downloaded that file into. > 3) python get-pip.py > 4) pip install beautifulsoup4 > > And then you should finally be ready to get started. Good luck! > To be fair Terry Reedy has suggested pip at least twice, I've just given another source of data on how to get pip in the first place. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From marko at pacujo.net Tue May 13 15:57:16 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 13 May 2014 22:57:16 +0300 Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> Message-ID: <8761l9pi3n.fsf@elektro.pacujo.net> Alain Ketterlin : > The real nice thing that makes Julia a different language is the > optional static typing, which the JIT can use to produce efficient code. > It's the only meaningful difference with the current state of python. I'm guessing the two main performance roadblocks for Python are: 1. The dot notation is a hash table lookup instead of a fixed offset to a vector. 2. The creation of a class instance generates a set of trampolines for all methods. The trampolines are ordinary fields that can be overridden. Both features are critical to Python's "sex appeal;" I wouldn't give them up for performance gains. Producing an effective JIT for Python seems like a formidable challenge but not impossible in principle. After all, the developer *could* provide that static typing information in, like, 99.9% of the code. That would be feat worthy of a Millennium Technology Prize. It would be like having the cake and eating it, too. Marko From andrew at andros.org.uk Tue May 13 16:09:28 2014 From: andrew at andros.org.uk (Andrew McLean) Date: Tue, 13 May 2014 21:09:28 +0100 Subject: Real-world use of concurrent.futures In-Reply-To: References: <536BD338.4070004@andros.org.uk> Message-ID: <53727BF8.7080304@gmail.com> On 08/05/2014 21:44, Ian Kelly wrote: > On May 8, 2014 12:57 PM, "Andrew McLean" > wrote: > > So far so good. However, I thought this would be an opportunity to > > explore concurrent.futures and to see whether it offered any benefits > > over the more explicit approach discussed above. The problem I am having > > is that all the discussions I can find of the use of concurrent.futures > > show use with toy problems involving just a few tasks. The url > > downloader in the documentation is typical, it proceeds as follows: > > > > 1. Get an instance of concurrent.futuresThreadPoolExecutor > > 2. Submit a few tasks to the executer > > 3. Iterate over the results using concurrent.futures.as_completed > > > > That's fine, but I suspect that isn't a helpful pattern if I have a very > > large number of tasks. In my case I could run out of memory if I tried > > submitting all of the tasks to the executor before processing any of the > > results. > > I thought that ThreadPoolExecutor.map would handle this transparently > if you passed it a lazy iterable such as a generator. From my testing > though, that seems not to be the case; with a generator of 100000 > items and a pool of 2 workers, the entire generator was consumed > before any results were returned. > > > I'm guessing what I want to do is, submit tasks in batches of perhaps a > > few hundred, iterate over the results until most are complete, then > > submit some more tasks and so on. I'm struggling to see how to do this > > elegantly without a lot of messy code just there to do "bookkeeping". > > This can't be an uncommon scenario. Am I missing something, or is this > > just not a job suitable for futures? > > I don't think it needs to be "messy". Something like this should do > the trick, I think: > > from concurrent.futures import * > from itertools import islice > > def batched_pool_runner(f, iterable, pool, batch_size): > it = iter(iterable) > # Submit the first batch of tasks. > futures = set(pool.submit(f, x) for x in islice(it, batch_size)) > while futures: > done, futures = wait(futures, return_when=FIRST_COMPLETED) > # Replenish submitted tasks up to the number that completed. > futures.update(pool.submit(f, x) for x in islice(it, len(done))) > yield from done That worked very nicely, thank you. I think that would make a good recipe, whether for the documentation or elsewhere. I suspect I'm not the only person that would benefit from something to bridge the gap between a toy example and something practical. Andrew -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue May 13 16:26:51 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 13 May 2014 21:26:51 +0100 Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: <63051425-ec42-45b4-8a9e-53001625f32a@googlegroups.com> References: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> <537222d8$0$29980$c3e8da3$5496439d@news.astraweb.com> <63051425-ec42-45b4-8a9e-53001625f32a@googlegroups.com> Message-ID: <5372800B.2040704@mrabarnett.plus.com> On 2014-05-13 20:01, scottcabit at gmail.com wrote: > On Tuesday, May 13, 2014 9:49:12 AM UTC-4, Steven D'Aprano wrote: >> >> You may have missed my follow up post, where I said I had not noticed you >> were operating on a binary .doc file. >> >> If you're not willing or able to use a full-blown doc parser, say by >> controlling Word or LibreOffice, the other alternative is to do something >> quick and dirty that might work most of the time. Open a doc file, or >> multiple doc files, in a hex editor and *hopefully* you will be able to >> see chunks of human-readable text where you can identify how en-dashes >> and similar are stored. > > I created a .doc file and opened it with UltraEdit in binary (Hex) mode. What I see is that there are two characters, one for ndash and one for mdash, each a single byte long. 0x96 and 0x97. > So I tried this: fStr = re.sub(b'\0x96',b'-',fStr) > > that did nothing in my file. So I tried this: fStr = re.sub(b'0x97',b'-',fStr) > > which also did nothing. > So, for fun I also tried to just put these wildcards in my re.findall so I added |Part \0x96|Part \0x97 to no avail. > > Obviously 0x96 and 0x97 are NOT being interpreted in a re.findall or re.sub as hex byte values of 96 and 97 hexadecimal using my current syntax. > > So here's my question...if I want to replace all ndash or mdash values with regular '-' symbols using re.sub, what is the proper syntax to do so? > > Thanks! > 0x96 is a hexadecimal literal for an int. Within a string you need \x96 (it's \x for 2 hex digits, \u for 4 hex digits, \U for 8 hex digits). From ben at benfinney.id.au Tue May 13 18:55:33 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 14 May 2014 08:55:33 +1000 Subject: PEP 8 : Maximum line Length : References: <5372223c$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85iop98f16.fsf@benfinney.id.au> Steven D'Aprano writes: > On Tue, 13 May 2014 04:52:26 -0700, Rustom Mody wrote: > > > What this goes to show is that while 80 is ridiculously low by most > > displays today, > > Not for people who like to has two (or three, or four) windows side-by- > side. Or multiple views of the same document. There's also the fact that, while the capacity of monitors to display pixels has dramatically increased in recent decades, the capacity of human cognition to scan long lines of text has not increased at all in that time. The 80 character line limit is *not* driven by a limitation of computer technology; it is driven by a limitation of human cognition. For that reason, it remains relevant until human cognition in the general reading population improves. -- \ ?Give a man a fish, and you'll feed him for a day; give him a | `\ religion, and he'll starve to death while praying for a fish.? | _o__) ?Anonymous | Ben Finney From joseph.martinot-lagarde at m4x.org Tue May 13 19:14:04 2014 From: joseph.martinot-lagarde at m4x.org (Joseph Martinot-Lagarde) Date: Wed, 14 May 2014 01:14:04 +0200 Subject: How can this assert() ever trigger? In-Reply-To: <5371ec30$0$27133$e4fe514c@dreader35.news.xs4all.nl> References: <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> <5371ec30$0$27133$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <5372A73C.2050607@m4x.org> Le 13/05/2014 11:56, Albert van der Horst a ?crit : > In article , > Joseph Martinot-Lagarde wrote: >> Le 10/05/2014 17:24, Albert van der Horst a ?crit : >>> I have the following code for calculating the determinant of >>> a matrix. It works inasfar that it gives the same result as an >>> octave program on a same matrix. >>> >>> / ---------------------------------------------------------------- >>> >>> def determinant( mat ): > .. >>> result = lastr[jx] >>> assert(result<>0.) > ... >>> assert(result<>0.) >>> nom *= result # Compenstate for multiplying a row. > ... >>> assert(nom<>0.) > .. >>> >>> /----------------------------------------- >>> >>> Now on some matrices the assert triggers, meaning that nom is zero. >>> How can that ever happen? mon start out as 1. and gets multiplied >>> with a number that is asserted to be not zero. >>> >>> Any hints appreciated. >>> >>> Groetjes Albert >>> >> I know it's not the question, but if you want a replacement for octave >> did you try numpy (and scipy) ? The determinant would be computer faster >> and with less memory than with your function. > > I'm using several programming languages in a mix to solve Euler problems. > This is about learning how octave compares to python for a certain kind of > problem as anything. > The determinant program I had lying around, but it was infinite precision > with integer only arithmetic. Then I made a simple modification and got > mad because I didn't understand why it didn't work. > > I have used numpy and its det before, but I find it difficult to > remember how to create a matrix in numpy. This is the kind of thing > that is hard to find in the docs. Now I looked it up in my old > programs: you start a matrix with the zeroes() function. > > I expect the built in determinant of octave to be on a par with corresponding > python libraries. > >> >> --- > > Groetjes Albert > > > You can use numpy.zeros(), but you can also use the same list of lists that you use for your problem. Transform a list of lists into a numpy array: >>> np.asarray([[1, 2],[3, 4]]) array([[1, 2], [3, 4]]) Use a numpy function directly on a list of lists (works for must numpy functions): >>> np.linalg.det([[1, 2],[3, 4]]) -2.0000000000000004 More info on array creation: http://wiki.scipy.org/Tentative_NumPy_Tutorial#head-d3f8e5fe9b903f3c3b2a5c0dfceb60d71602cf93 --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com From en.pratibha at gmail.com Tue May 13 19:33:15 2014 From: en.pratibha at gmail.com (pratibha natani) Date: Tue, 13 May 2014 16:33:15 -0700 (PDT) Subject: httplib with NETRC authentication Message-ID: Hi, I am trying to establish http connection to a gerrit host using netrc authentication. I have a netrc file created with following entries: machine host1.com login name password pass I did a debug and saw that my netrc file is being read correctly. Also in the connection object(after sending request) a header got created with appropriate credentials: 'headers': {'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ='} Still I get 401,Unauthorized in response. Any help would be greatly appreciated! headers = headers or {} bare_host = host.partition(':')[0] auth = NETRC.authenticators(bare_host) if auth: headers.setdefault('Authorization', 'Basic %s' % ( base64.b64encode('%s:%s' % (auth[0], auth[2])))) print "inside auth 0 ", auth[0] print "inside auth 2 ", auth [2] if body: body = json.JSONEncoder().encode(body) headers.setdefault('Content-Type', 'application/json') conn = httplib.HTTPSConnection(host) conn.req_host = host conn.req_params = { 'url': '/a/%s' % path, 'method': reqtype, 'headers': headers, 'body': body, } conn.request(**conn.req_params) print "conn ", conn.__dict__ Thanks Pratibha From steve+comp.lang.python at pearwood.info Tue May 13 19:53:53 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 May 2014 23:53:53 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 13 May 2014 14:42:51 +0000, alister wrote: > On Tue, 13 May 2014 13:51:20 +0000, Grant Edwards wrote: > >> On 2014-05-13, Steven D'Aprano >> wrote: >>> On Tue, 13 May 2014 07:20:34 -0400, Roy Smith wrote: >>> >>>> ASCII *is* all I need. >>> >>> You've never needed to copyright something? Copyright ? Roy Smith >>> 2014... >> >> Bah. You don't need the little copyright symbol at all. The statement >> without the symbol has the exact same legal weight. > > > You do not need any statements at all, copyright is automaticly assigned > to anything you create (at least that is the case in UK Law) although > proving the creation date my be difficult. (1) In my lifetime, that wasn't always the case. Up until the 1970s or thereabouts, you had to explicitly register anything you wanted copyrighted, a much more sensible system which weeded out the meaningless copyrights on economically worthless content. If we still had that system, orphan works would be a lesser problem. With the current system, all of us here are technically violating copyright every time we reply to an email and quote more than a small percentage of it. Not to mention all the mirror sites that violate copyright by mirroring our posts in their entirety without permission. (Author's moral rights not to be misquoted or plagiarised are a different kettle of fish separate from their ownership rights over the work. That should be automatic.) (2) You don't have to just prove copyright. You also have to *identify* who the work is copyrighted by, and it needs to be an identifiable legal person (actual person or corporation), not necessarily the author. In the absence of a statement otherwise, copyright is assumed to be held by the author, but that's not always the case -- it might be a work for hire, or copyright might have been transferred to another person or entity. Or the author is unidentifiable. Hence the orphan work problem: it's presumed to be copyrighted, but since nobody knows who owns the copyright, there's no way to get permission to copy that work. It might as well be lost, even when the original is sitting right there in front of you mouldering away. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Tue May 13 20:02:54 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 May 2014 00:02:54 GMT Subject: Exception problem with module References: Message-ID: <5372b2ae$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 13 May 2014 16:59:46 +0000, Joseph L. Casale wrote: > I am working with a module that I am seeing some odd behavior. > > A module.foo builds a custom exception, module.foo.MyError, its done > right afaict. > > Another module, module.bar imports this and calls > bar.__setattr__('a_new_name', MyError). I see that you've solved your immediate problem, but you shouldn't call __setattr__ directly. That should actually be written setattr(bar, 'a_new_name', MyError) But really, since bar is (apparently) a module, and it is *bar itself* setting the attribute, the better way is a_new_name = MyError or even from module.foo import MyError as a_new_name -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Tue May 13 20:08:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 May 2014 10:08:57 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 14, 2014 at 9:53 AM, Steven D'Aprano wrote: > With the current system, all of us here are technically violating > copyright every time we reply to an email and quote more than a small > percentage of it. Oh wow... so when someone quotes heaps of text without trimming, and adding blank lines, we can complain that it's a copyright violation - reproducing our work with unauthorized modifications and without permission... I never thought of it like that. ChrisA From rosuav at gmail.com Tue May 13 20:11:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 May 2014 10:11:23 +1000 Subject: httplib with NETRC authentication In-Reply-To: References: Message-ID: On Wed, May 14, 2014 at 9:33 AM, pratibha natani wrote: > I am trying to establish http connection to a gerrit host using netrc authentication. I have a netrc file created with following entries: > machine host1.com login name password pass > > I did a debug and saw that my netrc file is being read correctly. Also in the connection object(after sending request) a header got created with appropriate credentials: > 'headers': {'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ='} > > Still I get 401,Unauthorized in response. Any help would be greatly appreciated! The obvious question is: What *does* work? Does it work when you use wget, or some other application? Then go and look at what that sends for its authentication headers. Tip: It won't be "Authorization". ChrisA From steve+comp.lang.python at pearwood.info Tue May 13 20:10:48 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 May 2014 00:10:48 GMT Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> Message-ID: <5372b488$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 13 May 2014 22:57:16 +0300, Marko Rauhamaa wrote: > Producing an effective JIT for Python seems like a formidable challenge > but not impossible in principle. Or in practice. http://pypy.org/ And it's predecessor: http://psyco.sourceforge.net/ -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Tue May 13 20:10:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 May 2014 00:10:59 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5372b493$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 13 May 2014 10:08:42 -0600, Ian Kelly wrote: > Because Python 3 presents stdin and stdout as text streams however, it > makes them more difficult to use with binary data, which is why Armin > sets up all that extra code to make sure his file objects are binary. What surprises me is how hard that is. Surely there's a simpler way to open stdin and stdout in binary mode? If not, there ought to be. -- Steven D'Aprano http://import-that.dreamwidth.org/ From greg.ewing at canterbury.ac.nz Tue May 13 20:24:55 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 14 May 2014 12:24:55 +1200 Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5372223c$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ben Finney wrote: > The 80 character line limit is *not* driven by a limitation of computer > technology; it is driven by a limitation of human cognition. For that > reason, it remains relevant until human cognition in the general reading > population improves. Another thing: Just because I may have 2048 pixes of horizontal space available on my monitor, that doesn't mean I want to devote all of them to displaying a single source file. I like to be able to put 2 or 3 source windows side by side, or have a web browser showing documentation alongside while I work, etc. While the limit doesn't have to be exactly 80 chars, something not too much bigger is a good idea for a variety of reasons. -- Greg From roy at panix.com Tue May 13 20:51:00 2014 From: roy at panix.com (Roy Smith) Date: Tue, 13 May 2014 20:51:00 -0400 Subject: PEP 8 : Maximum line Length : References: Message-ID: In article , Ben Finney wrote: > Roy Smith writes: > > > > p = Subprocess.Popen(shlex.split(cmd), > > > stdout=subprocess.PIPE, > > > stderr=subprocess.PIPE) > > That is PEP 8 conformant, but I find it hurts maintainability: it is far > too much indentation. Horizontal space is costly, because so much > indentation severely limits the length of names etc. that you can use on > the continuation lines. It only does that if you limit yourself to 80 character lines. From ben at benfinney.id.au Tue May 13 21:01:25 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 14 May 2014 11:01:25 +1000 Subject: [OT] Copyright statements and why they can be useful (was: Everything you did not want to know about Unicode in Python 3) References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85egzx897e.fsf_-_@benfinney.id.au> Steven D'Aprano writes: > On Tue, 13 May 2014 14:42:51 +0000, alister wrote: > > > You do not need any statements at all, copyright is automaticly > > assigned to anything you create (at least that is the case in UK > > Law) although proving the creation date my be difficult. > > (1) In my lifetime, that wasn't always the case. Up until the 1970s or > thereabouts, you had to explicitly register anything you wanted > copyrighted [?] > (2) You don't have to just prove copyright. You also have to *identify* > who the work is copyrighted by, and it needs to be an identifiable legal > person (actual person or corporation), not necessarily the author. [?] (3) In all jurisdictions where copyright exists, the copyright holder nominally has monopoly on the work for only a fixed term, starting from the date of publication. To know when the copyright will expire, it's essential to know the date from which copyright starts; this is best done explicitly in the copyright statement. I say ?nominally?, because another alarming and unilateral trend is to dramatically extend the nominally fixed term, and to strong-arm national governments with terade deals to maximise the copyright term around the world. The effect, as Lawrence Lessig points out: The meaning of this pattern is absolutely clear to those who pay to produce it. The meaning is: No one can do to the Disney Corporation what Walt Disney did to the Brothers Grimm. That though we had a culture where people could take and build upon what went before, that's over. There is no such thing as the public domain in the minds of those who have produced these 11 extensions these last 40 years because now culture is owned. Or, less poetically, since the term of copyright is only nominally fixed, and in practice just keeps getting extended by newly-lobbied legislation every twenty years or so, the copyright maximalists have de facto instituted ?perpetual copyright on the installment plan? . Nevertheless, copyright on works created this century will in principle expire at some date in the future; and to know when that date will be, we need to know when the copyright began. Hence the need for explicit copyright statements saying the date of publication. -- \ ?[T]he great menace to progress is not ignorance but the | `\ illusion of knowledge.? ?Daniel J. Boorstin, historian, | _o__) 1914?2004 | Ben Finney From ethan at stoneleaf.us Tue May 13 20:53:31 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 13 May 2014 17:53:31 -0700 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <5372b493$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b493$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5372BE8B.3070302@stoneleaf.us> On 05/13/2014 05:10 PM, Steven D'Aprano wrote: > On Tue, 13 May 2014 10:08:42 -0600, Ian Kelly wrote: > >> Because Python 3 presents stdin and stdout as text streams however, it >> makes them more difficult to use with binary data, which is why Armin >> sets up all that extra code to make sure his file objects are binary. > > What surprises me is how hard that is. Surely there's a simpler way to > open stdin and stdout in binary mode? If not, there ought to be. Somebody already posted this: https://docs.python.org/3/library/sys.html#sys.stdin which talks about .detach(). -- ~Ethan~ From d at davea.name Tue May 13 22:09:47 2014 From: d at davea.name (Dave Angel) Date: Tue, 13 May 2014 22:09:47 -0400 Subject: Need help to write data onto an XML file after reading data from another xml file In-Reply-To: <2c8cb313-50f6-439b-a979-bd320a2c7b2c@googlegroups.com> References: <2c8cb313-50f6-439b-a979-bd320a2c7b2c@googlegroups.com> Message-ID: <5372D06B.9000303@davea.name> On 05/13/2014 10:31 AM, varun7rs at gmail.com wrote: > Hello Users, > > I am in dire need of your help. I have been working on this code for quite some time and it is making me restless. All I am trying to do is, > > 1. Read data from an xml file. Source: http://sndlib.zib.de/coredata.download.action?objectName=germany50&format=xml&objectType=network > > 2. The data I'm concerned about is the node ID, co-ordinates, capacity of the links, source and destination names. > > 3. I'm creating a topology with this information and the topology is same as the one given in the xml file. But, I'd like to add a few extra parameters and demands which I have mentioned in the .py file. > > 4. This is where I am faltering. I am just not able to create this topology. The file has also become really messy as I tried a lot of weird stuff and commented it out as it did not work. > > 5. I'll attach the relevant files and I'd like to write the output onto a new xml file. > > I'd be glad if any of you could help me out. I'm indebted to you guys. Oh I was not aware that I could attach files. Anyways, here is the link to the files I'm working on > https://www.dropbox.com/sh/i8h321y7c9c60vt/AADzDj7oOM8YU76Ww6W4LIPYa > > Thanks a lot everyone > Try to include the relevant information in your message. Many people cannot, or will not, follow links. Further, those links are frequently transient (such as your dropbox one), which means the message thread becomes historically useless. So a link to point to a particular library is useful and practical, one to your source code is not. And many readers cannot see attachments or html formatted messages. -- DaveA From leonardo.petry.br at gmail.com Tue May 13 23:38:32 2014 From: leonardo.petry.br at gmail.com (Leonardo Petry) Date: Tue, 13 May 2014 20:38:32 -0700 (PDT) Subject: New to Python. For in loops curiosity Message-ID: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> Hi All, So I am starting with python and I have been working on some simple exercises. Here is something I found curious about python loops This loop run each character in a string def avoids(word,letters): flag = True for letter in letters: if(letter in word): flag = False return flag The loop below (at the bottom) runs each line of the file fin = open('wordplay.txt'); user_input = raw_input('Enter some characters: ') count = 0 for line in fin: word = line.strip() if(avoids(word, user_input)): count += 1; This is just too convenient. Basically my question is: Why is python not treating the contents of wordplay.txt as one long string and looping each character? Any comment is greatly appreciate. Thanks From ian.g.kelly at gmail.com Tue May 13 23:49:04 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 13 May 2014 21:49:04 -0600 Subject: New to Python. For in loops curiosity In-Reply-To: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> References: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> Message-ID: On Tue, May 13, 2014 at 9:38 PM, Leonardo Petry wrote: > The loop below (at the bottom) runs each line of the file > > fin = open('wordplay.txt'); > user_input = raw_input('Enter some characters: ') > count = 0 > for line in fin: > word = line.strip() > if(avoids(word, user_input)): > count += 1; > > This is just too convenient. > Basically my question is: Why is python not treating the contents of wordplay.txt as one long string and looping each character? Because the iterator for file-like objects iterates over lines, not characters. From gordon at panix.com Tue May 13 23:46:30 2014 From: gordon at panix.com (John Gordon) Date: Wed, 14 May 2014 03:46:30 +0000 (UTC) Subject: New to Python. For in loops curiosity References: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> Message-ID: In <2f08e970-1334-4e7f-ba84-14869708a73b at googlegroups.com> Leonardo Petry writes: > fin = open('wordplay.txt'); > user_input = raw_input('Enter some characters: ') > count = 0 > for line in fin: > word = line.strip() > if(avoids(word, user_input)): > count += 1; > This is just too convenient. > Basically my question is: Why is python not treating the contents of > wordplay.txt as one long string and looping each character? > Any comment is greatly appreciate. Thanks Your code is not treating the contents of wordplay.txt as one long string because 'for line in fin:' tells it to read line-by-line. If you want to read the entire contents, use the read() method: file_content = fin.read() -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From rustompmody at gmail.com Tue May 13 23:48:13 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 13 May 2014 20:48:13 -0700 (PDT) Subject: New to Python. For in loops curiosity In-Reply-To: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> References: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> Message-ID: On Wednesday, May 14, 2014 9:08:32 AM UTC+5:30, Leonardo Petry wrote: > > This is just too convenient. > > Basically my question is: Why is python not treating the contents of wordplay.txt as one long string and looping each character? Did you mean convenient or inconvenient? Anyways... Maybe you want the read method? https://docs.python.org/2/tutorial/inputoutput.html#methods-of-file-objects From ian.g.kelly at gmail.com Tue May 13 23:43:34 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 13 May 2014 21:43:34 -0600 Subject: Fortran In-Reply-To: <5372b488$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> <5372b488$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 13, 2014 at 6:10 PM, Steven D'Aprano wrote: > On Tue, 13 May 2014 22:57:16 +0300, Marko Rauhamaa wrote: > >> Producing an effective JIT for Python seems like a formidable challenge >> but not impossible in principle. > > Or in practice. > > http://pypy.org/ > > And it's predecessor: http://psyco.sourceforge.net/ Also numba, which is reminiscent of psyco, but with more features and Python 3 support. From ben at benfinney.id.au Wed May 14 00:03:08 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 14 May 2014 14:03:08 +1000 Subject: New to Python. For in loops curiosity References: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> Message-ID: <85a9al80sj.fsf@benfinney.id.au> Leonardo Petry writes: > So I am starting with python and I have been working on some simple > exercises. You are welcome here. Congratulations on starting with Python! You may also be interested to know there is also a separate forum dedicated to tutoring beginners in Python. > Here is something I found curious about python loops > > This loop run each character in a string > > def avoids(word,letters): > flag = True > for letter in letters: > if(letter in word): > flag = False > return flag You should avoid using U+0009 TAB characters for indentation, since they render inconsistently and can easily result in invisible differences in changed code. Instead, use four-column indentation with space (U+0020 SPACE) characters. > The loop below (at the bottom) runs each line of the file > > fin = open('wordplay.txt'); > user_input = raw_input('Enter some characters: ') > count = 0 > for line in fin: > word = line.strip() > if(avoids(word, user_input)): > count += 1; > > This is just too convenient. Is that a complaint, or shock at how easy it is? :-) > Basically my question is: Why is python not treating the contents of > wordplay.txt as one long string and looping each character? Because the types of the objects are different; different types define different behaviour. Indeed, that is almost the definition of what a type is. A text string object supports iteration by returning each character . A file object supports iteration by returning each line from the stream . -- \ ?Our products just aren't engineered for security.? ?Brian | `\ Valentine, senior vice-president of Microsoft Windows | _o__) development, 2002 | Ben Finney From marko at pacujo.net Wed May 14 00:35:35 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 14 May 2014 07:35:35 +0300 Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> <5372b488$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87tx8tnfjc.fsf@elektro.pacujo.net> Steven D'Aprano : > On Tue, 13 May 2014 22:57:16 +0300, Marko Rauhamaa wrote: > >> Producing an effective JIT for Python seems like a formidable challenge >> but not impossible in principle. > > Or in practice. > > http://pypy.org/ I'm having a hard time finding information on how well it performs wrt Java, for example. Did PyPy truly find the Philosophers' Stone? Marko From wxjmfauth at gmail.com Wed May 14 02:12:40 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 13 May 2014 23:12:40 -0700 (PDT) Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: References: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> <537222d8$0$29980$c3e8da3$5496439d@news.astraweb.com> <63051425-ec42-45b4-8a9e-53001625f32a@googlegroups.com> Message-ID: <220e9313-4887-446f-bf30-81972dfe2c2e@googlegroups.com> Le mardi 13 mai 2014 22:26:51 UTC+2, MRAB a ?crit : > On 2014-05-13 20:01, scottcabit at gmail.com wrote: > > > On Tuesday, May 13, 2014 9:49:12 AM UTC-4, Steven D'Aprano wrote: > > >> > > >> You may have missed my follow up post, where I said I had not noticed you > > >> were operating on a binary .doc file. > > >> > > >> If you're not willing or able to use a full-blown doc parser, say by > > >> controlling Word or LibreOffice, the other alternative is to do something > > >> quick and dirty that might work most of the time. Open a doc file, or > > >> multiple doc files, in a hex editor and *hopefully* you will be able to > > >> see chunks of human-readable text where you can identify how en-dashes > > >> and similar are stored. > > > > > > I created a .doc file and opened it with UltraEdit in binary (Hex) mode. What I see is that there are two characters, one for ndash and one for mdash, each a single byte long. 0x96 and 0x97. > > > So I tried this: fStr = re.sub(b'\0x96',b'-',fStr) > > > > > > that did nothing in my file. So I tried this: fStr = re.sub(b'0x97',b'-',fStr) > > > > > > which also did nothing. > > > So, for fun I also tried to just put these wildcards in my re.findall so I added |Part \0x96|Part \0x97 to no avail. > > > > > > Obviously 0x96 and 0x97 are NOT being interpreted in a re.findall or re.sub as hex byte values of 96 and 97 hexadecimal using my current syntax. > > > > > > So here's my question...if I want to replace all ndash or mdash values with regular '-' symbols using re.sub, what is the proper syntax to do so? > > > > > > Thanks! > > > > > 0x96 is a hexadecimal literal for an int. Within a string you need \x96 > > (it's \x for 2 hex digits, \u for 4 hex digits, \U for 8 hex digits). ---------------- >>> b'0x61' == b'0x61' True >>> b'0x96' == b'\x96' False - Python and the coding of characters is an unbelievable mess. - Unicode a joke. - I can make Python failing with any valid sequence of chars I wish. - There is a difference between "look, my code work with my chars" and "this code is safely working with any chars". jmf From varun7rs at gmail.com Wed May 14 02:49:06 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Tue, 13 May 2014 23:49:06 -0700 (PDT) Subject: Need help to write data onto an XML file after reading data from another xml file In-Reply-To: <2c8cb313-50f6-439b-a979-bd320a2c7b2c@googlegroups.com> References: <2c8cb313-50f6-439b-a979-bd320a2c7b2c@googlegroups.com> Message-ID: I try to add an edge with the source id and destination id over a loop but this is the error I am getting. And the range for the for addEdge is something I have no clue about. python export.py --output topology.xml --xml germany50.xml Traceback (most recent call last): File "export.py", line 239, in main(sys.argv[1:]) File "export.py", line 234, in main network.addEdge( PHY_LINKS( j , sourcen, destnn, sid, did, cap_bdw) ) File "/home/srva/Approach_Read.py", line 89, in addEdge self.nodes[ edge.SourceID ].addInEdge( edge ) IndexError: list index out of range Thank You From steve at pearwood.info Wed May 14 02:58:07 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 14 May 2014 06:58:07 GMT Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> <5372b488$0$29977$c3e8da3$5496439d@news.astraweb.com> <87tx8tnfjc.fsf@elektro.pacujo.net> Message-ID: <537313fe$0$11109$c3e8da3@news.astraweb.com> On Wed, 14 May 2014 07:35:35 +0300, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Tue, 13 May 2014 22:57:16 +0300, Marko Rauhamaa wrote: >> >>> Producing an effective JIT for Python seems like a formidable >>> challenge but not impossible in principle. >> >> Or in practice. >> >> http://pypy.org/ > > I'm having a hard time finding information on how well it performs wrt > Java, for example. Did PyPy truly find the Philosophers' Stone? I don't understand your question. PyPy doesn't do anything with Java. In principle you could use PyPy's underlying toolchain to build a Java compiler, similar to the Python, Prolog and PHP compilers already made, but nobody has done so for Java so far as I know. http://morepypy.blogspot.com.au/2012/07/hello-everyone.html Or do you mean, how does PyPy compare with ? I don't know. There are some old benchmarks here: http://attractivechaos.wordpress.com/2011/04/25/my-programming-language- benchmarks-plb/ but the person doing the benchmarks is by his own admission not a skilled Python programmer. -- Steven From wxjmfauth at gmail.com Wed May 14 03:00:25 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 14 May 2014 00:00:25 -0700 (PDT) Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <09bacccb-5a82-4c3d-93ee-ec9dee1a2588@googlegroups.com> Le mardi 13 mai 2014 10:08:45 UTC+2, Johannes Bauer a ?crit?: > On 13.05.2014 03:18, Steven D'Aprano wrote: > > > > > Armin Ronacher is an extremely experienced and knowledgeable Python > > > developer, and a Python core developer. He might be wrong, but he's not > > > *obviously* wrong. > > > > He's correct about file name encodings. Which can be fixed really easily > > wihtout messing everything up (sys.argv binary variant, open accepting > > binary filenames). But that he suggests that Go would be superior: > > > > > Which uses an even simpler model than Python 2: everything is a byte string. The assumed encoding is UTF-8. End of the story. > > > > Is just a horrible idea. An obviously horrible idea, too. > > > > Having dealt with the UTF-8 problems on Python2 I can safely say that I > > never, never ever want to go back to that freaky hell. If I deal with > > strings, I want to be able to sanely manipulate them and I want to be > > sure that after manipulation they're still valid strings. Manipulating > > the bytes representation of unicode data just doesn't work. > > > > And I'm very very glad that some people felt the same way and > > implemented a sane, consistent way of dealing with Unicode in Python3. > > It's one of the reasons why I switched to Py3 very early and I love it. > > > > Cheers, > > Johannes > > > > -- > > >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > > > Zumindest nicht ?ffentlich! > > Ah, der neueste und bis heute genialste Streich unsere gro?en > > Kosmologen: Die Geheim-Vorhersage. > > - Karl Kaos ?ber R?diger Thomas in dsa =========== A Rob 'Commander' Pike will never put utf16 and ebcdic in the same basket, when discussing coding of characters. jmf From flebber.crue at gmail.com Wed May 14 03:27:09 2014 From: flebber.crue at gmail.com (flebber) Date: Wed, 14 May 2014 00:27:09 -0700 (PDT) Subject: SQLAlchemy - web framework ? In-Reply-To: References: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> Message-ID: <718e12ee-8f6c-4d21-8e98-14355c154470@googlegroups.com> One of the main parts that is tripping myself up is that I need to consistently import xml files into my database. Looking to find the best support and methodologies to do this, that is one of the reasons I am looking at SqlAlchemy. Sayth From ben at benfinney.id.au Wed May 14 03:45:05 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 14 May 2014 17:45:05 +1000 Subject: SQLAlchemy - web framework ? References: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> <718e12ee-8f6c-4d21-8e98-14355c154470@googlegroups.com> Message-ID: <85egzw9532.fsf@benfinney.id.au> flebber writes: > One of the main parts that is tripping myself up is that I need to > consistently import xml files into my database. XML documents represent a hierarchical tree of data. Relational databases are not good at representing hierarchical documents. So I don't know what you mean by ?consistently import xml files into my database?. What are you expecting the result to be? You won't have sensible relational records as a result. At best, you'll have XML blobs in single SQL fields. > Looking to find the best support and methodologies to do this, that is > one of the reasons I am looking at SqlAlchemy. I've asked you about using Django with SQLAlchemy; it's not clear why you don't think that is suitable. So I have the same question: What makes you think a database API is going to solve the problem, and what makes you think SQLAlchemy in particlar is the right solution? More generally: You appear to have already decided what the solution is, without making clear to us what the problem is. Advice is going to be mis-matched until you tell us more about what problem you're trying to solve. -- \ ?The Way to see by Faith is to shut the Eye of Reason.? | `\ ?Benjamin Franklin | _o__) | Ben Finney From marko at pacujo.net Wed May 14 04:46:49 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 14 May 2014 11:46:49 +0300 Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> <5372b488$0$29977$c3e8da3$5496439d@news.astraweb.com> <87tx8tnfjc.fsf@elektro.pacujo.net> <537313fe$0$11109$c3e8da3@news.astraweb.com> Message-ID: <87wqdobvd2.fsf@elektro.pacujo.net> Steven D'Aprano : > On Wed, 14 May 2014 07:35:35 +0300, Marko Rauhamaa wrote: >> I'm having a hard time finding information on how well it performs wrt >> Java, for example. Did PyPy truly find the Philosophers' Stone? > > [...] do you mean, how does PyPy compare with compiler here? I don't know. There are some old benchmarks here: > > http://attractivechaos.wordpress.com/2011/04/25/my-programming-language- > benchmarks-plb/ > > but the person doing the benchmarks is by his own admission not a > skilled Python programmer. That's what I'm after. The answer from the page is: Java 1.7 2.6 67.1 6.8 13.4 6.7 314.8 PyPy 19.5 8.5 84.1 4.0 7.3 12.3 236.0 None of the benchmark tests seems all that relevant, but the one that comes closest to being interesting is Column 1: Sudoku. There, Java is an order of magnitude faster (1.7 s vs 19.5 s). When Python equals Java performance, Java will lose its raison-d'?tre. Marko From th982a at googlemail.com Wed May 14 04:36:11 2014 From: th982a at googlemail.com (Tamer Higazi) Date: Wed, 14 May 2014 10:36:11 +0200 Subject: problems decoding json objects Message-ID: <53732AFB.8080204@googlemail.com> Hi people! My JSON String: from json.decoder import JSONDecoder myjs = '{"AVName":"Tamer","ANName":"Higazi","AAnschrift":"Bauerngasse","AHausnr":"1","APLZ":"55116","AOrt":"Mainz"},{"KontaktTel":["01234","11223344"],{"ZahlungsArt":"0"},{"ZugangsDaten":["tamer.higazi at nomail.com","mypass"]}' If I try to decode it, with: JSD = JSONDecoder() rsx = JSD.decode(myjs) I get this error message: >>> JSD.decode(myjs) Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.7/json/decoder.py", line 368, in decode raise ValueError(errmsg("Extra data", s, end, len(s))) ValueError: Extra data: line 1 column 108 - line 1 column 220 (char 107 - 219) How do I solve this problem ?! For any help, thanks Tamer From ben at benfinney.id.au Wed May 14 05:20:13 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 14 May 2014 19:20:13 +1000 Subject: problems decoding json objects References: <53732AFB.8080204@googlemail.com> Message-ID: <85a9ak90oi.fsf@benfinney.id.au> Tamer Higazi writes: > myjs = > '{"AVName":"Tamer","ANName":"Higazi","AAnschrift":"Bauerngasse","AHausnr":"1","APLZ":"55116","AOrt":"Mainz"},{"KontaktTel":["01234","11223344"],{"ZahlungsArt":"0"},{"ZugangsDaten":["tamer.higazi at nomail.com","mypass"]}' That's not a valid JSON document. See . You appear to have three documents in a row, separated by commas. Or one malformed document, missing its enclosure. Or something else; that's the trouble with a malformed document, we don't know what it should be. > I get this error message: > > >>> JSD.decode(myjs) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python2.7/json/decoder.py", line 368, in decode > raise ValueError(errmsg("Extra data", s, end, len(s))) > ValueError: Extra data: line 1 column 108 - line 1 column 220 (char 107 > - 219) Right. The document ends there, and the rest of the string is trailing garbage, which is an error. > How do I solve this problem ?! Fix the document. Where did it come from? Best, don't put it directly in the Python source code as a string. Ideally, have it as a distinct file, which you can examine in a text editor with JSON highlighting; and run separately through a JSON parser for correctness. -- \ ?Isn't it enough to see that a garden is beautiful without | `\ having to believe that there are fairies at the bottom of it | _o__) too?? ?Douglas Adams | Ben Finney From jcasale at activenetwerx.com Wed May 14 05:21:50 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Wed, 14 May 2014 09:21:50 +0000 Subject: Exception problem with module In-Reply-To: <5372b2ae$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5372b2ae$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <404c9a5d586c4911b5ac341232209822@exch.activenetwerx.com> > I see that you've solved your immediate problem, but you shouldn't call > __setattr__ directly. That should actually be written > > setattr(bar, 'a_new_name', MyError) > > But really, since bar is (apparently) a module, and it is *bar itself* > setting the attribute, the better way is > > a_new_name = MyError > > or even > > from module.foo import MyError as a_new_name Well I am not sure what advantage this has for the user, not my code as I don't advocate the import to begin with it, its fine spelled as it was from where it was... I'll look back at this and see if that resolves the issue as it had manifested. jlc From skip at pobox.com Wed May 14 06:39:15 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 14 May 2014 05:39:15 -0500 Subject: problems decoding json objects In-Reply-To: <53732AFB.8080204@googlemail.com> References: <53732AFB.8080204@googlemail.com> Message-ID: On Wed, May 14, 2014 at 3:36 AM, Tamer Higazi wrote: > myjs = > '{"AVName":"Tamer","ANName":"Higazi","AAnschrift":"Bauerngasse","AHausnr":"1","APLZ":"55116","AOrt":"Mainz"},{"KontaktTel":["01234","11223344"],{"ZahlungsArt":"0"},{"ZugangsDaten":["tamer.higazi at nomail.com","mypass"]}' Following up on Ben's comment, what did you expect? With my Python hat on, I'd say you've got a string representing a tuple of four dictionaries, though my human brain can see past the missing '}' which is supposed to close the second dict. If you add that, it's still not valid JSON (I guess JSON doesn't have tuples). This stuff isn't meant to be typed by humans. Instead computers are supposed to barf it out and munch on it. As Ben indicated, putting it in a string is pointless. Might as well just define the dictionaries yourself. not-gonna-mention-eval-ly, y'rs Skip From ben at benfinney.id.au Wed May 14 06:46:36 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 14 May 2014 20:46:36 +1000 Subject: problems decoding json objects References: <53732AFB.8080204@googlemail.com> Message-ID: <8538gc8woj.fsf@benfinney.id.au> Ben Finney writes: > Tamer Higazi writes: > > How do I solve this problem ?! > > Fix the document. Where did it come from? If you're the one typing raw JSON into your program: Fix that. Don't type raw JSON. JSON is an object serialisation format; it's foolish to type it yourself. You should only be generating it from a known-debugged JSON library, or reading it as input from some other generator. If you want to define an object in a Python literal, type Python code. Skip Montanaro writes: > This stuff isn't meant to be typed by humans. Instead computers are > supposed to barf it out and munch on it. As Ben indicated, putting it > in a string is pointless. It didn't even occur to me that the programmer would have typed this in manually. Good catch, Skip. -- \ ?Why doesn't Python warn that it's not 100% perfect? Are people | `\ just supposed to ?know? this, magically?? ?Mitya Sirenef, | _o__) comp.lang.python, 2012-12-27 | Ben Finney From antoon.pardon at rece.vub.ac.be Wed May 14 07:23:46 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 14 May 2014 13:23:46 +0200 Subject: python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly Message-ID: <53735242.2010406@rece.vub.ac.be> This is the code I run (python 3.3) host = ... user = ... passwd = ... from ftplib import FTP ftp = FTP(host, user, passwd) ftp.mkd(b'NewDir') ftp.rmd(b'NewDir') This is the traceback Traceback (most recent call last): File "ftp-problem", line 9, in ftp.mkd(b'NewDir') File "/usr/lib/python3.3/ftplib.py", line 612, in mkd resp = self.voidcmd('MKD ' + dirname) TypeError: Can't convert 'bytes' object to str implicitly The problem is that I do something like this in a backup program. I don't know the locales that other people use. So I manipulate all file and directory names as bytes. Am I doing something wrong? -- Antoon Pardon From roy at panix.com Wed May 14 07:38:26 2014 From: roy at panix.com (Roy Smith) Date: Wed, 14 May 2014 07:38:26 -0400 Subject: New to Python. For in loops curiosity References: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> Message-ID: In article <2f08e970-1334-4e7f-ba84-14869708a73b at googlegroups.com>, Leonardo Petry wrote: > Basically my question is: Why is python not treating the contents of > [a file] as one long string and looping each character? Because whoever designed the original file object decided that the right way to iterate over a file is line by line. In Python (although, at this level of explanation, I could be describing pretty much any language which has iterators), there is an iterator protocol which implements two ideas: 1) There's a method to call to get the next item. 2) There's a way for that method to signal that you've reached the end. Exactly what "the next item" means is up to whoever implements the iterator. In this case, it was decided that the most convenient thing would be for "item" to mean "line". If you really want to iterate over a file character-by-character, it's easy enough to write an adapter. Something like this (untested): def getchar(f): for line in f: for c in line: yield c Of course, if the native file iterator was character-by-character, then if you wanted it line-by-line, you would have to write the inverse, a function which accumulates characters until it sees a newline, and then returns that. Neither one is fundamentally better, or more correct than the other. One may just be more convenient for a particular use case. From roy at panix.com Wed May 14 07:43:33 2014 From: roy at panix.com (Roy Smith) Date: Wed, 14 May 2014 07:43:33 -0400 Subject: problems decoding json objects References: <53732AFB.8080204@googlemail.com> Message-ID: In article , Skip Montanaro wrote: > I guess JSON doesn't have tuples JSON has sequences, which both Python lists and tuples serialize as (losing the distinction between them). In the other direction, JSON sequences typically unpack as lists, but I think that's just convention. There might be json packages which unpack them as tuples. From denismfmcmahon at gmail.com Wed May 14 08:04:12 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 14 May 2014 12:04:12 +0000 (UTC) Subject: problems decoding json objects References: Message-ID: On Wed, 14 May 2014 10:36:11 +0200, Tamer Higazi wrote: > Hi people! > > My JSON String: > > from json.decoder import JSONDecoder > myjs = > '{"AVName":"Tamer","ANName":"Higazi","AAnschrift":"Bauerngasse","AHausnr":"1","APLZ":"55116","AOrt":"Mainz"}, {"KontaktTel":["01234","11223344"],{"ZahlungsArt":"0"},{"ZugangsDaten": ["tamer.higazi at nomail.com","mypass"]}' > > If I try to decode it, with: > > JSD = JSONDecoder() > rsx = JSD.decode(myjs) > > I get this error message: > >>>> JSD.decode(myjs) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python2.7/json/decoder.py", line 368, in decode > raise ValueError(errmsg("Extra data", s, end, len(s))) > ValueError: Extra data: line 1 column 108 - line 1 column 220 (char 107 > - 219) > How do I solve this problem ?! > For any help, thanks Try doing a manual inspection of your json string. It appears to contain several objects, but they're not contained within an outer object or an array. If you want a list of data objects, you need to put [] round them. If you want them to be dictionary elements, you need to wrap them with {} and put identifiers in. If you want a single dictionary, you need to remove most of the { and }. In addition, one of the objects doesn't appear to be terminated. {"AVName":"Tamer","ANName":"Higazi","AAnschrift":"Bauerngasse","AHausnr":"1","APLZ":"55116","AOrt":"Mainz"}, {"KontaktTel":["01234","11223344"] ** missing '}' ??? ** , {"ZahlungsArt":"0"}, {"ZugangsDaten":["tamer.higazi at nomail.com","mypass"]} Depending how I "correct" the json string, I can create different values for rsx: (1) a list of 4 dictionaries: $ ./jsonerr.py [{u'APLZ': u'55116', u'ANName': u'Higazi', u'AHausnr': u'1', u'AVName': u'Tamer', u'AAnschrift': u'Bauerngasse', u'AOrt': u'Mainz'}, {u'KontaktTel': [u'01234', u'11223344']}, {u'ZahlungsArt': u'0'}, {u'ZugangsDaten': [u'tamer.higazi at nomail.com', u'mypass']}] (2) a single dictionary: $ ./jsonerr.py {u'APLZ': u'55116', u'KontaktTel': [u'01234', u'11223344'], u'ZugangsDaten': [u'tamer.higazi at nomail.com', u'mypass'], u'ANName': u'Higazi', u'AHausnr': u'1', u'AVName': u'Tamer', u'AAnschrift': u'Bauerngasse', u'AOrt': u'Mainz', u'ZahlungsArt': u'0'} (3) an object with 4 subsidiary objects: $ ./jsonerr.py {u'Misc data': {u'ZahlungsArt': u'0'}, u'Name and Addr': {u'APLZ': u'55116', u'ANName': u'Higazi', u'AHausnr': u'1', u'AVName': u'Tamer', u'AAnschrift': u'Bauerngasse', u'AOrt': u'Mainz'}, u'Login info': {u'ZugangsDaten': [u'tamer.higazi at nomail.com', u'mypass']}, u'Telephones': {u'KontaktTel': [u'01234', u'11223344']}} but I have no way of knowing which it is you require. -- Denis McMahon, denismfmcmahon at gmail.com From th982a at googlemail.com Wed May 14 08:23:25 2014 From: th982a at googlemail.com (Tamer Higazi) Date: Wed, 14 May 2014 14:23:25 +0200 Subject: problems decoding json objects In-Reply-To: <85a9ak90oi.fsf@benfinney.id.au> References: <53732AFB.8080204@googlemail.com> <85a9ak90oi.fsf@benfinney.id.au> Message-ID: <5373603D.9000803@googlemail.com> You are right! It was all alone my mistake which I recently figured out. Thanks for helping me. Tamer Am 14.05.2014 11:20, schrieb Ben Finney: > Tamer Higazi writes: > > That's not a valid JSON document. See . > From alister.nospam.ware at ntlworld.com Wed May 14 08:38:38 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 14 May 2014 12:38:38 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 13 May 2014 10:08:42 -0600, Ian Kelly wrote: > On Tue, May 13, 2014 at 5:19 AM, alister > wrote: >> I am only an amateur python coder which is why I asked if I am missing >> something >> >> I could not see any reason to be using the shutil module if all that >> the programm is doing is opening a file, reading it & then printing it. >> >> is it python that causes the issue, the shutil module or just the OS >> not liking the data it is being sent? >> >> an explanation of why this approach is taken would be much appreciated. > > No, that part is perfectly fine. This is exactly what the shutil module > is meant for: providing shell-like operations. Although in this case > the copyfileobj function is quite simple (have yourself a look at the > source -- it just reads from one file and writes to the other in a > loop), in general the Pythonic thing is to avoid reinventing the wheel. > > And since it's so simple, it shouldn't be hard to see that the use of > the shutil module has nothing to do with the Unicode woes here. The > crux of the issue is that a general-purpose command like cat typically > can't know the encoding of its input and can't assume anything about it. > In fact, there may not even be an encoding; cat can be used with binary > data. The only non-destructive approach then is to copy the binary data > straight from the source to the destination with no decoding steps at > all, and trust the user to ensure that the destination will be able to > accommodate the source encoding. Because Python 3 presents stdin and > stdout as text streams however, it makes them more difficult to use with > binary data, which is why Armin sets up all that extra code to make sure > his file objects are binary. I think I understand that in which case I owe Armin an apology, this certainly sounds like a failing in pythons handling of stdout -- Get it up, keep it up... LINUX: Viagra for the PC. -- Chris Abbey From alister.nospam.ware at ntlworld.com Wed May 14 08:42:41 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 14 May 2014 12:42:41 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5xJcv.77901$dT1.66255@fx12.am4> On Wed, 14 May 2014 10:08:57 +1000, Chris Angelico wrote: > On Wed, May 14, 2014 at 9:53 AM, Steven D'Aprano > wrote: >> With the current system, all of us here are technically violating >> copyright every time we reply to an email and quote more than a small >> percentage of it. > > Oh wow... so when someone quotes heaps of text without trimming, and > adding blank lines, we can complain that it's a copyright violation - > reproducing our work with unauthorized modifications and without > permission... > > I never thought of it like that. > > ChrisA I think I could make a very strong case that anything sent to a public forum with the intention of being broadcast has been placed into the public domain by this action. -- Work expands to fill the time available. -- Cyril Northcote Parkinson, "The Economist", 1955 From rosuav at gmail.com Wed May 14 08:52:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 May 2014 22:52:25 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <5xJcv.77901$dT1.66255@fx12.am4> References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> Message-ID: On Wed, May 14, 2014 at 10:42 PM, alister wrote: > On Wed, 14 May 2014 10:08:57 +1000, Chris Angelico wrote: > >> On Wed, May 14, 2014 at 9:53 AM, Steven D'Aprano >> wrote: >>> With the current system, all of us here are technically violating >>> copyright every time we reply to an email and quote more than a small >>> percentage of it. >> >> Oh wow... so when someone quotes heaps of text without trimming, and >> adding blank lines, we can complain that it's a copyright violation - >> reproducing our work with unauthorized modifications and without >> permission... >> >> I never thought of it like that. >> >> ChrisA > > I think I could make a very strong case that anything sent to a public > forum with the intention of being broadcast has been placed into the > public domain by this action. I don't think so. One can reasonably assume that anything sent to a public forum is permissible to read, and to copy verbatim (although there may be "presumed limits" on the copying, but probably not with python-list). But if I quote your text and edit it, then you would rightly complain, which is not the case with public domain text. The question is whether or not it's fair to try to scare people with that when they repeatedly use buggy software that inserts blank lines everywhere :) In case it's not obvious, I am NOT seriously contemplating pursuing anything like this legally. It's just funny to contemplate. ChrisA From davea at davea.name Tue May 13 21:56:23 2014 From: davea at davea.name (Dave Angel) Date: Tue, 13 May 2014 21:56:23 -0400 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5372CD47.5070603@davea.name> On 05/13/2014 09:39 AM, Steven D'Aprano wrote: > On Tue, 13 May 2014 07:20:34 -0400, Roy Smith wrote: > >> ASCII *is* all I need. > > You've never needed to copyright something? Copyright ? Roy Smith 2014... > I know some people use (c) instead, but that actually has no legal > standing. (Not that any reasonable judge would invalidate a copyright > based on a technicality like that, not these days.) (c) has no standing whatsoever, as it's properly spelled (copr) -- DaveA From davea at davea.name Wed May 14 03:32:56 2014 From: davea at davea.name (Dave Angel) Date: Wed, 14 May 2014 03:32:56 -0400 Subject: Need help to write data onto an XML file after reading data from another xml file In-Reply-To: References: <2c8cb313-50f6-439b-a979-bd320a2c7b2c@googlegroups.com> Message-ID: <53731C28.6050602@davea.name> On 05/14/2014 02:49 AM, varun7rs at gmail.com wrote: > I try to add an edge with the source id and destination id over a loop but this is the error I am getting. And the range for the for addEdge is something I have no clue about. > > python export.py --output topology.xml --xml germany50.xml > Traceback (most recent call last): > File "export.py", line 239, in > main(sys.argv[1:]) > File "export.py", line 234, in main > network.addEdge( PHY_LINKS( j , sourcen, destnn, sid, did, cap_bdw) ) > File "/home/srva/Approach_Read.py", line 89, in addEdge > self.nodes[ edge.SourceID ].addInEdge( edge ) > IndexError: list index out of range > Thanks for posting a complete stack trace, it can be a real help. You still have not shown us the source code. Did you write it yourself, or are you just trying to debug something written by someone else? In particular, the exception occurs in Approach_Read.py. Is that your file, and can you edit it to ferret out the problem? Do you know what attributes are supposed to be of what types? I peaked; I actually took a look at your dropbox files. So I have some comments, though they may not help debug the problem. After all, there are hundreds of lines of code, First, you don't mention the Python version nor the OS you're using. Indirectly, I can surmise Python 2.7 and Linux, but it's much safer to declare such things in the problem descrition. Assuming 2.x, you're using old-style classes. While that might not be a bug, they've been obsolete for at least a decade. You need to derive each of your classes from object. So, you should have for example: class CplexSolver(object): next, you have way too few comments. I can't even tell why you put certain classes and functions in one file, versus others in another file. Next, you don't follow Pep8, or any other reasonable standard, for naming. Thus, I can't tell readily whether a particular name is a class name, an attribute, a method, or whatever. If the code were smaller, I might be willing to work it out, and make myself a crossref, but that's why you should simplify a problem you're asking for help with. If the code is 700 lines, few people are going to be willing to study it unless it's very well commented and easy to follow. You have a name PHY_NETWORK, which being all caps would indicate it's a const, but instead it's actually a class. It has a method addEdge(), which takes an argument edge. But it's not obvious to me what class that is, so I could look up its definition. If you don't know either, you could add a print type(edge) to that method, and see what gets printed just before it gets the exception. That field might happen to be of type PHY_LINKS, in which case we see the initializer has the line self.SourceID = SourceID Unfortunately, we don't know what class that's supposed to be. You're using it like it's an integer, and the integer is apparently outside the range of the list PHY_NETWORK.nodes So you could add a few more print statements, find out the len() of nodes, and the value of SourceID. -- DaveA From steve+comp.lang.python at pearwood.info Wed May 14 09:08:28 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 May 2014 13:08:28 GMT Subject: Exception problem with module References: <5372b2ae$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53736acb$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 14 May 2014 09:21:50 +0000, Joseph L. Casale wrote: >> I see that you've solved your immediate problem, but you shouldn't call >> __setattr__ directly. That should actually be written >> >> setattr(bar, 'a_new_name', MyError) >> >> But really, since bar is (apparently) a module, and it is *bar itself* >> setting the attribute, the better way is >> >> a_new_name = MyError >> >> or even >> >> from module.foo import MyError as a_new_name > > Well I am not sure what advantage this has for the user, not my code as > I don't advocate the import to begin with it, its fine spelled as it was > from where it was... The advantage for the user is: - it avoids module bar needing to get a reference to itself; - it avoids the distraction of unnecessarily calling a dunder method; - it is idiomatic Python code that should be instantly understandable by any even moderately experienced Python coder; - prevents the reader from puzzling over why the code does something so unusual ("but why does he do this...?"); - and avoids the inevitable anger and/or contempt when the reader works out that there is no good reason to write such unidiomatic code. One should code as if the next person who reads your program is an easily upset psychotic axe-murderer who knows where you live. You wouldn't condone writing y = x.__add__(1) instead of y = x + 1, you shouldn't condone writing module.__setattr__ directly either. > I'll look back at this and see if that resolves the > issue as it had manifested. I doubt it. Not unless module bar has done something weird, like define a function called __setattr__ that shadows the actual method and wraps the exception in another object. More likely, I think you'll find that the original MyError doesn't inherit from Exception. -- Steven D'Aprano http://import-that.dreamwidth.org/ From alain at dpt-info.u-strasbg.fr Wed May 14 09:13:51 2014 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 14 May 2014 15:13:51 +0200 Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> Message-ID: <87siocsdtc.fsf@dpt-info.u-strasbg.fr> Marko Rauhamaa writes: > Alain Ketterlin : > >> The real nice thing that makes Julia a different language is the >> optional static typing, which the JIT can use to produce efficient code. >> It's the only meaningful difference with the current state of python. > > I'm guessing the two main performance roadblocks for Python are: > > 1. The dot notation is a hash table lookup instead of a fixed offset to > a vector. > > 2. The creation of a class instance generates a set of trampolines for > all methods. The trampolines are ordinary fields that can be > overridden. Do you suggest this as a checklist to decide whether Python is the appropriate language for a task? ("Do you really need any of these? If yes, use python.") > Both features are critical to Python's "sex appeal;" I wouldn't give > them up for performance gains. There are cases where performance matters (especially, when it is directly related to your electricity bill). > Producing an effective JIT for Python seems like a formidable challenge > but not impossible in principle. After all, the developer *could* > provide that static typing information in, like, 99.9% of the code. Not 99% of the code; the code that runs 99% of the time. > That would be feat worthy of a Millennium Technology Prize. Here is a fairly interesting blog post about what the WebKit developpers do for javascript (including profile-directed type inference, as they call it): https://www.webkit.org/blog/3362/introducing-the-webkit-ftl-jit/ -- Alain. From rosuav at gmail.com Wed May 14 09:17:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 May 2014 23:17:45 +1000 Subject: Exception problem with module In-Reply-To: <53736acb$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5372b2ae$0$29977$c3e8da3$5496439d@news.astraweb.com> <53736acb$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 14, 2014 at 11:08 PM, Steven D'Aprano wrote: > One should code as if the next person who reads your program is an easily > upset psychotic axe-murderer who knows where you live. You wouldn't > condone writing y = x.__add__(1) instead of y = x + 1, you shouldn't > condone writing module.__setattr__ directly either. Oddly enough, I was referencing that first half earlier this evening :) There's a difference between x.__add__(1) and x + 1, though. The latter might end up calling (1).__radd__(x), which (obviously) the first won't. I can imagine there might be some use-case where you specifically DON'T want the reflected method to be silently called (maybe for introspection or debugging??). But it falls under code smell, the sort of thing where you absolutely MUST have a comment - like where I have a call to set_foreground(bg), because that could so easily be an error, yet in this case isn't. ChrisA From alister.nospam.ware at ntlworld.com Wed May 14 09:21:25 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 14 May 2014 13:21:25 GMT Subject: Why isn't my re.sub replacing the contents of my MS Word file? References: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> <537222d8$0$29980$c3e8da3$5496439d@news.astraweb.com> <63051425-ec42-45b4-8a9e-53001625f32a@googlegroups.com> <220e9313-4887-446f-bf30-81972dfe2c2e@googlegroups.com> Message-ID: On Tue, 13 May 2014 23:12:40 -0700, wxjmfauth wrote: > Le mardi 13 mai 2014 22:26:51 UTC+2, MRAB a ?crit : >> On 2014-05-13 20:01, scottcabit at gmail.com wrote: >> >> > On Tuesday, May 13, 2014 9:49:12 AM UTC-4, Steven D'Aprano wrote: >> >> >> >> >> >> You may have missed my follow up post, where I said I had not >> >> noticed you >> >> >> were operating on a binary .doc file. >> >> >> >> >> >> If you're not willing or able to use a full-blown doc parser, say by >> >> >> controlling Word or LibreOffice, the other alternative is to do >> >> something >> >> >> quick and dirty that might work most of the time. Open a doc file, >> >> or >> >> >> multiple doc files, in a hex editor and *hopefully* you will be able >> >> to >> >> >> see chunks of human-readable text where you can identify how >> >> en-dashes >> >> >> and similar are stored. >> >> >> > >> > I created a .doc file and opened it with UltraEdit in binary (Hex) >> > mode. What I see is that there are two characters, one for ndash >> > and one for mdash, each a single byte long. 0x96 and 0x97. >> >> > So I tried this: fStr = re.sub(b'\0x96',b'-',fStr) >> >> >> > >> > that did nothing in my file. So I tried this: fStr = >> > re.sub(b'0x97',b'-',fStr) >> >> >> > >> > which also did nothing. >> >> > So, for fun I also tried to just put these wildcards in my >> > re.findall so I added |Part \0x96|Part \0x97 to no avail. >> >> >> > >> > Obviously 0x96 and 0x97 are NOT being interpreted in a re.findall >> > or re.sub as hex byte values of 96 and 97 hexadecimal using my >> > current syntax. >> >> >> > >> > So here's my question...if I want to replace all ndash or mdash >> > values with regular '-' symbols using re.sub, what is the proper >> > syntax to do so? >> >> >> > >> > Thanks! >> >> >> > >> 0x96 is a hexadecimal literal for an int. Within a string you need \x96 >> >> (it's \x for 2 hex digits, \u for 4 hex digits, \U for 8 hex digits). > > > ---------------- > >>>> b'0x61' == b'0x61' > True >>>> b'0x96' == b'\x96' > False > > > - Python and the coding of characters is an unbelievable mess. > - Unicode a joke. > - I can make Python failing with any valid sequence of chars I wish. > - There is a difference between "look, my code work with my chars" and > "this code is safely working with any chars". > > jmf 0x96 is not valid ASCII neither is it a valid unicode character in any encoding scheme I am familiar with it is therefore no surprise that python refuses to encode it it looks like this file is in ANSI - ISO-8859-1 regular expressions are probably overkill fro this issue loop through the byte array & replace the bytes as needed. -- Under deadline pressure for the next week. If you want something, it can wait. Unless it's blind screaming paroxysmally hedonistic... From ned at nedbatchelder.com Wed May 14 09:41:48 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 14 May 2014 09:41:48 -0400 Subject: New to Python. For in loops curiosity In-Reply-To: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> References: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> Message-ID: On 5/13/14 11:38 PM, Leonardo Petry wrote: > Hi All, > > So I am starting with python and I have been working on some simple exercises. > > Here is something I found curious about python loops > > This loop run each character in a string > > def avoids(word,letters): > flag = True > for letter in letters: > if(letter in word): > flag = False > return flag > > The loop below (at the bottom) runs each line of the file > > fin = open('wordplay.txt'); > user_input = raw_input('Enter some characters: ') > count = 0 > for line in fin: > word = line.strip() > if(avoids(word, user_input)): > count += 1; > > This is just too convenient. > Basically my question is: Why is python not treating the contents of wordplay.txt as one long string and looping each character? > > Any comment is greatly appreciate. Thanks > > Every class can decide for itself how it will behave when iterated over (including deciding whether it can be iterated at all). File objects produce lines, strings produce characters, lists produce elements, dictionaries produce keys. Other objects do more exotic things. You might find this helpful: http://bit.ly/pyiter It's a PyCon talk all about iteration in Python, aimed at new learners. -- Ned Batchelder, http://nedbatchelder.com From varun7rs at gmail.com Wed May 14 09:42:38 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Wed, 14 May 2014 06:42:38 -0700 (PDT) Subject: Need help to write data onto an XML file after reading data from another xml file In-Reply-To: References: <2c8cb313-50f6-439b-a979-bd320a2c7b2c@googlegroups.com> Message-ID: <6c5ea113-d87a-40ff-8039-dd8694fdf73f@googlegroups.com> That is a very descriptive post. Since its my first time programming I am not aware of many conventions that are being used to name classes. I tried to distinguish them by naming classes in caps. I borrowed some ideas from here and there to come up with the Approach_Read.py file. What I intend to do with that file is basically define classes. I have defined all the classes that are necessary for me. Now, the lower part of the file contains a function readXML or something which I am still working on but as of now it is not relevant. Second file would be the approach file which I have to use once I generate the xml file that I need to use. So, this brings me to the last file which is really messy. All I want to do in the export.py file is that I'd like to pull out some data from the xml file(from the SNDLib website for the sake of topology). Since this xml file contains the source, destination and some other relevant attributes, I read them out of it. Now, I want to use the class PHY_NETWORK to create this topology. The class consists of arguments nodes, edges, etc., Here to add edges between the nodes, I call the method addEdge from the class PHY_NETWORK. But when I do that I get this error 'unicode' object has no attribute 'addInEdge. I'm not sure if I made myself clear. Once the stuff is working, I would like an xml file which looks somewhat like the one below but with attributes we need like the processing, storage and switching power. VNEInstance schema="VNEInstance.xsd" version=""> I'm really sorry for the trouble but once I get this thing going then I can move on with the CPLEX solving stuff.Thanks a lot for your help From rosuav at gmail.com Wed May 14 09:49:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 May 2014 23:49:58 +1000 Subject: Need help to write data onto an XML file after reading data from another xml file In-Reply-To: <6c5ea113-d87a-40ff-8039-dd8694fdf73f@googlegroups.com> References: <2c8cb313-50f6-439b-a979-bd320a2c7b2c@googlegroups.com> <6c5ea113-d87a-40ff-8039-dd8694fdf73f@googlegroups.com> Message-ID: On Wed, May 14, 2014 at 11:42 PM, wrote: > Since its my first time programming I am not aware of many conventions that are being used to name classes. I tried to distinguish them by naming classes in caps. The most commonly followed naming conventions in Python are those mandated for Python's own standard library. The definition of that is in a document called PEP 8: http://www.python.org/dev/peps/pep-0008/ Makes a good read. If you at least mostly follow PEP 8, people on this list will instantly know what's a class and what's not, etc, and it'll make things easier all round. ChrisA From sturla.molden at gmail.com Wed May 14 10:23:57 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Wed, 14 May 2014 16:23:57 +0200 Subject: Using threads for audio computing? In-Reply-To: <53705d34$0$2374$426a74cc@news.free.fr> References: <536f869c$0$2178$426a74cc@news.free.fr> <536f99eb$0$2109$426a74cc@news.free.fr> <53705d34$0$2374$426a74cc@news.free.fr> Message-ID: On 12/05/14 07:33, lgabiot wrote: > But AFAIK the python GIL (and in smaller or older computers that have > only one core) does not permit true paralell execution of two threads. I > believe it is quite like the way multiple processes are handled by an OS > on a single CPU computer: process A has x CPU cycles, then process B has > y CPU cycles, etc... Python threads are native OS threads. The GIL serializes access to the Python interpreter. If your thread is waiting for i/o or running computations in C or Fortran (e.g. with NumPy), it does not need the Python interpreter. Scientists and engineers use Python threads for "true parallel processing" all the time. The FUD you will find about the GIL is written by people who don't fully understand the issue. > So in my case, I must have a way to make sure that: > thread 1 (which gets audio from Pyaudio and put() it in the Queue) is > not interrupted long enough to miss a sample. Here you are mistaken. The DMA controller takes care of the audio i/o. Your audio acquisition thread is asleep while its buffer fills up. You don't miss a sample because your thread is interrupted. You do, however, have to make sure your thread don't block on the write to the Queue (use block=False in the call to Queue.put), but it is not a "GIL issue". In your case you basically have on thread waiting for the DMA controller to fill up a buffer and another doing computations in NumPy. Neither needs the GIL for most of their work. If you are worried about the GIL you can always use processes (multiprocessing, subprocess, or os.fork) instead of threads. Sturla From scottcabit at gmail.com Wed May 14 10:40:33 2014 From: scottcabit at gmail.com (scottcabit at gmail.com) Date: Wed, 14 May 2014 07:40:33 -0700 (PDT) Subject: Why isn't my re.sub replacing the contents of my MS Word file? In-Reply-To: References: <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> <537222d8$0$29980$c3e8da3$5496439d@news.astraweb.com> <63051425-ec42-45b4-8a9e-53001625f32a@googlegroups.com> Message-ID: On Tuesday, May 13, 2014 4:26:51 PM UTC-4, MRAB wrote: > > 0x96 is a hexadecimal literal for an int. Within a string you need \x96 > > (it's \x for 2 hex digits, \u for 4 hex digits, \U for 8 hex digits). Yes, that was my problem. Figured it out just after posting my last message. using \x96 works correctly. Thanks! From ian.g.kelly at gmail.com Wed May 14 11:07:23 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 14 May 2014 09:07:23 -0600 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 13, 2014 6:10 PM, "Chris Angelico" wrote: > > On Wed, May 14, 2014 at 9:53 AM, Steven D'Aprano > wrote: > > With the current system, all of us here are technically violating > > copyright every time we reply to an email and quote more than a small > > percentage of it. > > Oh wow... so when someone quotes heaps of text without trimming, and > adding blank lines, we can complain that it's a copyright violation - > reproducing our work with unauthorized modifications and without > permission... > > I never thought of it like that. I'd be surprised if this doesn't fall under fair use. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at reportlab.com Wed May 14 11:30:27 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 14 May 2014 16:30:27 +0100 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53738C13.60406@chamonix.reportlab.co.uk> On 13/05/2014 17:08, Ian Kelly wrote: ......... > > And since it's so simple, it shouldn't be hard to see that the use of > the shutil module has nothing to do with the Unicode woes here. The > crux of the issue is that a general-purpose command like cat typically > can't know the encoding of its input and can't assume anything about > it. In fact, there may not even be an encoding; cat can be used with > binary data. The only non-destructive approach then is to copy the > binary data straight from the source to the destination with no > decoding steps at all, and trust the user to ensure that the > destination will be able to accommodate the source encoding. Because > Python 3 presents stdin and stdout as text streams however, it makes > them more difficult to use with binary data, which is why Armin sets > up all that extra code to make sure his file objects are binary. > Doesn't this issue also come up wherever bytes are being read ie in sockets, pipe file handles etc? Some sources may have well defined encodings and so allow use of unicode strings but surely not all. I imagine all of the problems associated with a broken encoding promise for stdin can also occur with sockets & other sources ie error messages failing to be printable etc etc. Since bytes in Python 3 are not equivalent to the old str (Python 3 bytes != Python 2 str) using bytes everywhere has its own problems. -- Robin Becker From 4kir4.1i at gmail.com Wed May 14 11:44:00 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Wed, 14 May 2014 19:44:00 +0400 Subject: httplib with NETRC authentication References: Message-ID: <8738gcgybj.fsf@gmail.com> Chris Angelico writes: > On Wed, May 14, 2014 at 9:33 AM, pratibha natani wrote: >> I am trying to establish http connection to a gerrit host using >> netrc authentication. I have a netrc file created with following >> entries: >> machine host1.com login name password pass >> >> I did a debug and saw that my netrc file is being read >> correctly. Also in the connection object(after sending request) a >> header got created with appropriate credentials: >> 'headers': {'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ='} >> >> Still I get 401,Unauthorized in response. Any help would be greatly appreciated! > > The obvious question is: What *does* work? Does it work when you use > wget, or some other application? Then go and look at what that sends > for its authentication headers. Tip: It won't be "Authorization". "Authorization" is the appropriate header for basic http authentication: http://tools.ietf.org/html/rfc2617#section-2 Here's a code example for urllib2: https://gist.github.com/kennethreitz/973705#comment-56387 -- akira From ian.g.kelly at gmail.com Wed May 14 11:56:54 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 14 May 2014 09:56:54 -0600 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <53738C13.60406@chamonix.reportlab.co.uk> References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <53738C13.60406@chamonix.reportlab.co.uk> Message-ID: On Wed, May 14, 2014 at 9:30 AM, Robin Becker wrote: > Doesn't this issue also come up wherever bytes are being read ie in sockets, > pipe file handles etc? Some sources may have well defined encodings and so > allow use of unicode strings but surely not all. I imagine all of the > problems associated with a broken encoding promise for stdin can also occur > with sockets & other sources ie error messages failing to be printable etc > etc. Since bytes in Python 3 are not equivalent to the old str (Python 3 > bytes != Python 2 str) using bytes everywhere has its own problems. Sockets send and receive bytes, and pipes created by the subprocess module are opened in binary mode. Pipes inherited as stdin are still assumed to be unicode, though. From 4kir4.1i at gmail.com Wed May 14 12:24:11 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Wed, 14 May 2014 20:24:11 +0400 Subject: python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly References: <53735242.2010406@rece.vub.ac.be> Message-ID: <87r43wfhw4.fsf@gmail.com> Antoon Pardon writes: > This is the code I run (python 3.3) > > host = ... > user = ... > passwd = ... > > from ftplib import FTP > > ftp = FTP(host, user, passwd) > ftp.mkd(b'NewDir') > ftp.rmd(b'NewDir') > > This is the traceback > > Traceback (most recent call last): > File "ftp-problem", line 9, in > ftp.mkd(b'NewDir') > File "/usr/lib/python3.3/ftplib.py", line 612, in mkd > resp = self.voidcmd('MKD ' + dirname) > TypeError: Can't convert 'bytes' object to str implicitly > > The problem is that I do something like this in a backup program. > I don't know the locales that other people use. So I manipulate > all file and directory names as bytes. > > Am I doing something wrong? The error message shows that ftplib expects a string here, not bytes. You could use `ftp.mkd(some_bytes.decode(ftp.encoding))` as a workaround. -- akira From 4kir4.1i at gmail.com Wed May 14 12:47:22 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Wed, 14 May 2014 20:47:22 +0400 Subject: httplib with NETRC authentication References: Message-ID: <87mwekfgth.fsf@gmail.com> pratibha natani writes: > Hi, > > I am trying to establish http connection to a gerrit host using netrc authentication. I have a netrc file created with following entries: > machine host1.com login name password pass > > I did a debug and saw that my netrc file is being read correctly. Also in the connection object(after sending request) a header got created with appropriate credentials: > 'headers': {'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ='} > It should be QWxhZGRpbjpvcGVuIHNlc2FtZQ== (note: the second '=') Also, make sure that you use the correct case for the username. Userids might be case sensitive. -- akira From rosuav at gmail.com Wed May 14 13:03:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 May 2014 03:03:10 +1000 Subject: httplib with NETRC authentication In-Reply-To: <8738gcgybj.fsf@gmail.com> References: <8738gcgybj.fsf@gmail.com> Message-ID: On Thu, May 15, 2014 at 1:44 AM, Akira Li <4kir4.1i at gmail.com> wrote: >> The obvious question is: What *does* work? Does it work when you use >> wget, or some other application? Then go and look at what that sends >> for its authentication headers. Tip: It won't be "Authorization". > > "Authorization" is the appropriate header for basic http authentication: > http://tools.ietf.org/html/rfc2617#section-2 *facepalm* Critical reading failure on my part. He did have it right in the first place. Still, I stand by the original statement and (more importantly) the original question. It's just the tip that's wrong. ChrisA From antoon.pardon at rece.vub.ac.be Wed May 14 14:06:33 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 14 May 2014 20:06:33 +0200 Subject: python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly In-Reply-To: <87r43wfhw4.fsf@gmail.com> References: <53735242.2010406@rece.vub.ac.be> <87r43wfhw4.fsf@gmail.com> Message-ID: <5373B0A9.1090508@rece.vub.ac.be> op 14-05-14 18:24, Akira Li schreef: > Antoon Pardon writes: > >> This is the code I run (python 3.3) >> >> host = ... >> user = ... >> passwd = ... >> >> from ftplib import FTP >> >> ftp = FTP(host, user, passwd) >> ftp.mkd(b'NewDir') >> ftp.rmd(b'NewDir') >> >> This is the traceback >> >> Traceback (most recent call last): >> File "ftp-problem", line 9, in >> ftp.mkd(b'NewDir') >> File "/usr/lib/python3.3/ftplib.py", line 612, in mkd >> resp = self.voidcmd('MKD ' + dirname) >> TypeError: Can't convert 'bytes' object to str implicitly >> >> The problem is that I do something like this in a backup program. >> I don't know the locales that other people use. So I manipulate >> all file and directory names as bytes. >> >> Am I doing something wrong? > > The error message shows that ftplib expects a string here, not bytes. > You could use `ftp.mkd(some_bytes.decode(ftp.encoding))` as a > workaround. Sure but what I like to know: Can this be considered a failing of ftplib. Since python3 generally allows paths to be strings as well as bytes can't we expect the same of ftplib? Especially as I assume that path will be converted to bytes anyway in order to send it over the network. -- Antoon Pardon. From python at mrabarnett.plus.com Wed May 14 14:38:15 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 14 May 2014 19:38:15 +0100 Subject: python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly In-Reply-To: <5373B0A9.1090508@rece.vub.ac.be> References: <53735242.2010406@rece.vub.ac.be> <87r43wfhw4.fsf@gmail.com> <5373B0A9.1090508@rece.vub.ac.be> Message-ID: <5373B817.5030503@mrabarnett.plus.com> On 2014-05-14 19:06, Antoon Pardon wrote: > op 14-05-14 18:24, Akira Li schreef: >> Antoon Pardon writes: >> >>> This is the code I run (python 3.3) >>> >>> host = ... >>> user = ... >>> passwd = ... >>> >>> from ftplib import FTP >>> >>> ftp = FTP(host, user, passwd) >>> ftp.mkd(b'NewDir') >>> ftp.rmd(b'NewDir') >>> >>> This is the traceback >>> >>> Traceback (most recent call last): >>> File "ftp-problem", line 9, in >>> ftp.mkd(b'NewDir') >>> File "/usr/lib/python3.3/ftplib.py", line 612, in mkd >>> resp = self.voidcmd('MKD ' + dirname) >>> TypeError: Can't convert 'bytes' object to str implicitly >>> >>> The problem is that I do something like this in a backup program. >>> I don't know the locales that other people use. So I manipulate >>> all file and directory names as bytes. >>> >>> Am I doing something wrong? >> >> The error message shows that ftplib expects a string here, not bytes. >> You could use `ftp.mkd(some_bytes.decode(ftp.encoding))` as a >> workaround. > > Sure but what I like to know: Can this be considered a failing of > ftplib. Since python3 generally allows paths to be strings as > well as bytes can't we expect the same of ftplib? > > Especially as I assume that path will be converted to bytes anyway > in order to send it over the network. > From studying the code, I see that it uses the Latin-1 encoding. On another note, I find it interesting that the default for the timeout argument uses the 'magic' value -999 rather than, say, None! From musicalhacksaw at yahoo.co.uk Wed May 14 14:58:55 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Wed, 14 May 2014 11:58:55 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> Message-ID: <11010ab5-4bce-4d39-8d36-a010911f7090@googlegroups.com> I downloaded the get-pip.py file. I installed it to the same folder on my C drive as the Beautiful Soup one in which the Beautiful Soup 4 downloads was unzipped to. I changed directory to the folder on the Command Prompt, as you instructed in step 2. I input the code to the console you gave on step 3), that returned some code, as quoted below. I then input the code you gave on step 4) but Console seems to reject or not recognise 'pip' as a term. I am sure quoting the actual prompt response can explain things better than I : ------------------------------------------------------------------------------- Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Intel Atom>cd "c:\Beautiful Soup" c:\Beautiful Soup>python get-pip.py Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pi p-1.5.5-py2.py3-none-any.whl#md5=03a932d6f82a3887d8de1cdb837c87ed Installing collected packages: pip Found existing installation: pip 1.5.4 Uninstalling pip: Successfully uninstalled pip Successfully installed pip Cleaning up... c:\Beautiful Soup>pip install beautifulsoup4 'pip' is not recognized as an internal or external command, operable program or batch file. c:\Beautiful Soup> -------------------------------------------------------------------------------- Perhaps I oughtn't have downloaded the pip file to the same directory as the Beautiful Soup ? I will have a try at transferring the file to another folder and running the code you gave again. From musicalhacksaw at yahoo.co.uk Wed May 14 15:28:50 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Wed, 14 May 2014 12:28:50 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> Message-ID: I have input the above code by copy and pasting to the Idle python console, as the python 2.7 command prompt is fussy about the indentation on the eleventh line down, if I then indent it, it replies that the indentation is unnecessary of unexpected, and if I don't it says an indentation is expected. However when I get to the next lines of code - in the Idle prompt re: C:\Users\Intel Atom>cd "c:\Beautiful Soup" c:\Beautiful Soup>c:\Python27\python setup.py install Again it does not recognise 'bs4'. I think having used 'Just unzip it' instead of 'WinZip' may have caused this problem, in the first place ,as when I looked at the WinZip version at a local net caf?, it did have a folder hierarchy, however I wanted, and still want to skimp the ?25 fee for WinZip, which nowadays you can't seem to be able to do. I never asked for the darn files to be zipped, so why ought I pay to have them unzipped, being my contention. From ian.g.kelly at gmail.com Wed May 14 15:30:52 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 14 May 2014 13:30:52 -0600 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <11010ab5-4bce-4d39-8d36-a010911f7090@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> <11010ab5-4bce-4d39-8d36-a010911f7090@googlegroups.com> Message-ID: On Wed, May 14, 2014 at 12:58 PM, Simon Evans wrote: > c:\Beautiful Soup>pip install beautifulsoup4 > 'pip' is not recognized as an internal or external command, > operable program or batch file. > > c:\Beautiful Soup> > -------------------------------------------------------------------------------- > Perhaps I oughtn't have downloaded the pip file to the same directory as the Beautiful Soup ? I will have a try at transferring the file to another folder > and running the code you gave again. No, sounds like a path environment variable issue. The python executable is on your path, but the pip executable is not. The get-pip.py script should have installed it into C:\Python27\Scripts, I think, so either add that directory to your path (you can find instructions for this on the web) or just cd to that directory and run the pip command from there. From ian.g.kelly at gmail.com Wed May 14 15:33:40 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 14 May 2014 13:33:40 -0600 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> Message-ID: On Wed, May 14, 2014 at 1:28 PM, Simon Evans > Again it does not recognise 'bs4'. I think having used 'Just unzip it' instead of 'WinZip' may have caused this problem, in the first place ,as when I looked at the WinZip version at a local net caf?, it did have a folder hierarchy, however I wanted, and still want to skimp the ?25 fee for WinZip, which nowadays you can't seem to be able to do. I never asked for the darn files to be zipped, so why ought I pay to have them unzipped, being my contention. I use 7-zip (www.7-zip.org), which is freely distributed and open source. From rosuav at gmail.com Wed May 14 15:36:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 May 2014 05:36:55 +1000 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> Message-ID: On Thu, May 15, 2014 at 5:33 AM, Ian Kelly wrote: > I use 7-zip (www.7-zip.org), which is freely distributed and open source. You beat me to the punch. :) Was about to say the exact same thing, so instead I'll second your recommendation. ChrisA From tjreedy at udel.edu Wed May 14 17:09:30 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 May 2014 17:09:30 -0400 Subject: PEP 8 : Maximum line Length : In-Reply-To: <85iop98f16.fsf@benfinney.id.au> References: <5372223c$0$29980$c3e8da3$5496439d@news.astraweb.com> <85iop98f16.fsf@benfinney.id.au> Message-ID: On 5/13/2014 6:55 PM, Ben Finney wrote: > Steven D'Aprano writes: > >> On Tue, 13 May 2014 04:52:26 -0700, Rustom Mody wrote: >> >>> What this goes to show is that while 80 is ridiculously low by most >>> displays today, >> >> Not for people who like to has two (or three, or four) windows side-by- >> side. Or multiple views of the same document. > > There's also the fact that, while the capacity of monitors to display > pixels has dramatically increased in recent decades, the capacity of > human cognition to scan long lines of text has not increased at all in > that time. > The 80 character line limit is *not* driven by a limitation of computer > technology; it is driven by a limitation of human cognition. For that > reason, it remains relevant until human cognition in the general reading > population improves. I use the monitor capacity to have 2 or even 3 code windows open side-by-side. Really handy. -- Terry Jan Reedy From tjreedy at udel.edu Wed May 14 17:47:06 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 May 2014 17:47:06 -0400 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <5372BE8B.3070302@stoneleaf.us> References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b493$0$29977$c3e8da3$5496439d@news.astraweb.com> <5372BE8B.3070302@stoneleaf.us> Message-ID: On 5/13/2014 8:53 PM, Ethan Furman wrote: > On 05/13/2014 05:10 PM, Steven D'Aprano wrote: >> On Tue, 13 May 2014 10:08:42 -0600, Ian Kelly wrote: >> >>> Because Python 3 presents stdin and stdout as text streams however, it >>> makes them more difficult to use with binary data, which is why Armin >>> sets up all that extra code to make sure his file objects are binary. >> >> What surprises me is how hard that is. Surely there's a simpler way to >> open stdin and stdout in binary mode? If not, there ought to be. > > Somebody already posted this: > > https://docs.python.org/3/library/sys.html#sys.stdin > > which talks about .detach(). I sent a message to Armin about this. -- Terry Jan Reedy From albert at spenarnc.xs4all.nl Wed May 14 18:53:52 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 14 May 2014 22:53:52 GMT Subject: PEP 8 : Maximum line Length : References: Message-ID: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> In article , Rustom Mody wrote: >On Tuesday, May 13, 2014 12:37:24 PM UTC+5:30, Ganesh Pal wrote: >> Hi Team , >> >> >> what would be the best way to intent the below line . >> >> I have few lines in my program exceeding the allowed maximum line >Length of 79./80 characters >> >> >> Example 1 : >> >> >> p = >Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) > > >First rule of python-list: Pay careful attention to Peter Otten. > >That said... > >80-character limit?! > >Sheesh! A relic of the days when terminals were ASCII and 80x24 80 character was the hard limit. The soft limit for readability is 60..65 characters. Think about it. Just that a language accepts #define MASK_SEPIA_INTERNAL_BLEEDING_WASHINGTON_DC_BLACK 0x147800fa means that it is a good idea to do so. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From sturla.molden at gmail.com Wed May 14 19:05:44 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Wed, 14 May 2014 23:05:44 +0000 (UTC) Subject: Fortran References: <87mweotfe5.fsf@dpt-info.u-strasbg.fr> <87iopbtmh1.fsf@dpt-info.u-strasbg.fr> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> <5372b488$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1613032089421800145.832800sturla.molden-gmail.com@news.gmane.org> Ian Kelly wrote: > Also numba, which is reminiscent of psyco, but with more features and > Python 3 support. For numerical computing with NumPy, Numba tends to give performance comparable to -O2 in C. This is because it is very easy to do type inference in most scientific array computing. Numba is still a bit immature, though, compared to e.g. Cython. Sturla From gary.herron at islandtraining.com Wed May 14 20:15:06 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Wed, 14 May 2014 17:15:06 -0700 Subject: PEP 8 : Maximum line Length : In-Reply-To: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> Message-ID: <5374070A.5020308@islandtraining.com> On 05/14/2014 03:53 PM, Albert van der Horst wrote: > In article , > Rustom Mody wrote: >> On Tuesday, May 13, 2014 12:37:24 PM UTC+5:30, Ganesh Pal wrote: >>> Hi Team , >>> >>> >>> what would be the best way to intent the below line . >>> >>> I have few lines in my program exceeding the allowed maximum line >> Length of 79./80 characters >>> >>> Example 1 : >>> >>> >>> p = >> Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) >> >> >> First rule of python-list: Pay careful attention to Peter Otten. >> >> That said... >> >> 80-character limit?! >> >> Sheesh! A relic of the days when terminals were ASCII and 80x24 Which is a relic of the even older punch cards which contained one line of (up to) 80 characters. Gary Herron > 80 character was the hard limit. > The soft limit for readability is 60..65 characters. > Think about it. > > Just that a language accepts > #define MASK_SEPIA_INTERNAL_BLEEDING_WASHINGTON_DC_BLACK 0x147800fa > means that it is a good idea to do so. > > Groetjes Albert From breamoreboy at yahoo.co.uk Wed May 14 21:16:58 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 15 May 2014 02:16:58 +0100 Subject: PEP 8 : Maximum line Length : In-Reply-To: <5374070A.5020308@islandtraining.com> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <5374070A.5020308@islandtraining.com> Message-ID: On 15/05/2014 01:15, Gary Herron wrote: > > Which is a relic of the even older punch cards which contained one line > of (up to) 80 characters. > > Gary Herron > I still remember the cry of anguish when the guy in the computer building at (the then) Portsmouth Polytechnic dropped his cardboard box of punch cards that made up his end of course project. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From roy at panix.com Wed May 14 22:12:13 2014 From: roy at panix.com (Roy Smith) Date: Wed, 14 May 2014 22:12:13 -0400 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <5374070A.5020308@islandtraining.com> Message-ID: In article , Mark Lawrence wrote: > I still remember the cry of anguish when the guy in the computer > building at (the then) Portsmouth Polytechnic dropped his cardboard box > of punch cards that made up his end of course project. That's why you punch sequence numbers in columns 73-80. If the cards get out of order, just run the deck through the sorter. From rustompmody at gmail.com Wed May 14 22:36:13 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 14 May 2014 19:36:13 -0700 (PDT) Subject: PEP 8 : Maximum line Length : In-Reply-To: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> Message-ID: <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> On Thursday, May 15, 2014 4:23:52 AM UTC+5:30, Albert van der Horst wrote: > > Rustom Mody wrote: > >80-character limit?! > >Sheesh! A relic of the days when terminals were ASCII and 80x24 > > > 80 character was the hard limit. > The soft limit for readability is 60..65 characters. > Think about it. > > > Just that a language accepts > #define MASK_SEPIA_INTERNAL_BLEEDING_WASHINGTON_DC_BLACK 0x147800fa > means that it is a good idea to do so. Yes there are fundamental but soft limits, eg http://webtypography.net/2.1.2 And there are (semi)hard technological limits like if you post code longer 65 chars out here it will fold at random unforeseen points. These limits get irrelevant as the technology changes. If any of these has any relation with the magic number '79' I'd be curious to know. Until then may we relegate '79' to quaint historical curiosities like: Continuation in 6th column, Comment is a C in 1st column, 7-72 for code (ALONG WITH ALL CAPS CODE)? From ben at benfinney.id.au Wed May 14 22:43:21 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 15 May 2014 12:43:21 +1000 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> Message-ID: <85tx8r7ody.fsf@benfinney.id.au> Rustom Mody writes: > Until then may we relegate '79' to quaint historical curiosities Not until the general capacity of human cognition advances to make longer lines easier to read. We humans may be historical curiosities some day; until then, let's continue to write our code as though humans are the ones who will be reading it. -- \ ?Stop ? Drive sideways.? ?detour sign, Kyushu, Japan | `\ | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Wed May 14 23:28:17 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 May 2014 03:28:17 GMT Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> Message-ID: <53743451$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 14 May 2014 19:36:13 -0700, Rustom Mody wrote: > And there are (semi)hard technological limits like if you post code > longer 65 chars out here it will fold at random unforeseen points. These > limits get irrelevant as the technology changes. The technological limits may become irrelevant, but the human limits do not. While there are no *hard* limits to readability, both excessively long and excessively short lines are hard to read. Comprehension and reading speed suffers. > If any of these has any relation with the magic number '79' I'd be > curious to know. 79 is one short of 80, which gives you a margin of error of 1: off-by-one errors won't matter if you aim for 79 characters but miscalculate by one. People repeatedly state that 80 is the old, obsolete hard limit for ancient terminal systems, but the reason terminals standardised on 80 rather than 70 or 90 (or for that matter 300 or 30) is at least in part -- and I maintain a big part -- because of human reading. 60 to 90 characters per line is a comfortable range for human readability, which makes 80 a reasonable compromise that tends towards the upper end but without pushing hard up against it. Keeping the monitor size and character size fixed, it's easy to show *fewer* characters per line if you choose a standard towards the upper end, if you so choose, but impossible to squeeze in more if you choose a standard at the lower end. Just because the monitor (or the standard) *allows* up to 79 characters per line doesn't make it a good idea to regularly use that many. In my experience, given two or three indent levels, reasonably descriptive variable names, decently expressive expressions, I find that 60-70 characters is *typically* enough horizontal space for the average line of code. Long lines are often (not always) a sign that you're doing too much in one line. This isn't Perl, and newlines are a renewable resource. > Until then may we relegate '79' to quaint historical curiosities like: > Continuation in 6th column, Comment is a C in 1st column, 7-72 for code > (ALONG WITH ALL CAPS CODE)? Nope. Because the main driving force for 79 characters is not technology but human reading. -- Steven D'Aprano http://import-that.dreamwidth.org/ From breamoreboy at yahoo.co.uk Wed May 14 23:44:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 15 May 2014 04:44:06 +0100 Subject: PEP 8 : Maximum line Length : In-Reply-To: <85tx8r7ody.fsf@benfinney.id.au> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <85tx8r7ody.fsf@benfinney.id.au> Message-ID: On 15/05/2014 03:43, Ben Finney wrote: > Rustom Mody writes: > >> Until then may we relegate '79' to quaint historical curiosities > > Not until the general capacity of human cognition advances to make > longer lines easier to read. > > We humans may be historical curiosities some day; until then, let's > continue to write our code as though humans are the ones who will be > reading it. > I thought code was meant to be read by programmers, not humans :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From 4kir4.1i at gmail.com Thu May 15 02:36:35 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Thu, 15 May 2014 10:36:35 +0400 Subject: python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly References: <53735242.2010406@rece.vub.ac.be> <87r43wfhw4.fsf@gmail.com> <5373B0A9.1090508@rece.vub.ac.be> Message-ID: <871tvvfszw.fsf@gmail.com> Antoon Pardon writes: > op 14-05-14 18:24, Akira Li schreef: >> Antoon Pardon writes: >> >>> This is the code I run (python 3.3) >>> >>> host = ... >>> user = ... >>> passwd = ... >>> >>> from ftplib import FTP >>> >>> ftp = FTP(host, user, passwd) >>> ftp.mkd(b'NewDir') >>> ftp.rmd(b'NewDir') >>> >>> This is the traceback >>> >>> Traceback (most recent call last): >>> File "ftp-problem", line 9, in >>> ftp.mkd(b'NewDir') >>> File "/usr/lib/python3.3/ftplib.py", line 612, in mkd >>> resp = self.voidcmd('MKD ' + dirname) >>> TypeError: Can't convert 'bytes' object to str implicitly >>> >>> The problem is that I do something like this in a backup program. >>> I don't know the locales that other people use. So I manipulate >>> all file and directory names as bytes. >>> >>> Am I doing something wrong? >> >> The error message shows that ftplib expects a string here, not bytes. >> You could use `ftp.mkd(some_bytes.decode(ftp.encoding))` as a >> workaround. > > Sure but what I like to know: Can this be considered a failing of > ftplib. Since python3 generally allows paths to be strings as > well as bytes can't we expect the same of ftplib? > > Especially as I assume that path will be converted to bytes anyway > in order to send it over the network. bytes are supported for filenames because POSIX systems provide bytes-based interface e.g., on my system anything except / and NUL could be used. You can get away with passing opaque bytes filenames for some time. rfc 959 expects ascii filenames. rfc 2640 recommends UTF8 (if "feat" command returns it). rfc 3659: pathnames could be send as utf-8 *and* "raw". (plus CR LF or CR NUL or IAC or other telnet control codes handling). Using utf-8 might have security implications and some firewalls might interfere with OPTS command and FEAT response. Popular clients such as FileZilla may break on non-utf-8 filenames. It is less likely that ftp clients use the same character encoding and it is more likely that an ftp server performs some unexpected character encoding conversion despite it being non-standard-compliant. You could try to post on python-ideas mailing list anyway, to suggest the enhancement (support bytes where filenames are expected) for your backup application use case: - you might not avoid undecodable filenames -- UnicodeEncodeError in the current implementation if you pass Unicode string created using os.fsdecode(undecodable_bytes) to ftplib - non-python ftp clients should be able to access the content -- no Python error handlers such as surrogateescape or backslashreplace are allowed - set ftp.encoding to utf-8 and pass non-utf-8 filenames as bytes -- to avoid '\U0001F604'.encode('utf-8').decode(ftp.encoding) -- akira From musicalhacksaw at yahoo.co.uk Thu May 15 05:22:29 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Thu, 15 May 2014 02:22:29 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> Message-ID: <167bfe35-c36b-4d9d-8bd3-810015b24af6@googlegroups.com> Dear Programmers, I downloaded Peazip, which doesn't remove file/ folder hierarchy. I unzipped it and input the same code to the console and it installed Beautiful Soup 4 okay re:- --------------------------------------------------------------------------------- Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Intel Atom>cd "c:\Beautiful Soup" c:\Beautiful Soup>c:\Python27\python setup.py install running install running build running build_py creating build creating build\lib creating build\lib\bs4 copying bs4\dammit.py -> build\lib\bs4 copying bs4\element.py -> build\lib\bs4 copying bs4\testing.py -> build\lib\bs4 copying bs4\__init__.py -> build\lib\bs4 creating build\lib\bs4\builder copying bs4\builder\_html5lib.py -> build\lib\bs4\builder copying bs4\builder\_htmlparser.py -> build\lib\bs4\builder copying bs4\builder\_lxml.py -> build\lib\bs4\builder copying bs4\builder\__init__.py -> build\lib\bs4\builder creating build\lib\bs4\tests copying bs4\tests\test_builder_registry.py -> build\lib\bs4\tests copying bs4\tests\test_docs.py -> build\lib\bs4\tests copying bs4\tests\test_html5lib.py -> build\lib\bs4\tests copying bs4\tests\test_htmlparser.py -> build\lib\bs4\tests copying bs4\tests\test_lxml.py -> build\lib\bs4\tests copying bs4\tests\test_soup.py -> build\lib\bs4\tests copying bs4\tests\test_tree.py -> build\lib\bs4\tests copying bs4\tests\__init__.py -> build\lib\bs4\tests running install_lib creating c:\Python27\Lib\site-packages\bs4 creating c:\Python27\Lib\site-packages\bs4\builder copying build\lib\bs4\builder\_html5lib.py -> c:\Python27\Lib\site-packages\bs4\ builder copying build\lib\bs4\builder\_htmlparser.py -> c:\Python27\Lib\site-packages\bs 4\builder copying build\lib\bs4\builder\_lxml.py -> c:\Python27\Lib\site-packages\bs4\buil der copying build\lib\bs4\builder\__init__.py -> c:\Python27\Lib\site-packages\bs4\b uilder copying build\lib\bs4\dammit.py -> c:\Python27\Lib\site-packages\bs4 copying build\lib\bs4\element.py -> c:\Python27\Lib\site-packages\bs4 copying build\lib\bs4\testing.py -> c:\Python27\Lib\site-packages\bs4 creating c:\Python27\Lib\site-packages\bs4\tests copying build\lib\bs4\tests\test_builder_registry.py -> c:\Python27\Lib\site-pac kages\bs4\tests copying build\lib\bs4\tests\test_docs.py -> c:\Python27\Lib\site-packages\bs4\te sts copying build\lib\bs4\tests\test_html5lib.py -> c:\Python27\Lib\site-packages\bs 4\tests copying build\lib\bs4\tests\test_htmlparser.py -> c:\Python27\Lib\site-packages\ bs4\tests copying build\lib\bs4\tests\test_lxml.py -> c:\Python27\Lib\site-packages\bs4\te sts copying build\lib\bs4\tests\test_soup.py -> c:\Python27\Lib\site-packages\bs4\te sts copying build\lib\bs4\tests\test_tree.py -> c:\Python27\Lib\site-packages\bs4\te sts copying build\lib\bs4\tests\__init__.py -> c:\Python27\Lib\site-packages\bs4\tes ts copying build\lib\bs4\__init__.py -> c:\Python27\Lib\site-packages\bs4 byte-compiling c:\Python27\Lib\site-packages\bs4\builder\_html5lib.py to _html5l ib.pyc byte-compiling c:\Python27\Lib\site-packages\bs4\builder\_htmlparser.py to _html parser.pyc byte-compiling c:\Python27\Lib\site-packages\bs4\builder\_lxml.py to _lxml.pyc byte-compiling c:\Python27\Lib\site-packages\bs4\builder\__init__.py to __init__ .pyc byte-compiling c:\Python27\Lib\site-packages\bs4\dammit.py to dammit.pyc byte-compiling c:\Python27\Lib\site-packages\bs4\element.py to element.pyc byte-compiling c:\Python27\Lib\site-packages\bs4\testing.py to testing.pyc byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_builder_registry.py to test_builder_registry.pyc byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_docs.py to test_docs .pyc byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_html5lib.py to test_ html5lib.pyc byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_htmlparser.py to tes t_htmlparser.pyc byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_lxml.py to test_lxml .pyc byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_soup.py to test_soup .pyc byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_tree.py to test_tree .pyc byte-compiling c:\Python27\Lib\site-packages\bs4\tests\__init__.py to __init__.p yc byte-compiling c:\Python27\Lib\site-packages\bs4\__init__.py to __init__.pyc running install_egg_info Writing c:\Python27\Lib\site-packages\beautifulsoup4-4.1.0-py2.7.egg-info c:\Beautiful Soup> -------------------------------------------------------------------------------- Thank you for your thoughtful help, I am sure I will be needing more though, in the not too distant future. From musicalhacksaw at yahoo.co.uk Thu May 15 07:25:42 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Thu, 15 May 2014 04:25:42 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <167bfe35-c36b-4d9d-8bd3-810015b24af6@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> <167bfe35-c36b-4d9d-8bd3-810015b24af6@googlegroups.com> Message-ID: Dear Programmers, As anticipated, it has not been to long before I have encountered further difficulty. At the top of page 16 of 'Getting Started with Beautiful Soup" it gives code to be input, whether to the Python or Windows command prompt I am not sure, but both seem to be resistant to it. I quote the response to the code below, the code input being :- helloworld = "

Hello World

" soup_string = BeautifulSoup(helloworld) to Windows Command prompt this gives :- ---------------------------------------------------------------------------------- SyntaxError: invalid syntax >>> helloworld = "

HelloWorld

" >>> soup_string = BeautifulSoup(helloworld) Traceback (most recent call last): File "", line 1, in NameError: name 'BeautifulSoup' is not defined ---------------------------------------------------------------------------------- I have been told by one of the programmers, that I ought be inputting this to the Python command prompt (the book doesn't spacify), but that doesn't take either re:- ---------------------------------------------------------------------------------- >>>helloworld =

HelloWorld

" >>>soup_string = BeautifulSoup(helloworld) Traceback (most recent call last): File "", line 1, in NameError: name 'BeautifulSoup' is not defined >>> ---------------------------------------------------------------------------------- Looking at the bottom of page 16, there is more code for the inputting of, that again does not take to the Windows Command Prompt or the Python command prompt, re: import urllib2 from bs4 import BeautifulSoup url = "http://www.packtpub.com/books" page = urllib2.urlopen(url) soup_packtpage = BeautifulSoup(page) returns to the Windows Command prompt:- ---------------------------------------------------------------------------------- >>>import urllib2 Traceback (most recent call last): File "", line1, in ImportError: No module named 'urllib2' >>> ---------------------------------------------------------------------------------- returns to the Python command prompt :- ---------------------------------------------------------------------------------- >>> import urllib2 >>> from bs4 import BeautifulSoup >>> url = "http://www.packtpub.com/books" >>> page = urllib2.urlopen(url) Traceback (most recent call last): File "C\Python27\lib\urllib2.py",line 127, in urlopen return_opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py",line 410, in open response = meth(req, response) File "C:\Pyton27\lib\urllib2.py", oine 523, in http_response 'http', request, response, code, msg, hdrs) File"C:\Python27\lib\urllib2.py", line 448, in error return self._call_chain(*args) File "C:/Python27/lib/urllib2.py",line 382, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 531, in http_error_default raise HTTPError(req.get_full_url(), code, masg, hdrs, fp) urllib2.HTTPError: HTTP Error 403: Forbidden --------------------------------------------------------------------------------- Anway I hope you can tell me what is amiss, there is no point in my proceeding with the book (about 111 pages all told) until I find out why it won't take. I realise I have been told to learn python in order to make things less painful, but I don't see why code written in the book does not take. Thank you for reading. I thought I might as well include, so's you might be able to see where things are going astray. The Windows command prompt :- From musicalhacksaw at yahoo.co.uk Thu May 15 07:30:33 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Thu, 15 May 2014 04:30:33 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> <167bfe35-c36b-4d9d-8bd3-810015b24af6@googlegroups.com> Message-ID: <85a05ee8-9f79-4cd2-875f-4926d11e9639@googlegroups.com> Dear Programmers, I noticed a couple of typos in my previous message, so have now altered them thus :- Dear Programmers, As anticipated, it has not been to long before I have encountered further difficulty. At the top of page 16 of 'Getting Started with Beautiful Soup" it gives code to be input, whether to the Python or Windows command prompt I am not sure, but both seem to be resistant to it. I quote the response to the code below, the code input being :- helloworld = "

Hello World

" soup_string = BeautifulSoup(helloworld) to Windows Command prompt this gives :- ---------------------------------------------------------------------------------- SyntaxError: invalid syntax >>> helloworld = "

HelloWorld

" >>> soup_string = BeautifulSoup(helloworld) Traceback (most recent call last): File "", line 1, in NameError: name 'BeautifulSoup' is not defined ---------------------------------------------------------------------------------- I have been told by one of the programmers, that I ought be inputting this to the Python command prompt (the book doesn't spacify), but that doesn't take either re:- ---------------------------------------------------------------------------------- >>>helloworld =

HelloWorld

" >>>soup_string = BeautifulSoup(helloworld) Traceback (most recent call last): File "", line 1, in NameError: name 'BeautifulSoup' is not defined >>> ---------------------------------------------------------------------------------- Looking at the bottom of page 16, there is more code for the inputting of, that again does not take to the Windows Command Prompt or the Python command prompt, re: import urllib2 from bs4 import BeautifulSoup url = "http://www.packtpub.com/books" page = urllib2.urlopen(url) soup_packtpage = BeautifulSoup(page) returns to the Windows Command prompt:- ---------------------------------------------------------------------------------- >>>import urllib2 Traceback (most recent call last): File "", line1, in ImportError: No module named 'urllib2' >>> ---------------------------------------------------------------------------------- returns to the Python command prompt :- ---------------------------------------------------------------------------------- >>> import urllib2 >>> from bs4 import BeautifulSoup >>> url = "http://www.packtpub.com/books" >>> page = urllib2.urlopen(url) Traceback (most recent call last): File "C\Python27\lib\urllib2.py",line 127, in urlopen return_opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py",line 410, in open response = meth(req, response) File "C:\Python27\lib\urllib2.py", oine 523, in http_response 'http', request, response, code, msg, hdrs) File"C:\Python27\lib\urllib2.py", line 448, in error return self._call_chain(*args) File "C:/Python27/lib/urllib2.py",line 382, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 531, in http_error_default raise HTTPError(req.get_full_url(), code, masg, hdrs, fp) urllib2.HTTPError: HTTP Error 403: Forbidden --------------------------------------------------------------------------------- Anway I hope you can tell me what is amiss, there is no point in my proceeding with the book (about 111 pages all told) until I find out why it won't take. I realise I have been told to learn python in order to make things less painful, but I don't see why code written in the book does not take. Thank you for reading. From davea at davea.name Thu May 15 08:12:39 2014 From: davea at davea.name (Dave Angel) Date: Thu, 15 May 2014 08:12:39 -0400 Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: <85a05ee8-9f79-4cd2-875f-4926d11e9639@googlegroups.com> References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> <167bfe35-c36b-4d9d-8bd3-810015b24af6@googlegroups.com> <85a05ee8-9f79-4cd2-875f-4926d11e9639@googlegroups.com> Message-ID: <5374AF37.4080202@davea.name> On 05/15/2014 07:30 AM, Simon Evans wrote: > Dear Programmers, I noticed a couple of typos in my previous message, so have now altered them thus :- > > Dear Programmers, > As anticipated, it has not been to long before I have encountered further > > difficulty. Your first thread was about getting Beautiful Soup installed and working. If you can successfully import it, you're ready for a new thread, new subject line, etc. Note the new thread's opener should be self-contained, meaning you should mention the environment (version of BS, version of Python, version of what OS), and your difficulty. > At the top of page 16 of 'Getting Started with Beautiful Soup" it > > gives code to be input, whether to the Python or Windows command prompt I am not > My guess is that the book is now describing what goes in a program, not at the "command prompts". A program is typically written in a text file, not at the interpreter prompt, though experimentation is certainly done there. Once you have a program in a text file (usually with the extension .py), you run it at the OS terminal prompt by typing: python myprogram.py -- DaveA From davea at davea.name Thu May 15 08:16:19 2014 From: davea at davea.name (Dave Angel) Date: Thu, 15 May 2014 08:16:19 -0400 Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <5374070A.5020308@islandtraining.com> Message-ID: <5374B013.5080908@davea.name> On 05/14/2014 10:12 PM, Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> I still remember the cry of anguish when the guy in the computer >> building at (the then) Portsmouth Polytechnic dropped his cardboard box >> of punch cards that made up his end of course project. > > That's why you punch sequence numbers in columns 73-80. If the cards > get out of order, just run the deck through the sorter. > And of course, don't forget to increment them by 10's, so you can insert new cards without resequencing the remainder. I recall having to buy two tapes, because the operators were very resistant to taking several boxes of cards at one shot. (A box was 2000 cards) At that point, the card decks were instructions to the editor, how to turn the version of the code on tape1 into the new version, to be written to tape2. (And on every run, don't forget to reverse the lines describing which tape is tape1 and which is tape2.) -- DaveA From rustompmody at gmail.com Thu May 15 08:17:57 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 15 May 2014 05:17:57 -0700 (PDT) Subject: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions. In-Reply-To: References: <10313d81-01f2-48ed-951c-a5a6cccee65e@googlegroups.com> <7a908d5e-1e0e-4828-a3e0-172df735e6c3@googlegroups.com> <1ade4a7c-833c-44eb-982a-3e17ccbc64b1@googlegroups.com> <7b33a525-58ee-4009-94c4-f9ed69eb3af0@googlegroups.com> <81acc9a1-f3d5-4379-9b29-1be4966f6c35@googlegroups.com> <167bfe35-c36b-4d9d-8bd3-810015b24af6@googlegroups.com> Message-ID: On Thursday, May 15, 2014 4:55:42 PM UTC+5:30, Simon Evans wrote: > Dear Programmers, > > As anticipated, it has not been to long before I have encountered further > > difficulty. At the top of page 16 of 'Getting Started with Beautiful Soup" it > > gives code to be input, whether to the Python or Windows command prompt I am not > > sure, but both seem to be resistant to it. I quote the response to the code below, It was because I thought I saw such a mixup in your earlier posts that I suggested you start with the python tutorial :-) > Looking at the bottom of page 16, there is more code for the inputting of, that > > > > again does not take to the Windows Command Prompt or the Python command prompt, > > re: import urllib2 > > from bs4 import BeautifulSoup You probably need the above line And you need to preceded the other lines at the python (not shell) prompt On the whole it may be a good idea to put aside the book and just follow the quick start http://www.crummy.com/software/BeautifulSoup/bs4/doc/#quick-start at the python prompt > > url = "http://www.packtpub.com/books" > > page = urllib2.urlopen(url) > > soup_packtpage = BeautifulSoup(page) > > > > returns to the Windows Command prompt:- > > ---------------------------------------------------------------------------------- > > >>>import urllib2 > > Traceback (most recent call last): > > File "", line1, in > > ImportError: No module named 'urllib2' > > >>> > > > > ---------------------------------------------------------------------------------- > > returns to the Python command prompt :- > > ---------------------------------------------------------------------------------- > > >>> import urllib2 > > >>> from bs4 import BeautifulSoup > > >>> url = "http://www.packtpub.com/books" > > >>> page = urllib2.urlopen(url) > > Traceback (most recent call last): > > File "C\Python27\lib\urllib2.py",line 127, in urlopen > > return_opener.open(url, data, timeout) > > File "C:\Python27\lib\urllib2.py",line 410, in open > > response = meth(req, response) > > File "C:\Pyton27\lib\urllib2.py", oine 523, in http_response > > 'http', request, response, code, msg, hdrs) > > File"C:\Python27\lib\urllib2.py", line 448, in error > > return self._call_chain(*args) > > File "C:/Python27/lib/urllib2.py",line 382, in _call_chain > > result = func(*args) > > File "C:\Python27\lib\urllib2.py", line 531, in http_error_default > > raise HTTPError(req.get_full_url(), code, masg, hdrs, fp) > > urllib2.HTTPError: HTTP Error 403: Forbidden > > --------------------------------------------------------------------------------- > > Anway I hope you can tell me what is amiss, there is no point in my proceeding > > > > with the book (about 111 pages all told) until I find out why it won't take. > > I realise I have been told to learn python in order to make things less painful, > > > > but I don't see why code written in the book does not take. > > Thank you for reading. > > > > > > > > > > > > I thought I might as well include, so's you might be able to see where things are > > > > going astray. The Windows command prompt :- From dfnsonfsduifb at gmx.de Thu May 15 08:32:03 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 15 May 2014 14:32:03 +0200 Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> Message-ID: On 15.05.2014 04:43, Ben Finney wrote: > Rustom Mody writes: > >> Until then may we relegate '79' to quaint historical curiosities > > Not until the general capacity of human cognition advances to make > longer lines easier to read. I find it surprising how you can make such a claim about the whole of humanity (!) without even feeling the need to have a pro forma study to back it up. Also, not everything that applies to prose also equally applies to code. Personally I find overly narrow code (80 cols) to be much *harder* to read than code that is 100 cols wide. Keep in mind that even if the break is at 100 cols, lines will rarely exceed that limit. And if they do to *understand* the code, the further down the line it is the less important are the details usually. I don't know why anyone would force a display issue onto everyone. It imples the arrogant stance that every human being has the exact way of reading and writing code. Everyone can configure her editor to what she wants (including line breaks and such). If people were to force pixel sizes of editor fonts, everyone would immediately recognize what a stupid idea this would be. Even though I could claim that the vertical formatting is all messed up when you don't display my code with the correct font size! Ridiculous, right? Regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From cx63 at outlook.com Thu May 15 08:34:46 2014 From: cx63 at outlook.com (GuoChao) Date: Thu, 15 May 2014 20:34:46 +0800 Subject: struct.unpack: why 's' fmt char convert to bytestring In-Reply-To: <1613032089421800145.832800sturla.molden-gmail.com@news.gmane.org> References: , <87mweotfe5.fsf@dpt-info.u-strasbg.fr>, <87iopbtmh1.fsf@dpt-info.u-strasbg.fr>, <871tvxtwgj.fsf@dpt-info.u-strasbg.fr>, <8761l9pi3n.fsf@elektro.pacujo.net>, <5372b488$0$29977$c3e8da3$5496439d@news.astraweb.com>, , <1613032089421800145.832800sturla.molden-gmail.com@news.gmane.org> Message-ID: The Python documentation gives this same example:>>> record = b'raymond \x32\x12\x08\x01\x08' >>> name, serialnum, school, gradelevel = unpack('<10sHHb', record) but get different results as to 's', don't know why this change in Python 3? need extra work to encode...>>> name >>> 'raymond ' # for 2.7>>> name >>> b'raymond ' # for 3.3 -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Thu May 15 09:07:54 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 15 May 2014 16:07:54 +0300 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> Message-ID: <87a9ajb36d.fsf@elektro.pacujo.net> Johannes Bauer : > I don't know why anyone would force a display issue onto everyone. Well, if I have to work with your code, you are forcing your style on me. > It imples the arrogant stance that every human being has the exact way > of reading and writing code. Everyone can configure her editor to what > she wants (including line breaks and such). That's a good point: why aren't we just exchanging AST's and configuring the editor to display them in our preferred format? Well, we're not there yet. Objective readability is not the main issue here, IMO. It's the screen estate. I know the idea of "windows" is fast disappearing from modern ("mobile") computing; you have "apps" instead that commandeer the whole screen. Personally, I find that a big step backwards. I want to be able to subdivide the screen for many windows that represent different contexts and tasks. Marko From rosuav at gmail.com Thu May 15 09:27:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 May 2014 23:27:26 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> Message-ID: On Thu, May 15, 2014 at 10:32 PM, Johannes Bauer wrote: > Personally I find overly narrow code (80 cols) to be much *harder* to > read than code that is 100 cols wide. Keep in mind that even if the > break is at 100 cols, lines will rarely exceed that limit. And if they > do to *understand* the code, the further down the line it is the less > important are the details usually. The limit of human readability is generally given to be somewhere in the range of 60-120. It's not a single specific value that's exactly the same for everyone; personally, I like my lines of code to be a bit longer than 80, and will happily go to 90-100, but in the interests of interoperability, it's helpful to standardize on one common value - especially for large shared codebases. You're arguing against the specific value of 80, but 100 is still pretty close to that. There are two key boundaries: the point at which your eye can no longer comfortably read the text, and the point at which you need to scroll horizontally. The latter of course depends on your screen, but it's an EXTREMELY important barrier; the former is the "soft" boundary, as you won't instantly know when you're over it. (The two can be in either order, of course. I could easily read 90 char lines, but if I'm in a standard 80x24-25 terminal window, that's going to scroll.) Both boundaries are almost certainly exceeded by a 500-character line; if you're doing your code like that, you obviously do not want anyone reading it. [1] Whether you cut it off at 70, 80, 100, or some other figure, you still want to put some kind of limit on it. ChrisA [1] That doesn't mean "never do this". I've sometimes had code with insanely long lines - for instance, an auto-generated list of names - and it wasn't meant to be human-readable. Breaking it onto multiple lines would have complicated matters unnecessarily, and if you wanted to read the code, you should be reading the other file anyway. From rosuav at gmail.com Thu May 15 09:31:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 May 2014 23:31:44 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: <87a9ajb36d.fsf@elektro.pacujo.net> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> Message-ID: On Thu, May 15, 2014 at 11:07 PM, Marko Rauhamaa wrote: > I know the idea of "windows" is fast disappearing from modern > ("mobile") computing; you have "apps" instead that commandeer the whole > screen. Personally, I find that a big step backwards. I want to be able > to subdivide the screen for many windows that represent different > contexts and tasks. Duh! :) I'm currently working on Sikorsky (all my computers have names, of course), with six Xfce workspaces. On those, my text editor (SciTE) and MUD client (Gypsum) are set to "Always on visible workspace"; everything else is whereever I choose to put it (VMs on workspace 2, most of my primary activity on workspace 3, Alice: Madness Returns on workspace 6, etc). Each workspace is subdivided into approximately five million terminal windows, because that's what I do everything with :) One web browser window, or maybe two; occasional other stuff; but mainly, lots and lots of terminals. I can't imagine trying to get any serious work done without loading up multiple consoles, some of them SSH'd to other boxes, and being able to copy and paste between them. The Windows 8 / Unity / GNOME 3 model annoys me greatly. Can't get work done like that. ChrisA From alister.nospam.ware at ntlworld.com Thu May 15 09:38:57 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 15 May 2014 13:38:57 GMT Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> Message-ID: On Thu, 15 May 2014 23:31:44 +1000, Chris Angelico wrote: > The Windows 8 / Unity / GNOME 3 model annoys me greatly. Can't get work > done like that. > > ChrisA Windows 8/ Unity/ Gnome 3 are great on tablets (at least they look like they should be the only one I can confirm is Win 8) but lousy on a full pc with keyboard (Mouse optional) I am with you & use either LXDE or XFCE or run level 3 on all of my systems. -- Q: What do you call 50 Microsoft products at the bottom of the ocean? A: A darned good start. From rosuav at gmail.com Thu May 15 09:44:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 May 2014 23:44:34 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> Message-ID: On Thu, May 15, 2014 at 11:38 PM, alister wrote: > On Thu, 15 May 2014 23:31:44 +1000, Chris Angelico wrote: >> The Windows 8 / Unity / GNOME 3 model annoys me greatly. Can't get work >> done like that. >> >> ChrisA > Windows 8/ Unity/ Gnome 3 are great on tablets (at least they look like > they should be the only one I can confirm is Win 8) but lousy on a full > pc with keyboard (Mouse optional) > > I am with you & use either LXDE or XFCE or run level 3 on all of my > systems. Sorry, I should clarify that I'm talking about desktop systems here. I have no idea how good those UIs are on actual tablets; my beef with them is that putting a tablet UI on a desktop is just as much a bad idea as putting a desktop UI on a tablet. When I have a 1920x1080 display on a screen that's about a meter wide, running a single application is seldom what I want to do. ChrisA From davea at davea.name Thu May 15 09:49:13 2014 From: davea at davea.name (Dave Angel) Date: Thu, 15 May 2014 09:49:13 -0400 Subject: struct.unpack: why 's' fmt char convert to bytestring In-Reply-To: References: , <87mweotfe5.fsf@dpt-info.u-strasbg.fr>, <87iopbtmh1.fsf@dpt-info.u-strasbg.fr>, <871tvxtwgj.fsf@dpt-info.u-strasbg.fr>, <8761l9pi3n.fsf@elektro.pacujo.net>, <5372b488$0$29977$c3e8da3$5496439d@news.astraweb.com>, , <1613032089421800145.832800sturla.molden-gmail.com@news.gmane.org> Message-ID: <5374C5D9.4060409@davea.name> On 05/15/2014 08:34 AM, GuoChao wrote: > The Python documentation gives this same example:>>> record = b'raymond \x32\x12\x08\x01\x08' >>>> name, serialnum, school, gradelevel = unpack('<10sHHb', record) > but get different results as to 's', don't know why this change in Python 3? need extra work to encode...>>> name >>>> 'raymond ' # for 2.7>>> name >>>> b'raymond ' # for 3.3 >>>> >>>> Please start a new thread, don't just change the subject and hope to hijack this existing thread on Fortran. But you also need a problem statement. What is it you're having trouble with? Do you have some code that works differently in 3.3 and you want to know how to fix it? If so, show what you've tried, what resulted, and what you expected instead. Please post in text form. This is a text list, and many people cannot see your html at all. Others see it as improperly wrapped, which thoroughly masks what you're trying to do. Even when I show it as html, it doesn't make sense. Perhaps you're trying to retype the stuff, rather than copy/pasting it from your terminal window. I could comment on individual portions of your query, but hopefully when you get one that's better organized, that won't be necessary. -- DaveA From rustompmody at gmail.com Thu May 15 09:53:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 15 May 2014 06:53:27 -0700 (PDT) Subject: PEP 8 : Maximum line Length : In-Reply-To: <87a9ajb36d.fsf@elektro.pacujo.net> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> Message-ID: <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> On Thursday, May 15, 2014 6:37:54 PM UTC+5:30, Marko Rauhamaa wrote: > Johannes Bauer : > > > > I don't know why anyone would force a display issue onto everyone. > > > Well, if I have to work with your code, you are forcing your style on > me. > > > > It imples the arrogant stance that every human being has the exact way > > of reading and writing code. Everyone can configure her editor to what > > she wants (including line breaks and such). > > > That's a good point: why aren't we just exchanging AST's and configuring > the editor to display them in our preferred format? > > Well, we're not there yet. Yes, regarding programmers using plain-text instead of hypertext at http://blog.languager.org/2012/10/html-is-why-mess-in-programming-syntax.html I wrote: And yet programmers continue to be decades behind all other users of computers. We continue to use flat text for our programs when all others have moved on. From roy at panix.com Thu May 15 09:58:01 2014 From: roy at panix.com (Roy Smith) Date: Thu, 15 May 2014 09:58:01 -0400 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> Message-ID: In article <78ac407a-c429-4a7a-93c9-5d83e0f09cbb at googlegroups.com>, Rustom Mody wrote: > And yet programmers continue to be decades behind all other users of > computers. We continue to use flat text for our programs when all others > have moved on. It's not like we haven't tried. There have been a few attempts at using richer media to program (graphical UML editors, for example). They've all pretty much been failures. There *are* some places where non-text programming has won. The biggest example would be GUI builders. Nobody programs screen and window layouts by typing textual descriptions. They push boxes around in a GUI builder. From rustompmody at gmail.com Thu May 15 09:58:53 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 15 May 2014 06:58:53 -0700 (PDT) Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> Message-ID: On Thursday, May 15, 2014 6:57:26 PM UTC+5:30, Chris Angelico wrote: > The limit of human readability is generally given to be somewhere in > the range of 60-120. It's not a single specific value that's exactly > the same for everyone; personally, I like my lines of code to be a bit > longer than 80, and will happily go to 90-100, but in the interests of > interoperability, it's helpful to standardize on one common value - > especially for large shared codebases. > > You're arguing against the specific value of 80, but 100 is still > pretty close to that. There are two key boundaries: the point at which > your eye can no longer comfortably read the text, and the point at > which you need to scroll horizontally. The latter of course depends on > your screen, but it's an EXTREMELY important barrier; the former is > the "soft" boundary, as you won't instantly know when you're over it. > Thanks Chris for some sanity As far as I can see the votaries of the mystical 79 have yet to explain how/where it appeared from JFTR the OP asked how to shorten a line and the shortest so far is what I suggested From rosuav at gmail.com Thu May 15 10:14:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 May 2014 00:14:15 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> Message-ID: On Thu, May 15, 2014 at 11:58 PM, Roy Smith wrote: > There *are* some places where non-text programming has won. The biggest > example would be GUI builders. Nobody programs screen and window > layouts by typing textual descriptions. They push boxes around in a GUI > builder. Hi, I'm Nobody, and I like warm hugs! My GUI building is entirely by typing textual descriptions. Yes, there are some good builders, but I do my layouts on a basis of rules rather than strict pixel positions. Rules and bag-based layouts mean there's no problem with something getting too big and messing up your layout. Is it really helpful to drag objects into a nearly-invisible "Vertical Box" container? Pushing boxes around is great when you attach everything directly to the window, but that gets messed up pretty quickly by a user's themes, font sizes, etc (not to mention a change of platform). Explicitly putting things into their boxes, grids, tables, etc means it's always right. ChrisA From marko at pacujo.net Thu May 15 10:12:57 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 15 May 2014 17:12:57 +0300 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> Message-ID: <8761l7b05y.fsf@elektro.pacujo.net> Rustom Mody : > We continue to use flat text for our programs when all others have > moved on. My more moderate and immediate point is, why should the physical encoding of the program be also the presentation format? A definitive Python source file could be binary, XML, .py, .ast, whatever, and that would also be the file fed to the Python compiler/interpreter. However, your editor could choose freely how to present it to you. IOW, shouldn't PEP8 be redundant? Marko From rustompmody at gmail.com Thu May 15 10:15:18 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 15 May 2014 07:15:18 -0700 (PDT) Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> Message-ID: On Thursday, May 15, 2014 7:28:01 PM UTC+5:30, Roy Smith wrote: > > Rustom Mody wrote: > > > > > And yet programmers continue to be decades behind all other users of > > computers. We continue to use flat text for our programs when all others > > have moved on. > > > > It's not like we haven't tried. There have been a few attempts at using > richer media to program (graphical UML editors, for example). They've > all pretty much been failures. > In Fifth Discipline, Peter Senge starts by dilating on the length of time between 1903 when the Wright brothers first flew and 1935 when the DC-3 ushered in commercial air travel. Five things were needed for that transition from pioneering to commercial: | They were: the variable-pitch propeller, retractable landing gear, a type of | lightweight molded body construction called "monocque," radial air-cooled | engine, and wing flaps. To succeed, the DC-3 needed all five; four were not | enough. One year earlier, the Boeing 247 was introduced with all of them except | wing flaps. Lacking wing flaps, Boeing's engineers found that the plane was | unstable on take-off and landing and had to downsize the engine. So maybe you are just being pessimistic when in fact we are in the (equivalent of) that 30 year period? Two more examples: Dijkstra pointed out that it typically takes an idea a hundred years from discovery to mainstream. Think Cantor inventing set theory in 1880s, modern math entering schools in 1970s. A more extreme example: Europeans learnt first of Hindu-Arabic numerals in around 1000 AD. IT took a good 500 years to give up on Roman numerals > > > There *are* some places where non-text programming has won. The biggest > example would be GUI builders. Nobody programs screen and window > layouts by typing textual descriptions. They push boxes around in a GUI > builder. And yet you routinely find people on this list recommending writing python to using a GUI-builder. On the one hand I am tempted to say "Sheesh!!" On the other, maybe the builders are still too half-assed... Dunno [BTW is there any equivalent for html?] From wxjmfauth at gmail.com Thu May 15 10:17:03 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 15 May 2014 07:17:03 -0700 (PDT) Subject: PEP 8 : Maximum line Length : In-Reply-To: References: Message-ID: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> Le mardi 13 mai 2014 10:45:49 UTC+2, Peter Otten a ?crit?: > Ganesh Pal wrote: > > > > > Hi Team , > > > > > > > > > what would be the best way to intent the below line . > > > > > > I have few lines in my program exceeding the allowed maximum line Length > > > of 79./80 characters > > > > > > Example 1 : > > > > > > p = > > > > > Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) > > > > > > > > > Iam running pylint and it says the above line is tool long how do I limit > > > it to 79 character without violating any rules > > > > > > ************* Module isi_corrupt > > > C: 14,0: Line too long (88/80) > > > W: 19,0: Bad indentation. Found 6 spaces, expected 8 > > > > (1) Newlines are allowed inside an open (, [, or {. So: > > > > p = subprocess.Popen( > > shlex.split(cmd), > > stdout=subprocess.PIPE, > > stderr=subprocess.PIPE) > > > > Other techniques: > > > > (2) Introduce helper variables: > > > > cmd = shlex.split(cmd) > > p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > > > (3) Import names: > > > > from subprocess import PIPE > > p = subprocess.Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE) > > > > (4) Use aliases: > > > > import subprocess as sp > > p = sp.Popen(shlex.split(cmd), stdout=sp.PIPE, stderr=sp.PIPE) ===== One another trick is to drop spaces around keywords >>> 99999and 12345or 9999999999if 'a'in'a' else 88888888or 777777 12345 and pray, the tools from those who are wasting their time in writing code analyzers or syntax colorizers or doc strings collectors or ... are finally working. Depending of the tools the interpretation may vary, but definitely all are producing erroneous results. jmf From rosuav at gmail.com Thu May 15 10:24:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 May 2014 00:24:20 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: <8761l7b05y.fsf@elektro.pacujo.net> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <8761l7b05y.fsf@elektro.pacujo.net> Message-ID: On Fri, May 16, 2014 at 12:12 AM, Marko Rauhamaa wrote: > A definitive Python source file could be binary, XML, .py, .ast, > whatever, and that would also be the file fed to the Python > compiler/interpreter. However, your editor could choose freely how to > present it to you. > > IOW, shouldn't PEP8 be redundant? I believe the Python interpreter happily accepts a zip file, which in theory could be edited directly by a competent text editor. But that has nothing to do with PEP 8. Compare a classic compiled language like C - you have the bit you edit (the C source code) and the "definitive version" that's fed to the program loader (the compiled binary). Style guides apply to the edited version, not to the executed version. ChrisA From rosuav at gmail.com Thu May 15 10:27:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 May 2014 00:27:16 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> References: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> Message-ID: On Fri, May 16, 2014 at 12:17 AM, wrote: > One another trick is to drop spaces around keywords > >>>> 99999and 12345or 9999999999if 'a'in'a' else 88888888or 777777 > 12345 > > and pray, the tools from those who are wasting their time in > writing code analyzers or syntax colorizers or doc strings > collectors or ... are finally working. Depending of the tools > the interpretation may vary, but definitely all are producing > erroneous results. Yes. Another very effective way to get your code below 80 characters is to shorten all names to a single letter. Since you don't need to restrict yourself to monocase Roman letters (as I had to in my earliest programming days, in BASIC), it's actually quite practical to uniquely name everything in a single character; you could save enormous amounts of horizontal space. Then, aggressively "import as" to do the same with remote symbols (you might need two characters for those), and you'll be able to write everything in just a few tight symbols! ChrisA From marko at pacujo.net Thu May 15 10:29:51 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 15 May 2014 17:29:51 +0300 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> Message-ID: <87y4y39ktc.fsf@elektro.pacujo.net> Rustom Mody : > And yet you routinely find people on this list recommending writing > python to using a GUI-builder. On the one hand I am tempted to say > "Sheesh!!" On the other, maybe the builders are still too > half-assed... Dunno That's like diagnosing cancer without invasive procedures, lab tests and interviews: the doctor should be able to look at how pale you look and if your skin has any funny bulges. Thing is, programs and even text documents and spreadsheets have a lot more abstract structure, dynamics and dependencies than the visible fa?ade. Block diagrams and graphics can be great presentation tools, but nothing beats text in concise, explicit expressiveness. An everyday example: a word processor displays the word "hello" with "hel" in boldface and "lo" in italics. You put the cursor between the l's and type a letter. Should it be in boldface or italics? Who of you hasn't sworn at a Web editor that gets the formatting all messed up when you have typed a backspace in the "wrong place?" Marko From skip at pobox.com Thu May 15 10:38:23 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 15 May 2014 09:38:23 -0500 Subject: PEP 8 : Maximum line Length : In-Reply-To: <87y4y39ktc.fsf@elektro.pacujo.net> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <87y4y39ktc.fsf@elektro.pacujo.net> Message-ID: On Thu, May 15, 2014 at 9:29 AM, Marko Rauhamaa wrote: > Who of you hasn't sworn at a Web editor that gets the formatting all > messed up when you have typed a backspace in the "wrong place?" My current pet peeve is the Gmail composition pane. What a load of crap (especially in rich text mode). You set the font to Sans Serif, start typing. Everything is in Courier. Select All, switch everything to Sans Serif, and it redraw the text, still in Courier, but in a different version of Courier. Switch back to plain text mode. It has not-too-helpfully inserted line breaks everywhere the rich text editor surrounded text with
tags. Go back and delete all of them. Edit your text. Proofread your text. Switch back to rich text so you can insert the image you wanted to display. Hit Send. Haven't we had WYSIWYG editors for about 40 years? Skip From marko at pacujo.net Thu May 15 10:36:10 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 15 May 2014 17:36:10 +0300 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <8761l7b05y.fsf@elektro.pacujo.net> Message-ID: <87tx8r9kit.fsf@elektro.pacujo.net> Chris Angelico : > I believe the Python interpreter happily accepts a zip file, which in > theory could be edited directly by a competent text editor. But that > has nothing to do with PEP 8. Compare a classic compiled language like > C - you have the bit you edit (the C source code) and the "definitive > version" that's fed to the program loader (the compiled binary). Style > guides apply to the edited version, not to the executed version. My point applies to C as well. Shouldn't the .c file contain an AST? Only when you open the file in your text editor, it makes it look like you wrote it yourself in your favorite style? You and I could have opened the same C file. Only you see: #include int +--------------------+ main ( int argc, | My first C program | char *const argv[] ) +--------------------+ { (void) printf( "Hello world\n" ); return(0); } while I see: #include /* My first C program */ int main(int argc, char *const argv[]) { printf("Hello world\n"); return 0; } Marko From rosuav at gmail.com Thu May 15 10:42:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 May 2014 00:42:41 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: <87y4y39ktc.fsf@elektro.pacujo.net> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <87y4y39ktc.fsf@elektro.pacujo.net> Message-ID: On Fri, May 16, 2014 at 12:29 AM, Marko Rauhamaa wrote: > An everyday example: a word processor displays the word "hello" with > "hel" in boldface and "lo" in italics. You put the cursor between the > l's and type a letter. Should it be in boldface or italics? Impossible to say, and one of the perpetual annoyances. Here's a web site that I host: http://gilbertandsullivan.org.au/index.php?option=com_content&view=article&id=92:2001-patience&catid=30:patience&Itemid=102 (Tiny URL: http://tinyurl.com/pphpkuk ) Why is "Lt Duke of Dunstable" different from all the other character names? (By the way, I just picked an article at random from the archive, and the first random pick had an example of what I'm talking about. It's fairly prevalent on that site.) Now, if this were hand-written HTML2, this sort of thing wouldn't happen; and, even better, if the structure and formatting were properly separated (as in my proposed web site redesign), they'd not only be guaranteed consistent within a page, but also *across* pages. Tagged text works well. In HTML pages, that means literal ; in programming, that's all our various notations and things. I wouldn't want to write code by writing a bunch of words and then marking "This word is an assignment target, this one is an object that you should find a method on, this one is the method name, and these ones are the arguments". I want to put = . ( ) to mark those. More efficient... MUCH more reliable. And, bonus: it's all text. ChrisA From python at mrabarnett.plus.com Thu May 15 10:47:58 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 15 May 2014 15:47:58 +0100 Subject: struct.unpack: why 's' fmt char convert to bytestring In-Reply-To: References: , <87mweotfe5.fsf@dpt-info.u-strasbg.fr>, <87iopbtmh1.fsf@dpt-info.u-strasbg.fr>, <871tvxtwgj.fsf@dpt-info.u-strasbg.fr>, <8761l9pi3n.fsf@elektro.pacujo.net>, <5372b488$0$29977$c3e8da3$5496439d@news.astraweb.com>, , <1613032089421800145.832800sturla.molden-gmail.com@news.gmane.org> Message-ID: <5374D39E.4020002@mrabarnett.plus.com> On 2014-05-15 13:34, GuoChao wrote: > T he Python > documentation gives this same example: > >>>>record = b'raymond\x32\x12\x08\x01\x08' >>>>name, serialnum, school, gradelevel = unpack('<10sHHb', record) > > but get different results as to 's', don't know why this change in > Python 3? need extra work to encode... > >>>>name >>>>'raymond ' #for 2.7 > >>>>name >>>>b'raymond ' #for _3.3 _ > They are actually the same result; they are both bytestrings (a string of bytes). In Python 2, the 'str' class is for bytestrings and the 'unicode' class is for Unicode strings, so 'abc' (or b'abc') is a bytestring and u'abc' is a Unicode string. In Python 3, the 'bytes' class is for bytestrings and the 'str' class is for Unicode strings, so b'abc' is a bytestring and 'abc' is a Unicode string. From rosuav at gmail.com Thu May 15 11:03:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 May 2014 01:03:47 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: <87tx8r9kit.fsf@elektro.pacujo.net> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <8761l7b05y.fsf@elektro.pacujo.net> <87tx8r9kit.fsf@elektro.pacujo.net> Message-ID: On Fri, May 16, 2014 at 12:36 AM, Marko Rauhamaa wrote: > You and I could have opened the same C file. Only you see: > > #include > > int +--------------------+ > main ( int argc, | My first C program | > char *const argv[] ) +--------------------+ > { > (void) printf( "Hello world\n" ); > > return(0); > } > > while I see: > > #include > > /* My first C program */ > int main(int argc, char *const argv[]) { > printf("Hello world\n"); > return 0; > } Well no, for two reasons. Firstly, I think the first one looks disgusting, so even if I had that feature, I wouldn't use it like that :) But more importantly: You can already do that sort of thing, and it's a bad idea. Maybe there aren't any text editors that can do it, but you can use source control that way. (I'm going to use git as my example, as I don't know how it's done in hg or any other; but I'm sure it won't be hard.) You just tell git that these files (probably "files matching glob *.c") are to be reformatted, and provide two commands: one that cleans a file prior to it going into source control, and one that "smudges" it at the other end. So you could simply write a code reformatter and register it as your smudge command, and (in the interests of readable diffs) have some standardized reformatter as the clean command. Voila! You now can check out my code with your formatting. Which brings me to the second reason for not doing this. That clean/smudge operation *destroys information*. Once you enforce code formatting like that, you violate PEP 8's "rule zero": sometimes, it's better to break the rules. Sometimes, your nice code reformatting operation will actually make the program worse... and there'll be no way for you to get back from that. Not to mention that any reformatting that inserts or deletes lines is a pain for debugging. "Line 42" on your screen and "Line 42" in the traceback won't be the same thing any more. If I run your code and give you an exception trace, you'll have to check out my version of the code to be able to understand anything. Theoretically that could be solved (eg you absolutely always run the checked-in version - of course, that assumes that everyone's smudge and clean will perfectly recreate the exact same output), but even with editor support, where you'd move the cursor around and the line number would go berserk (press down-arrow three times and the line number goes 5, 6, 6, 10), it would be a pain. Code is a text file. So is music (I use GNU LilyPond, and everything works like code). So is data, in many many cases. So is configuration, often, although some programs prefer to work with an opaque format. About the only thing that really definitely shouldn't be massaged into text is actual 2D images. Can you turn this into a few lines of code? https://lh3.googleusercontent.com/-_8upQkJcvjE/UhTJlDzW3ZI/AAAAAAAABU8/QvExuUq47dI/s512/DSCF7600.JPG Pretty much everything else, though, works better as plain text. ChrisA From wxjmfauth at gmail.com Thu May 15 11:48:38 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 15 May 2014 08:48:38 -0700 (PDT) Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> Message-ID: Le jeudi 15 mai 2014 16:27:16 UTC+2, Chris Angelico a ?crit?: > On Fri, May 16, 2014 at 12:17 AM, wrote: > > > One another trick is to drop spaces around keywords > > > > > >>>> 99999and 12345or 9999999999if 'a'in'a' else 88888888or 777777 > > > 12345 > > > > > > and pray, the tools from those who are wasting their time in > > > writing code analyzers or syntax colorizers or doc strings > > > collectors or ... are finally working. Depending of the tools > > > the interpretation may vary, but definitely all are producing > > > erroneous results. > > > > Yes. Another very effective way to get your code below 80 characters > > is to shorten all names to a single letter. Since you don't need to > > restrict yourself to monocase Roman letters (as I had to in my > > earliest programming days, in BASIC), it's actually quite practical to > > uniquely name everything in a single character; you could save > > enormous amounts of horizontal space. Then, aggressively "import as" > > to do the same with remote symbols (you might need two characters for > > those), and you'll be able to write everything in just a few tight ========= >>> 1or 0 1 >>> Short, but still a bug. 1 From breamoreboy at yahoo.co.uk Thu May 15 12:18:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 15 May 2014 17:18:31 +0100 Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> Message-ID: On 15/05/2014 14:58, Roy Smith wrote: > In article <78ac407a-c429-4a7a-93c9-5d83e0f09cbb at googlegroups.com>, > Rustom Mody wrote: > >> And yet programmers continue to be decades behind all other users of >> computers. We continue to use flat text for our programs when all others >> have moved on. > > It's not like we haven't tried. There have been a few attempts at using > richer media to program (graphical UML editors, for example). They've > all pretty much been failures. > This http://sourceforge.net/projects/doublesvsoop/ was project of the month just a little while ago, so it's obviously overcome all of the known obstacles, in exactly the same way that all previous silver bullets have done. At least I think it's the kind of thing that you're talking about. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From alister.nospam.ware at ntlworld.com Thu May 15 15:29:22 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 15 May 2014 19:29:22 GMT Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> Message-ID: On Thu, 15 May 2014 23:44:34 +1000, Chris Angelico wrote: > On Thu, May 15, 2014 at 11:38 PM, alister > wrote: >> On Thu, 15 May 2014 23:31:44 +1000, Chris Angelico wrote: >>> The Windows 8 / Unity / GNOME 3 model annoys me greatly. Can't get >>> work done like that. >>> >>> ChrisA >> Windows 8/ Unity/ Gnome 3 are great on tablets (at least they look like >> they should be the only one I can confirm is Win 8) but lousy on a full >> pc with keyboard (Mouse optional) >> >> I am with you & use either LXDE or XFCE or run level 3 on all of my >> systems. > > Sorry, I should clarify that I'm talking about desktop systems here. I > have no idea how good those UIs are on actual tablets; my beef with them > is that putting a tablet UI on a desktop is just as much a bad idea as > putting a desktop UI on a tablet. When I have a 1920x1080 display on a > screen that's about a meter wide, running a single application is seldom > what I want to do. > > ChrisA i think i was actually agreeing with you :-) -- Afternoon very favorable for romance. Try a single person for a change. From benjamin at schollnick.net Thu May 15 15:34:50 2014 From: benjamin at schollnick.net (Benjamin Schollnick) Date: Thu, 15 May 2014 15:34:50 -0400 Subject: Directory Caching, suggestions and comments? Message-ID: Folks, I am going to be using this code as part of a web system, and I would love any feedback, comments and criticism. Just as a side note, I'm not completely PEP 8. I know that, I use a slightly laxer setting in pylint, but I'm working my way up to it... I am using scandir from benhoyt to speed up the directory listings, and data collection. The module is here as well, https://dl.dropboxusercontent.com/u/241415/misc/directory_caching_v1.py I had considered using OrderedDicts, but I really didn't see how that would help the system. I'm not completely happy with the return_sort_* functions, since they return two different tuples, one goal was to try to keep everything in the dictionary, but I couldn't think of a better method. So any suggestions are welcome. - Benjamin ---- """ Directory Caching system. Used to cache & speed up directory listing. Preqs - Scandir - https://github.com/benhoyt/scandir scandir is a module which provides a generator version of os.listdir() that also exposes the extra file information the operating system returns when you iterate a directory. Generally 2-3 (or more) times faster than the standard library. (It's quite noticeable!) """ import os import os.path import re from stat import ST_MODE, ST_INO, ST_DEV, ST_NLINK, ST_UID, ST_GID, \ ST_SIZE, ST_ATIME, ST_MTIME, ST_CTIME import time import scandir plugin_name = "dir_cache" ##################################################### class CachedDirectory(object): """ For example: To be added shortly. """ def __init__(self): self.files_to_ignore = ['.ds_store', '.htaccess'] self.root_path = None # This is the path in the OS that is being examined # (e.g. /Volumes/Users/username/) self.directory_cache = {} def _scan_directory_list(self, scan_directory): """ Scan the directory "scan_directory", and save it to the self.directory_cache dictionary. Low Level function, intended to be used by the populate function. """ scan_directory = os.path.abspath(scan_directory) directories = {} files = {} self.directory_cache[scan_directory.strip().lower()] = {} self.directory_cache[scan_directory.strip().lower()]["number_dirs"] = 0 self.directory_cache[scan_directory.strip().lower()]["number_files"] = 0 for x in scandir.scandir(scan_directory): st = x.lstat() data = {} data["fq_filename"] = os.path.realpath(scan_directory).lower() + \ os.sep+x.name.strip().lower() data["parentdirectory"] = os.sep.join(\ os.path.split(scan_directory)[0:-1]) data["st_mode"] = st[ST_MODE] data["st_inode"] = st[ST_INO] data["st_dev"] = st[ST_DEV] data["st_nlink"] = st[ST_NLINK] data["st_uid"] = st[ST_UID] data["st_gid"] = st[ST_GID] data["compressed"] = st[ST_SIZE] data["st_size"] = st[ST_SIZE] #10 data["st_atime"] = st[ST_ATIME] #11 data["raw_st_mtime"] = st[ST_MTIME] #12 data["st_mtime"] = time.asctime(time.localtime(st[ST_MTIME])) data["st_ctime"] = st[ST_CTIME] if not x.name.strip().lower() in self.files_to_ignore: if x.is_dir(): self.directory_cache[scan_directory.strip().lower()]\ ["number_dirs"] += 1 data["archivefilename"] = "" data["filename"] = "" data["directoryname"] = x.name.strip().lower() data["dot_extension"] = ".dir" data["file_extension"] = "dir" directories[x.name.lower().strip()] = True self._scan_directory_list(data["fq_filename"]) data["number_files"] = self.directory_cache\ [data["fq_filename"]]["number_files"] data["number_dirs"] = self.directory_cache\ [data["fq_filename"]]["number_dirs"] directories[x.name.lower().strip()] = data else: self.directory_cache[scan_directory.strip().lower()]\ ["number_files"] += 1 data["archivefilename"] = "" data["filename"] = x.name.strip().lower() data["directoryname"] = scan_directory data["dot_extension"] = os.path.splitext\ (x.name)[1].lower() data["file_extension"] = os.path.splitext\ (x.name)[1][1:].lower() files[x.name.lower().strip()] = data self.directory_cache[scan_directory.strip().lower()]["files"] = files self.directory_cache[scan_directory.strip().lower()]\ ["dirs"] = directories self.directory_cache[scan_directory.strip().lower()]\ ["last_scanned_time"] = time.time() return def directory_in_cache(self, scan_directory): """ Pass the target directory Will return True if the directory is already cached Will return False if the directory is not already cached """ scan_directory = os.path.realpath(scan_directory).lower().strip() return scan_directory in self.directory_cache.keys() def directory_changed(self, scan_directory): """ Pass the target directory as scan_directory. Will return True if the directory has changed, or does not exist in cache. Returns False, if the directory exists in cache, and has not changed since the last read. This relies on the directory's Modified Time actually being updated since the last update. """ if self.directory_in_cache(scan_directory): scan_directory = os.path.realpath(scan_directory).lower().strip() st = os.stat(scan_directory) return st[ST_MTIME] > self.directory_cache[scan_directory]\ ["last_scanned_time"] else: return True def smart_read(self, scan_directory): """ This is a wrapper around the Read and changed functions. The scan_directory is passed in, converted to a normalized form, and then checked to see if it exists in the cache. If it doesn't exist (or is expired), then it is read. If it already exists *AND* has not expired, it is not updated. Net affect, this will ensure the directory is in cache, and update to date. """ scan_directory = os.path.realpath(scan_directory).lower().strip() if self.directory_changed(scan_directory): self._scan_directory_list(scan_directory) def return_sort_name(self, scan_directory, reverse=False): """ Return sorted list(s) from the Directory Cache for the Scanned directory, sorted by name. Returns 2 tuples of date, T[0] - Files, and T[1] - Directories which contain the data from the cached directory. """ scan_directory = os.path.realpath(scan_directory).lower().strip() files = self.directory_cache[scan_directory]["files"] dirs = self.directory_cache[scan_directory]["dirs"] sorted_files = sorted(files.items(), key=lambda t: t[1]["filename"], reverse=reverse) sorted_dirs = sorted(dirs.items(), key=lambda t: t[1]["directoryname"], reverse=reverse) return (sorted_files, sorted_dirs) def return_sort_lmod(self, scan_directory, reverse=False): """ Return sorted list(s) from the Directory Cache for the Scanned directory, sorted by Last Modified. Returns 2 tuples of date, T[0] - Files, and T[1] - Directories which contain the data from the cached directory. """ scan_directory = os.path.realpath(scan_directory).lower().strip() files = self.directory_cache[scan_directory]["files"] dirs = self.directory_cache[scan_directory]["dirs"] sorted_files = sorted(files.items(), key=lambda t: t[1]["raw_st_mtime"], reverse=reverse) sorted_dirs = sorted(dirs.items(), key=lambda t: t[1]["raw_st_mtime"], reverse=reverse) return (sorted_files, sorted_dirs) def return_sort_ctime(self, scan_directory, reverse=False): """ Return sorted list(s) from the Directory Cache for the Scanned directory, sorted by Creation Time. Returns 2 tuples of date, T[0] - Files, and T[1] - Directories which contain the data from the cached directory. """ scan_directory = os.path.realpath(scan_directory).lower().strip() files = self.directory_cache[scan_directory]["files"] dirs = self.directory_cache[scan_directory]["dirs"] sorted_files = sorted(files.items(), key=lambda t: t[1]["st_ctime"], reverse=reverse) sorted_dirs = sorted(dirs.items(), key=lambda t: t[1]["st_ctime"], reverse=reverse) return (sorted_files, sorted_dirs) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 15 15:49:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 May 2014 05:49:04 +1000 Subject: Directory Caching, suggestions and comments? In-Reply-To: References: Message-ID: On Fri, May 16, 2014 at 5:34 AM, Benjamin Schollnick wrote: > Just as a side note, I'm not completely PEP 8. I know that, I use a > slightly laxer setting in pylint, but I'm working my way up to it... > > I am using scandir from benhoyt to speed up the directory listings, and data > collection. First comment: You're running headlong into the two hardest problems in computing - cache invalidation, and naming things. (And off-by-one errors.) More specifically, and leaving aside the naming issue as you're aware of it, you have to cope with all sorts of messes of stale cache data. For instance, you stat a directory and depend on its mtime - you can't depend on that always being up-to-date, AND you can't rely on the clock not shifting. (What happens, for instance, if the server's onboard clock gains time at a notable rate, and a firewall misconfiguration is blocking NTP - and then you fix the firewall and the clock suddenly jumps backward by a few hours? Yep. Happened to me. Well, I think the clock jumped maybe half an hour, but it could easily have been a lot more.) What platform are you running this on? On all my Linux systems, the file system caches stat() info for me. That has never been a problem, because the FS knows when it needs to update/flush that cache. All I need to know is that having spare RAM means performance improves :) I can do a "sudo find / -name ..." and it chugs and chugs, and then I do it again and it's fast. Windows, not so nice, but I'd still look at OS or FS caching where possible. (Other platforms I don't personally use, so I don't know whether or not they have good caching.) ChrisA From pleasedontspam at isp.com Thu May 15 16:45:28 2014 From: pleasedontspam at isp.com (pleasedontspam at isp.com) Date: Thu, 15 May 2014 13:45:28 -0700 (PDT) Subject: Bug in Decimal?? In-Reply-To: References: <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com> Message-ID: On Sunday, May 4, 2014 6:53:06 AM UTC-4, Mark Dickinson wrote: > I had a quick look: this isn't a bug - it's just the result of propagation of > > the error in "partial" to "final". > > > > In more detail: we've got a working precision of 2016 significant figures. For > > any small x, we have (1 + x) / (1 - x) = 1 + 2x + 2x^2 + 2x^3 + .... For your > > value of x, `Decimal('1e-1007'), we've got enough precision to store > > 1 + 2x + 2x^2 exactly, but that's all. > > > > So partial has an absolute error of around 2x^3, or 2e-3021. > > > > And since the derivative of the natural log function is almost exactly 1 at the > > point we're interested in, we expect the absolute error in the output to be > > close to 2e-3021, too. > Please take a deeper look at my second post. Try the same but this time set the precision to 4000, 8000 or whatever you need to convince yourself there's no error propagation, yet there's a 4 in the middle that shouldn't be there. See for yourself! I've tested on all platforms I know of and confirmed it. The wrong digit occurs in the middle of the number. Propagation error would have a bad digit near the end, and garbage after that. Here there's a perfect sequence of numbers, but with one single digit changed in the middle of the number. No error propagation in a series expansion can do that. I generated a table of 1000 numbers, one correctly generated and one with mpdecimal. Then I did a diff of both files and it's horrible. The difference is all over the place, sometimes as high as digit 500 (out of 2000). Almost every result has the bad digit somewhere. The bad digit moves around a lot, from about position 500 to 2000. All other digits are correct, and in a 2000 digit sequence is hard to spot the difference (I used the visual diff tool that comes with TortoiseSVN or TortoiseGit). I think there's a bad pointer or something that's rounding the wrong digit. You cannot possibly have 1999 correct digits and only 1 changed on every number if it was propagation error. I'll follow up directly with the author of mpdecimal, as this is somewhat serious on a language that's so widely used as python. But please test it and confirm, am I seeing ghost digits? From harrismh777 at gmail.com Thu May 15 17:26:07 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 15 May 2014 16:26:07 -0500 Subject: Bug in Decimal?? References: <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com> Message-ID: On 5/15/14 3:45 PM, pleasedontspam at isp.com wrote: > Please take a deeper look at my second post. Try the same but this time > set the precision to 4000, 8000 or whatever you need to convince yourself > there's no error propagation, yet there's a 4 in the middle that shouldn't > be there. See for yourself! > I've tested on all platforms I know of and confirmed it. The wrong digit > occurs in the middle of the number. Propagation error would have a bad digit > near the end, and garbage after that. Here there's a perfect sequence of > numbers, but with one single digit changed in the middle of the number. > No error propagation in a series expansion can do that. > > I generated a table of 1000 numbers, one correctly generated and one with > mpdecimal. Then I did a diff of both files and it's horrible. The difference > is all over the place, sometimes as high as digit 500 (out of 2000). Almost > every result has the bad digit somewhere. The bad digit moves around a lot, > from about position 500 to 2000. All other digits are correct, and in a 2000 > digit sequence is hard to spot the difference (I used the visual diff tool > that comes with TortoiseSVN or TortoiseGit). I think there's a bad pointer > or something that's rounding the wrong digit. > You cannot possibly have 1999 correct digits and only 1 changed on every > number if it was propagation error. > I'll follow up directly with the author of mpdecimal, as this is somewhat > serious on a language that's so widely used as python. > > But please test it and confirm, am I seeing ghost digits? > I don't believe it. I've been running converging series to hudreds of thousands of decimal places (not only on different platforms, but on different BigFloat systmes, Jullia, BC, Decimal with pdeclib) and I'm not seeing the 'middle of the number' error you are talking about. I ran ? to over 100,000+ digits and compared between BC and Python Decimal with pilib pdeclib and both compared correct; also compared correct to the on-line standard. Soooo... not sure ... I can work on this some this weekend (comparing between Julia BigFloat and Python Decimal with pdeclib and see. I'm very skeptical at this point. marcus From tjreedy at udel.edu Thu May 15 17:50:20 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 May 2014 17:50:20 -0400 Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <87y4y39ktc.fsf@elektro.pacujo.net> Message-ID: On 5/15/2014 10:42 AM, Chris Angelico wrote: > Impossible to say, and one of the perpetual annoyances. Here's a web > site that I host: > > http://gilbertandsullivan.org.au/index.php?option=com_content&view=article&id=92:2001-patience&catid=30:patience&Itemid=102 > > (Tiny URL: http://tinyurl.com/pphpkuk ) > > Why is "Lt Duke of Dunstable" different from all the other character > names? For me, Windows FF, it is not different that I can see. -- Terry Jan Reedy From tjreedy at udel.edu Thu May 15 18:21:27 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 May 2014 18:21:27 -0400 Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> Message-ID: On 5/15/2014 9:58 AM, Rustom Mody wrote: > As far as I can see the votaries of the mystical 79 have yet to explain > how/where it appeared from As has been explained before, and is implied in the PEP, 79 = 80 - 1. 80 chars - 1 character width cursor leaves 79 non-cursor characters. When is hit, the cursor replaced with \n. So you can think of 79 as 79 visible + \n = 80. PEP 8 says "The limits are chosen to avoid wrapping in editors with the window width set to 80," and goes on about dynamic wrapping or not. To put is another way, all 80 char terminals work with 79 visible chars. Some but not all work with 80 visible, and some work with 80 on all lines except the last. I admit that this would have been clearer when most everyone reading it would have had some experience with 80 char sceens (including DOS). Still, did you really not notice that 79 = 80 - 1? -- Terry Jan Reedy From ben at benfinney.id.au Thu May 15 19:32:08 2014 From: ben at benfinney.id.au (Ben Finney) Date: Fri, 16 May 2014 09:32:08 +1000 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> Message-ID: <85ppje7h53.fsf@benfinney.id.au> Johannes Bauer writes: > On 15.05.2014 04:43, Ben Finney wrote: > > Rustom Mody writes: > > > >> Until then may we relegate '79' to quaint historical curiosities > > > > Not until the general capacity of human cognition advances to make > > longer lines easier to read. > > I find it surprising how you can make such a claim about the whole of > humanity (!) without even feeling the need to have a pro forma study > to back it up. This is an informal discussion forum. Merely because I don't produce citations every time I mention a fact doesn't imply that I'm not basing my assertions on fact. Here is one such study . But there is plenty of room for uninformed diverity of opinion . The point is less about hard evidence about *precise* limits; I make no claim about the superiority of 80 columns or 93 columns or 55 columns or whatever. Rather, the point is rather that human cognition *does* have limits, and those limits are at the basis of limits we choose to impose on text layout. Those who claim ?terminals just magically happened to be 80 columns wide and we were slaves to that limit? have it completely backward: the limits were imposed *onto* the terminals by human makers, based on their understanding of the cognitive limits of the humans reading from them. Those limits are with us still, and to my knowledge have not improved with recent human generations. > Also, not everything that applies to prose also equally applies to > code. If you're going to counter evidence of general human reading cognition by making special claims about code, that would need to be backed up with specific evidence. > Personally I find overly narrow code (80 cols) to be much *harder* to > read than code that is 100 cols wide. I counter your anecdote with my own: I find 80 columns to be quite long, and prefer code to be no more than around 60 columns. So what do we learn? That attempts to generalise from personal anecdote doesn't get us anywhere useful. -- \ ?I took a course in speed waiting. Now I can wait an hour in | `\ only ten minutes.? ?Steven Wright | _o__) | Ben Finney From python at mrabarnett.plus.com Thu May 15 20:05:54 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 May 2014 01:05:54 +0100 Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <87y4y39ktc.fsf@elektro.pacujo.net> Message-ID: <53755662.6010800@mrabarnett.plus.com> On 2014-05-15 22:50, Terry Reedy wrote: > On 5/15/2014 10:42 AM, Chris Angelico wrote: > >> Impossible to say, and one of the perpetual annoyances. Here's a web >> site that I host: >> >> http://gilbertandsullivan.org.au/index.php?option=com_content&view=article&id=92:2001-patience&catid=30:patience&Itemid=102 >> >> (Tiny URL: http://tinyurl.com/pphpkuk ) >> >> Why is "Lt Duke of Dunstable" different from all the other character >> names? > > For me, Windows FF, it is not different that I can see. > For me, with Firefox on Windows, it's slightly bolder, but that's probably because its colour is specified, unlike the others. From rustompmody at gmail.com Thu May 15 20:06:13 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 15 May 2014 17:06:13 -0700 (PDT) Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> Message-ID: <8f793d18-1160-401e-b56b-f467122565fc@googlegroups.com> On Friday, May 16, 2014 3:51:27 AM UTC+5:30, Terry Reedy wrote: > On 5/15/2014 9:58 AM, Rustom Mody wrote: > > > > As far as I can see the votaries of the mystical 79 have yet to explain > > how/where it appeared from > > > > As has been explained before, and is implied in the PEP, 79 = 80 - 1. > 80 chars - 1 character width cursor leaves 79 non-cursor characters. > When is hit, the cursor replaced with \n. So you can think of 79 > as 79 visible + \n = 80. > > > > PEP 8 says "The limits are chosen to avoid wrapping in editors with the > window width set to 80," and goes on about dynamic wrapping or not. To > put is another way, all 80 char terminals work with 79 visible chars. > Some but not all work with 80 visible, and some work with 80 on all > lines except the last. > > > > I admit that this would have been clearer when most everyone reading it > would have had some experience with 80 char sceens (including DOS). > Still, did you really not notice that 79 = 80 - 1? The claim being made is that 79/80 is a fundamental, cognitive limit and has no relation to technological changes. From ben at benfinney.id.au Thu May 15 20:21:21 2014 From: ben at benfinney.id.au (Ben Finney) Date: Fri, 16 May 2014 10:21:21 +1000 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <8f793d18-1160-401e-b56b-f467122565fc@googlegroups.com> Message-ID: <85lhu27ev2.fsf@benfinney.id.au> Rustom Mody writes: > The claim being made is that 79/80 is a fundamental, cognitive limit > and has no relation to technological changes. Who has made that claim, and where? You appear to be attacking a straw man. Rather, I've claimed that the conventional lime length limit is *based in* the real cognitive limits of human reading comprehension ? and that technologies have been designed with corresponding limitations. Nowhere have I claimed 79 or 80 are somehow fundamental or encoded in human cognition, and I have seen no-one else claim that. Please try to work within your own cognitive limits and read what people write for comprehension. -- \ ?As soon as we abandon our own reason, and are content to rely | `\ upon authority, there is no end to our troubles.? ?Bertrand | _o__) Russell, _Unpopular Essays_, 1950 | Ben Finney From steve+comp.lang.python at pearwood.info Thu May 15 20:21:31 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2014 00:21:31 GMT Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> Message-ID: <53755a0a$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 May 2014 16:07:54 +0300, Marko Rauhamaa wrote: > Johannes Bauer : > >> I don't know why anyone would force a display issue onto everyone. > > Well, if I have to work with your code, you are forcing your style on > me. +1 >> It imples the arrogant stance that every human being has the exact way >> of reading and writing code. Everyone can configure her editor to what >> she wants (including line breaks and such). > > That's a good point: why aren't we just exchanging AST's and configuring > the editor to display them in our preferred format? Oh, I hope not. Sometimes information is carried by the layout. For example, if I write a class: class Spam: def foo(self): ... def bar(self): ... def baz(self): ... def foobar(self): ... then without me saying anything, the reader should realise that foo, bar and baz, but not foobar, go together in a weak sense. If it were a strong sense, foobar ought to go into a separate class. A real example: writing getters and setters for property. Particularly if they are one or two line methods, I'll usually run them together with no separating blank lines to emphasize that they belong together. ASTs often don't include comments, so that's a problem. > Well, we're not there yet. > > Objective readability is not the main issue here, IMO. It's the screen > estate. I know the idea of "windows" is fast disappearing from modern > ("mobile") computing; you have "apps" instead that commandeer the whole > screen. Personally, I find that a big step backwards. Yes. In my opinion, mobile computing is a huge step backwards for personal control of your own hardware, usability, and power. In my opinion, people will look back at the first decade of the 21st century as the golden age of personal computing. -- Steven D'Aprano http://import-that.dreamwidth.org/ From cs at zip.com.au Thu May 15 20:25:20 2014 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 16 May 2014 10:25:20 +1000 Subject: Directory Caching, suggestions and comments? In-Reply-To: References: Message-ID: <20140516002520.GA30435@cskk.homeip.net> On 15May2014 15:34, Benjamin Schollnick wrote: >I am going to be using this code as part of a web system, and I would love >any feedback, comments and criticism. [...] >I am using scandir from benhoyt to speed up the directory listings, and >data collection. [...] >I had considered using OrderedDicts, but I really didn't see how that would >help the system. > >I'm not completely happy with the return_sort_* functions, since they >return two different tuples, one goal was to try to keep everything in the >dictionary, but I couldn't think of a better method. > >So any suggestions are welcome. Firstly, I'm with ChrisA on the whole: let the filesystem/OS do the stat caching. It _is_ actually slower to rely on this than an in-memory cache such as yours, but at least it is reliable because you will then have exactly the same file info state as any other user of the OS. Stale caches are a usability PITA for the end user; witness the continued presence of "Shift-Reload" in most browsers because browser (and proxy) caches get stale. His remark about relying on the mtime of a directory is correct also, and not just because of clock changes. On UNIX, the mtime of a directory changes _only_ when a filename is added/removed from the directory. To the point, it will not change if a file in the directory is just modified, and therefore your cache will become stale (and stay stale) in that circumstance. Of course, you wouldn't even be bothering with scandir if you were not concerned about relying of the filesystem/OS. So, it is your call about remembering this stuff. I would include a real-time staleness in addition to the mtime check, eg if the mtime is updated _or_ the system time says it is more than N seconds since the last directory scan, with N being smallish. Most of my other remarks have to do with style and implementation. >Preqs - > Scandir - https://github.com/benhoyt/scandir > scandir is a module which provides a generator version of > os.listdir() that also exposes the extra file information the > operating system returns when you iterate a directory. Personally, my habit is to use os.listdir() and accept the memory cost for two reasons: it is simple and the list is stable. If you iterate over a directory (eg via the C library readdir() facility) to my mind there is scope for the directory changing underneath you. A bit like iterating over a dictionary which is in active use by other code. Using os.listdir() minimises that window. So I'd be going: names = list(scandir(directory_path)) to get a snapshot, and then working with that list. >from stat import ST_MODE, ST_INO, ST_DEV, ST_NLINK, ST_UID, ST_GID, \ > ST_SIZE, ST_ATIME, ST_MTIME, ST_CTIME You don't need these. os.lstat() and os.stat() return stat objects, and they have convenient .st_mtime etc attributes. So all your: data["st_nlink"] = st[ST_NLINK] stuff can become: data["st_nlink"] = st.st_nlink I'd also be making your "data" object just an object, and assigning directory to an attribute on it, thus: data.st_nlink = st.st_nlink Much more readable. You could also avoid the entire issue of manually copying each st.st_blah attribute by just going: data.st = st Then just reach for data.st.st_mtime (or whatever) as needed. Short, quick, avoids needing to worry about optional stat fields - just keep the original stat result. >import time >import scandir > >plugin_name = "dir_cache" > >##################################################### >class CachedDirectory(object): > """ > For example: > > To be added shortly. It is _well_ work sketching this part out. Since this is just a cache, an example should be quite short. I find it enormously convenient to sketch some of the use cases here - it helps keep the required method names nicely defined. i.e. sketch a little code that you need to write, then write methods to support the code. You get a much better match that way. I often revisit classes when I use them, because I write some code using the class and think "that was very painful, how would I _like_ to have been able to use this"? > """ > def __init__(self): > self.files_to_ignore = ['.ds_store', '.htaccess'] > self.root_path = None You don't seem to use .root_path? > # This is the path in the OS that is being examined > # (e.g. /Volumes/Users/username/) > self.directory_cache = {} This is a CachedDirectory class. I would have just called this .cache - it will make all the code using it less wordy, and hopefully more readable. Unless there may be caches of other stuff too. This is almost entirely a matter of personal style though. > def _scan_directory_list(self, scan_directory): > """ > Scan the directory "scan_directory", and save it to the > self.directory_cache dictionary. > > Low Level function, intended to be used by the populate >function. > """ > scan_directory = os.path.abspath(scan_directory) > directories = {} > files = {} > self.directory_cache[scan_directory.strip().lower()] = {} > self.directory_cache[scan_directory.strip().lower()]["number_dirs"] = 0 You write "scan_directory.strip().lower()". It if probably worth going: norm_directory = scan_directory.strip().lower() and saying "norm_directory" throughout. Also, you say: self.directory_cache[scan_directory.strip().lower()] You can also bind: cache = self.directory_cache[norm_directory] right after binding "norm_directory", and say "cache" throughout instead of the longer term. It is naming the same object. >self.directory_cache[scan_directory.strip().lower()]["number_files"] = 0 > for x in scandir.scandir(scan_directory): > st = x.lstat() > data = {} As mentioned earlier, you could usefully define a tiny class: class Dirent(object): pass and go: data = Dirent() which will allow you to replace: > data["fq_filename"] = os.path.realpath(scan_directory).lower() + \ > os.sep+x.name.strip().lower() with: data.fq_filename = os.path.realpath( os.path.join(norm_directory, x.name.strip().lower()) ) Note also the use of os.path.join: it is portable across OSes (eg UNIX versus Windows). Also, well worth defining: norm_name = x.name.strip().lower() and just saying "norm_name" throughout. More readable, less prone to typing accidents. Um. A serious point here: why do you go .strip().lower() to all your filenames and pathnames? On a real UNIX system that will usually mean a different object. Many other platforms may have case insensitive names, but will still complaint about names with and without whitespace as different objects. I would even expect os.path.realname to be unreliable if handed such mangled names. If you are sanitising some input I would recommend doing that elsewhere, and not binding some much special knowledge into this class. Maybe you have good reasons for that. At the least those reasons need to be expressed in comments (best in the opening docstring), because otherwise I would recommend strongly to make the cache class as naive about names as possible (i.e. do not mangle them). > data["parentdirectory"] = os.sep.join(\ > os.path.split(scan_directory)[0:-1]) Use os.path.dirname. > data["st_mode"] = st[ST_MODE] > data["st_inode"] = st[ST_INO] > data["st_dev"] = st[ST_DEV] > data["st_nlink"] = st[ST_NLINK] > data["st_uid"] = st[ST_UID] > data["st_gid"] = st[ST_GID] > data["compressed"] = st[ST_SIZE] "compressed" is worth a comment. > data["st_size"] = st[ST_SIZE] #10 > data["st_atime"] = st[ST_ATIME] #11 > data["raw_st_mtime"] = st[ST_MTIME] #12 > data["st_mtime"] = time.asctime(time.localtime(st[ST_MTIME])) I strongly recommend against this. Keep "st_mtime" (or data.st.st_mtime per my earlier suggestion) as the raw mtime. Any human readable transcription of the time should get a name like "human_st_mtime". Better still, if you make a Dirent class for "data", you can give it a property like: @property def human_st_mtime(self): return time.asctime(time.localtime(self.st.st_mtime)) and just use ".human.st.mtime" like any other attribute later when needed. Note: no brackets. > data["st_ctime"] = st[ST_CTIME] > if not x.name.strip().lower() in self.files_to_ignore: Personally I phrase this as "a not in b" instead of "not a in b". Also, if you really are ignoring it, you could go: if norm_name in self.files_to_ignore: # do nothing else with this entry continue and save yourself some indentation below. Not everyone likes this. > def directory_in_cache(self, scan_directory): > """ > Pass the target directory > > Will return True if the directory is already cached > Will return False if the directory is not already cached > """ > scan_directory = os.path.realpath(scan_directory).lower().strip() Probably worth making normalisation function: def norm_name(name): return name.lower().strip() becuase you do this a lot. Using a function ensures you do it the same way everywhere and makes it obvious that it is the same thing with the same purpose everywhere. > return scan_directory in self.directory_cache.keys() You can just say: return scan_directory in self.directory_cache and for added points you can rename "directory_in_cache" to "__contains__". That way from outside (or inside) you use "in" directly. Example: if "foo" in self: Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Thu May 15 22:25:44 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2014 02:25:44 GMT Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> Message-ID: <53757728$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 May 2014 06:58:53 -0700, Rustom Mody wrote: > As far as I can see the votaries of the mystical 79 have yet to explain > how/where it appeared from You're either trolling, or haven't been reading this thread in any detail. That's already been explained, repeatedly both in this thread and many times over the years: 79 is one less than 80, which is the standard width of many editors, which in turn comes from old dedicated terminals. Given your use of deliberately provocative terms like "votaries" and "mystical", I would say you're trolling. On the chance that you are asking an honest question, there's nothing "mystical" or magical about the number 79, or 80. 80 is a de facto standard. Had history turned out a bit different, that standard might have been 90 characters, or 70. Less likely (because people psychologically have a preference for multiples of ten over "random" numbers) it could have been 65, or 93, or any number somewhere in that range of 60 to 100 or thereabouts. But once a standard is established, even an arbitrary standard like 80 columns -- but not *entirely* arbitrary -- there is value in sticking to it *just because it is the standard*. There's nothing "mystical" about driving on the left hand side of the road (on the right hand side for Americans), but whatever choice everyone else has made, you really ought to do the same. Following the same standard simply makes interoperability easier and reduces friction. But as I said, 80 isn't *entirely* arbitrary. 8 characters would be too few; 800 would be too many. Approximately 60 to 100 characters or thereabouts is the "Goldilocks" zone of "not too few, not too many" for most texts. Think of it this way: every time the reader has to scroll horizontally, consider that as a page fault (it's an order of magnitude slower than scanning with the eyes). Every time a single logical expression has to be split over two lines, that's also a page fault. Every time you read a line of complicated code that does too much, that's also a page fault. We want to minimize the number of page faults. A limit of 60 characters would minimize the number of horizontal scrolling page faults (hardly anyone has their editor to display fewer than 60 characters!), but increase the number of expression-splitting page faults. A limit of 120 characters would reduce the number of expression-splitting page faults, but increase the number of horizontal- scrolling faults, and encourage people to write long lines of complicated code that does too much. Somewhere in between is a range that minimizes the number of page faults, hence maximizes readability. There's unlikely to be "One True Best Answer" to maximize readability at N characters, because maximum readability is dependent on the context. One can only hope to get close to maximum readability for a range of typical text, including code. That's likely to be around 80 characters, which fits nicely with the historical standard. Reducing that to 80-1=79 means you're protected from "off-by-one" errors in either your counting or your editor. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Thu May 15 23:03:28 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 15 May 2014 20:03:28 -0700 (PDT) Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <8f793d18-1160-401e-b56b-f467122565fc@googlegroups.com> Message-ID: On Friday, May 16, 2014 5:51:21 AM UTC+5:30, Ben Finney wrote: > > > Rather, I've claimed that the conventional lime length limit is *based > in* the real cognitive limits of human reading comprehension -- and that > technologies have been designed with corresponding limitations. > > > Nowhere have I claimed 79 or 80 are somehow fundamental or encoded in > human cognition, and I have seen no-one else claim that. Please try to > work within your own cognitive limits and read what people write for > comprehension. > You said this: > The 80 character line limit is *not* driven by a limitation of computer > technology; it is driven by a limitation of human cognition. For that > reason, it remains relevant until human cognition in the general reading > population improves. And you answered: > Until then may we relegate '79' to quaint historical curiosities...?? with > Not until the general capacity of human cognition advances to make > longer lines easier to read. From chris at freeranger.com Fri May 16 00:36:49 2014 From: chris at freeranger.com (chris at freeranger.com) Date: Thu, 15 May 2014 21:36:49 -0700 (PDT) Subject: IndexError: pop from empty list Message-ID: <960b2711-6ed5-4a31-845b-7d15e39c9cf2@googlegroups.com> Any ideas about what this might mean? Running Debian Wheezy on a RaspBerry Pi and collecting data on a dispatch thread that is reading input on the serial port (connected to xbee series 1). It happens every few days but it really chokes the program. Thanks for any tips, ChrisJ Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 95, in run self._callback(self.wait_read_frame()) File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 400, in wait_read_frame return self._split_response(frame.data) File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 288, in _split_response info[parse_rule[0]] = parse_rule[1](self, info) File "/usr/local/lib/python2.7/dist-packages/xbee/ieee.py", line 117, in lambda xbee,original: xbee._parse_samples(original['samples']) File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 357, in _parse_samples digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0)) IndexError: pop from empty list From gary.herron at islandtraining.com Fri May 16 00:48:00 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Thu, 15 May 2014 21:48:00 -0700 Subject: IndexError: pop from empty list In-Reply-To: <960b2711-6ed5-4a31-845b-7d15e39c9cf2@googlegroups.com> References: <960b2711-6ed5-4a31-845b-7d15e39c9cf2@googlegroups.com> Message-ID: <53759880.30601@islandtraining.com> On 05/15/2014 09:36 PM, chris at freeranger.com wrote: > Any ideas about what this might mean? > > Running Debian Wheezy on a RaspBerry Pi and collecting data on a dispatch thread that is reading input on the serial port (connected to xbee series 1). > > It happens every few days but it really chokes the program. > > Thanks for any tips, > ChrisJ > > > > > Exception in thread Thread-2: > Traceback (most recent call last): > File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner > self.run() > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 95, in run > self._callback(self.wait_read_frame()) > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 400, in wait_read_frame > return self._split_response(frame.data) > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 288, in _split_response > info[parse_rule[0]] = parse_rule[1](self, info) > File "/usr/local/lib/python2.7/dist-packages/xbee/ieee.py", line 117, in > lambda xbee,original: xbee._parse_samples(original['samples']) > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 357, in _parse_samples > digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0)) > IndexError: pop from empty list The error means that sample_bytes is an empty list so calling pop is an error. Or were you asking something deeper, like *why* sample_bytes is an empty list? Gary Herron From chris at freeranger.com Fri May 16 00:59:09 2014 From: chris at freeranger.com (chris at freeranger.com) Date: Thu, 15 May 2014 21:59:09 -0700 (PDT) Subject: socket client and server in one application? In-Reply-To: References: <2db82378-5bb3-4a5c-b9e0-7ccb29760a06@googlegroups.com> <69f1b8e6-0b03-4d26-9b89-0d7b3dc43b16@googlegroups.com> Message-ID: Thank you all. The 2 threaded in/out sockets are working great. I'm receiving input on the xbee/serial port in the dispatch thread. For each receipt I send the xbee data through a socket connected to node-red. Node-red is collecting the data, parsing it and sending it along to other end points; mainly to carbon/graphite for charting. Then I've got some injection nodes in node-red that can send signals back to the python script. The python script has a socket server in the main loop that waits for a specialized command which, when received, sends a command back out the serial/xbee port to instruct a device to turn on/off. Generally it works great but I'm tuning it to optimize the amount of data I'm managing. The xbees are set to send 4 data points every .5 seconds. I only have 5 xbee radios in my setup but I think that means the little raspi is collecting up to 40 data points every second. On the node-red, it breaks each data set into 4 discreet entries and sends those to the carbon/graphite charting app. I'm thinking of including some signal averaging into the python receiver to smooth out the various signals I'm tracking. Again, thank you all for your help, Chris. On Monday, May 5, 2014 4:05:22 PM UTC-7, Chris Angelico wrote: > On Tue, May 6, 2014 at 8:37 AM, wrote: > > > I'm using a dispatch method to receive and occasionally send data through a serial port on a Raspberry Pi. I think the dispatch method is essentially a threaded approach, right? > > > > > > Now to receive serial data and send via socket, then occasionally receive some socket based input and send out on the same serial port. It's combining the client and server socket code into a single app (so I can have a single connection to the serial port) that has me confused. I don't see any discussion of that anywhere. > > > > > > > Threads would be easy. As I understand it, you have two bidirectional > > connections, and you're simply linking them? Sounds like a very simple > > proxy/tunnel. You don't need to multiplex, so all you need is two > > threads: one reading from the socket and writing to the serial port, > > and one reading from the serial port and writing to the socket. The > > code would look something like this: > > > > serial_port = open(...) > > tcp_socket = socket.create_connection(...) > > # initialize them both, do whatever setup is needed > > > > def socket_to_serial(): > > while True: > > data = tcp_socket.recv(4096) > > serial_port.write(data) > > > > Thread.Thread(target=socket_to_serial).start() > > > > while True: > > data = serial_port.read(4096) > > tcp_socket.send(data) > > > > > > Two simple loops, running concurrently. Pretty straight-forward as > > threads. Both of them will fall idle in their read/recv calls, so > > threading works very nicely here. > > > > ChrisA From chris at freeranger.com Fri May 16 01:08:34 2014 From: chris at freeranger.com (chris at freeranger.com) Date: Thu, 15 May 2014 22:08:34 -0700 (PDT) Subject: IndexError: pop from empty list In-Reply-To: References: <960b2711-6ed5-4a31-845b-7d15e39c9cf2@googlegroups.com> Message-ID: <5aa8abd1-05d4-4cf3-99fc-08493306b6a1@googlegroups.com> No, that was pretty much what I was looking for. If anyone has an answer to the deeper question, that would be icing on the cake. What is interesting is that usually the traceback shows the line of code that I invoke which, deep inside a library I'm using, has generated an error. In this case I don't know which of my commands has spawned the error. I can experiment, I suppose, with putting a try/catch around suspected lines of code... Thanks, Chris. On Thursday, May 15, 2014 9:48:00 PM UTC-7, Gary Herron wrote: > On 05/15/2014 09:36 PM, chris at freeranger.com wrote: > > > Any ideas about what this might mean? > > > > > > Running Debian Wheezy on a RaspBerry Pi and collecting data on a dispatch thread that is reading input on the serial port (connected to xbee series 1). > > > > > > It happens every few days but it really chokes the program. > > > > > > Thanks for any tips, > > > ChrisJ > > > > > > > > > > > > > > > Exception in thread Thread-2: > > > Traceback (most recent call last): > > > File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner > > > self.run() > > > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 95, in run > > > self._callback(self.wait_read_frame()) > > > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 400, in wait_read_frame > > > return self._split_response(frame.data) > > > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 288, in _split_response > > > info[parse_rule[0]] = parse_rule[1](self, info) > > > File "/usr/local/lib/python2.7/dist-packages/xbee/ieee.py", line 117, in > > > lambda xbee,original: xbee._parse_samples(original['samples']) > > > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 357, in _parse_samples > > > digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0)) > > > IndexError: pop from empty list > > > > The error means that sample_bytes is an empty list so calling pop is an > > error. > > > > Or were you asking something deeper, like *why* sample_bytes is an > > empty list? > > > > Gary Herron From ben at benfinney.id.au Fri May 16 02:12:30 2014 From: ben at benfinney.id.au (Ben Finney) Date: Fri, 16 May 2014 16:12:30 +1000 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <8f793d18-1160-401e-b56b-f467122565fc@googlegroups.com> Message-ID: <85ha4q6ylt.fsf@benfinney.id.au> Rustom Mody writes: > You said this: > > > The 80 character line limit is *not* driven by a limitation of > > computer technology; it is driven by a limitation of human > > cognition. For that reason, it remains relevant until human > > cognition in the general reading population improves. > > And you answered: > > > Until then may we relegate '79' to quaint historical > > curiosities...?? > > with > > > Not until the general capacity of human cognition advances to make > > longer lines easier to read. Indeed. Once again: Human cognition has limits, including limits on reading speed and reading comprehension as the length of a line of text increases beyond a threshold. You have caricatured that as some kind of statement that every human has a fundamental 79-column limit, which no-one has claimed. If you can't see the difference between what I and others have been saying about limits on human cognition, versus your caricature, then I can only leave you to re-read until you do understand. And I'll thank you not to straw-man people's positions. -- \ ?Dyslexia means never having to say that you're ysror.? | `\ ?anonymous | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Fri May 16 02:25:27 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2014 06:25:27 GMT Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <8761l7b05y.fsf@elektro.pacujo.net> Message-ID: <5375af57$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 May 2014 17:12:57 +0300, Marko Rauhamaa wrote: > A definitive Python source file could be binary, XML, .py, .ast, > whatever, Containing *what*? You can't just wave your hands and say "binary". What sort of binary file? Perhaps a JPEG file, where red triangles of different sizes represent keywords. Variable names can be encoded using a pattern of purple dots. Expressions and blocks of code can be formed by joining components with lines. Operators by squares of different colours (green means +, blue means -, etc.). No? Then what? Besides, where does the information inside the file come from? You surely don't expect people to write the binary data/AST/whatever directly. How can the zip file be "definitive" when it is derived from something more fundamental? Source code is, *by definition*, the definitive version. (It's the SOURCE, see?) Zipping the source code just means that the *source* inside the zip file is the definitive version, not the compressed binary data. The AST is not definitive. Human beings write *text*, which is what the source code is. It may be text with an especially restrictive grammar, but it's still text. Everything else -- the parse tree, the abstract syntax tree, the byte code, the machine code, the compressed text, encrypted text, the pixel rendering of the text, ... are derived from the code as written by human beings. Code is written primarily for human beings. Many programmers, and many language designers, don't realise this, which is why so many programs are write-only code. Presentation *is important*, and cannot always be separated from semantics without hurting the primary audience, the human reader. This is what code obfuscators do, deliberately: mangle the presentation while keeping the semantics the same. You're inadvertently proposing the same thing (albeit to a lesser degree). -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri May 16 02:41:22 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2014 06:41:22 GMT Subject: IndexError: pop from empty list References: <960b2711-6ed5-4a31-845b-7d15e39c9cf2@googlegroups.com> Message-ID: <5375b312$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 May 2014 21:36:49 -0700, chris wrote: > Any ideas about what this might mean? [jumping ahead] > digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0)) > IndexError: pop from empty list sample_bytes is an empty list. Or it could be a list with just a single sample. You try to pop from it twice in a row, so unless it contains at least two items, one or the other of the pops will fail. Without understanding the context, it's impossible to say what the best way to fix this, but my guess is that you need to guard this clause with something that ensures that there are at least two samples, and if not, just waits until there are. E.g.: if len(sample_bytes) >= 2: digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0)) or similar. This assumes the function will try again a moment later, after it's had a chance to gather some more data from the serial port. Ultimately, that's the problem: you're trying to process data faster than in can be collected. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ben at benfinney.id.au Fri May 16 02:54:32 2014 From: ben at benfinney.id.au (Ben Finney) Date: Fri, 16 May 2014 16:54:32 +1000 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <8761l7b05y.fsf@elektro.pacujo.net> <5375af57$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85d2fe6wnr.fsf@benfinney.id.au> Steven D'Aprano writes: > Source code is, *by definition*, the definitive version. (It's the > SOURCE, see?) Zipping the source code just means that the *source* > inside the zip file is the definitive version, not the compressed > binary data. I find the Free Software Foundation has a good, clear definition of ?source? for programs: The "source code" for a work means the preferred form of the work for making modifications to it. (GNU General Public License, version 3 ?1). There is ambiguity there, but it's exactly where it needs to be: focussing the discussion on what form of the work is preferred for making modofications to it. A byte stream is only source *with respect to some work*, and is only the source of *that* work if it is the preferred form of that work for making modifications to that work. This neatly cuts of at the knees a whole mob of futile speculative distractions about ?who is to say whether one person might consider this byte stream to be source?. To hell with all that. We're interested in making modifications to a work, and we reach for some form of the work to do so: *that* form is the source for the work. > The AST is not definitive. Human beings write *text*, which is what > the source code is. And if it's not text in some outlying cases, then it will only be because some *other* form of the work which is preferred by actual human programmers for making modifications to the work. > Code is written primarily for human beings. Many programmers, and many > language designers, don't realise this, which is why so many programs > are write-only code. Presentation *is important*, and cannot always be > separated from semantics without hurting the primary audience, the > human reader. This is what code obfuscators do, deliberately: mangle > the presentation while keeping the semantics the same. You're > inadvertently proposing the same thing (albeit to a lesser degree). Yes. And this is why obfuscated code, though it may be interpreted without difficulty by the same compiler algorithm, still does not constitute the source for the program. -- \ ?Any intelligent fool can make things bigger and more complex? | `\ It takes a touch of genius ? and a lot of courage ? to move in | _o__) the opposite direction.? ?Albert Einstein | Ben Finney From marko at pacujo.net Fri May 16 03:00:44 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 16 May 2014 10:00:44 +0300 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <8761l7b05y.fsf@elektro.pacujo.net> <5375af57$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k39m9pib.fsf@elektro.pacujo.net> Steven D'Aprano : > On Thu, 15 May 2014 17:12:57 +0300, Marko Rauhamaa wrote: > >> A definitive Python source file could be binary, XML, .py, .ast, >> whatever, > > Containing *what*? You can't just wave your hands and say "binary". I sure can and am. > Besides, where does the information inside the file come from? The file would a canonical serialization of the AST. The information would come from an editor (say, emacs) that displays the AST as two-dimensional text according to your preferences. Analogy: How do you edit a .png file? With an editor (say, gimp). Programming languages could work the same way. > Source code is, *by definition*, the definitive version. The AST file would be the source code, only it wouldn't have line numbers or columns. Maybe it could even leave out capitalization/camel-casing so the editor can display the variable, function and class names according to your preferences. > The AST is not definitive. Human beings write *text*, which is what the > source code is. You are stuck to the status quo. I'm proposing the AST should be the definitive source and the human beings would express AST through the editor. Yes, it would probably be text, at least partly, but for example the AST wouldn't specify the order of the function or class definitions. > This is what code obfuscators do, deliberately: mangle the > presentation while keeping the semantics the same. You're > inadvertently proposing the same thing (albeit to a lesser degree). At least, we could stop debating silly surface presentation issues (indentation, line width, spacing around operators...). Well, actually, any .py file *does* specify a unique AST. Nothing would prevent the text editor from presenting it according to your preferences. They all do that to a degree anyway (colors, fonts), but they could take even more liberties (which some IDE's do: hiding/showing comments and function definitions). There are tools that reindent and refactor code automatically. The text editor could do that on the fly. Marko From steve+comp.lang.python at pearwood.info Fri May 16 03:05:53 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2014 07:05:53 GMT Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <8f793d18-1160-401e-b56b-f467122565fc@googlegroups.com> Message-ID: <5375b8d1$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 May 2014 17:06:13 -0700, Rustom Mody wrote: > The claim being made is that 79/80 is a fundamental, cognitive limit and > has no relation to technological changes. I don't believe anyone has made that claim. You are reading a statement about general (typical, average) behaviour, and turning it into an absurd statement of a "fundamental" (your word) which applies to every single human being on earth. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri May 16 03:36:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 May 2014 17:36:06 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: <5375af57$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <8761l7b05y.fsf@elektro.pacujo.net> <5375af57$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 16, 2014 at 4:25 PM, Steven D'Aprano wrote: > Containing *what*? You can't just wave your hands and say "binary". What > sort of binary file? Perhaps a JPEG file, where red triangles of > different sizes represent keywords. Variable names can be encoded using a > pattern of purple dots. Expressions and blocks of code can be formed by > joining components with lines. Operators by squares of different colours > (green means +, blue means -, etc.). http://www.dangermouse.net/esoteric/piet.html ChrisA From rosuav at gmail.com Fri May 16 03:39:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 May 2014 17:39:28 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: <87k39m9pib.fsf@elektro.pacujo.net> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <8761l7b05y.fsf@elektro.pacujo.net> <5375af57$0$29977$c3e8da3$5496439d@news.astraweb.com> <87k39m9pib.fsf@elektro.pacujo.net> Message-ID: On Fri, May 16, 2014 at 5:00 PM, Marko Rauhamaa wrote: > Well, actually, any .py file *does* specify a unique AST. Nothing would > prevent the text editor from presenting it according to your > preferences. They all do that to a degree anyway (colors, fonts), but > they could take even more liberties (which some IDE's do: hiding/showing > comments and function definitions). > > There are tools that reindent and refactor code automatically. The text > editor could do that on the fly. You still haven't answered my biggest objection from earlier. Source code contains more information than the AST does; even if you make a frAnkenSTein's monster that includes comments, there's still the point that whitespace carries information, and that information is frequently communicative of the programmer's intent. Any automated reformatter destroys that information, and that is, by definition, a net loss to the code. How do you propose to fix that? Or if not, will you at least acknowledge that the AST cannot perfectly transmit what the source code says? ChrisA From __peter__ at web.de Fri May 16 04:15:13 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 16 May 2014 10:15:13 +0200 Subject: IndexError: pop from empty list References: <960b2711-6ed5-4a31-845b-7d15e39c9cf2@googlegroups.com> <5aa8abd1-05d4-4cf3-99fc-08493306b6a1@googlegroups.com> Message-ID: chris at freeranger.com wrote: > No, that was pretty much what I was looking for. If anyone has an answer > to the deeper question, that would be icing on the cake. > > What is interesting is that usually the traceback shows the line of code > that I invoke which, deep inside a library I'm using, has generated an > error. In this case I don't know which of my commands has spawned the > error. > > I can experiment, I suppose, with putting a try/catch around suspected > lines of code... It looks like the xbee library is responsible for reading the right amount of bytes and then fails to parse them properly. So it is possible (even likely I think) that you have run into a bug in the library. A report to the author/maintainer should be in order. Of course it would help if you can find a way to reproduce the error. One way to do that is to modify the code def _parse_samples(self, io_bytes): try: ... # original code of the method except IndexError: # replace path with something that makes sense on your system with open("/path/to/io_bytes.data", "wb") as f: f.write(io_bytes) raise wait until the error occurs again and then send the contents of the io_bytes.data file along with your bug report. From winefrog at gmail.com Fri May 16 04:44:58 2014 From: winefrog at gmail.com (Isaac Won) Date: Fri, 16 May 2014 01:44:58 -0700 (PDT) Subject: Extracting the value from Netcdf file with longitude and lattitude Message-ID: Hi, My question may be confusing. Now I would like to extract temperature values from model output with python. My model output have separate temperature, longitude and latitude variables. So, I overlap these three grid variables on one figure to show temperature with longitude and latitude through model domain. Up to this point, everything is fine. The problem is to extract temperature value at certain longitude and latitude. Temperature variable doesn't have coordinate, but only values with grid. Do you have idea about this issue? Below is my code for the 2 D plot with temperature on model domain. varn1 = 'T2' varn2 = 'XLONG' varn3 = 'XLAT' Temp = read_netcdf(filin,varn1) Lon = read_netcdf(filin,varn2) Lat = read_netcdf(filin,varn3) Temp_plt = Temp[12,:,:] Lon_plt = Lon[12,:,:] Lat_plt = Lat[12,:,:] x = Lon_plt y = Lat_plt Temp_c = Temp_plt-273.15 myPLT = plt.pcolor(x,y,Temp_c) mxlabel = plt.xlabel('Latitude') mylabel = plt.ylabel('Longitude') plt.xlim(126.35,127.35) plt.ylim(37.16,37.84) myBAR = plt.colorbar(myPLT) myBAR.set_label('Temperature ($^\circ$C)') plt.show() -------------------------------------------------- read_netcdf is a code for extracting values of [time, x,y] format. I think that the point is to bind x, y in Temp_plt with x, y in Lon_plt and Lat_plt to extract temperature values with longitude and latitude input. This question might be confusing. If you can't understand please let me know. Any idea or help will be really appreciated. Best regards, Hoonill From marko at pacujo.net Fri May 16 05:18:16 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 16 May 2014 12:18:16 +0300 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <8761l7b05y.fsf@elektro.pacujo.net> <5375af57$0$29977$c3e8da3$5496439d@news.astraweb.com> <87k39m9pib.fsf@elektro.pacujo.net> Message-ID: <87d2fe9j53.fsf@elektro.pacujo.net> Chris Angelico : > You still haven't answered my biggest objection from earlier. Source > code contains more information than the AST does; even if you make a > frAnkenSTein's monster that includes comments, there's still the point > that whitespace carries information, and that information is > frequently communicative of the programmer's intent. Any automated > reformatter destroys that information, and that is, by definition, a > net loss to the code. How do you propose to fix that? Or if not, will > you at least acknowledge that the AST cannot perfectly transmit what > the source code says? If every bit of your Python text conveys information, obviously, it can't be abstracted. I don't believe that to be the case, though. So this AST should contain all *actual* information worth conveying and strip away irrelevant stuff. Examples: * Function definition order. * Indentation depth. * Vertical empty space. Of course, I'm not being completely serious about all this stuff because the surface coding style questions are among the least relevant problems in the code. But at least that kind of arrangement would free us from the heated debates concerning the maximum line length etc. (BTW, regardless of PEP8, the maximum line length *must* be 79, and the maximum function length *must* be whatever can be seen on the screen at once.) Marko From liuenlong20 at gmail.com Fri May 16 04:49:19 2014 From: liuenlong20 at gmail.com (Enlong Liu) Date: Fri, 16 May 2014 16:49:19 +0800 Subject: The possibility integration in Python without an equation, just an array-like file Message-ID: Dear All, I have a question about the integration with Python. The equation is as below: and I want to get values of I with respect of V. E_F is known. But for T(E), I don't have explicit equation, but a .dat file containing two columns, the first is E, and the second is T(E). It is also in the attachment for reference. So is it possible to do integration in Python? Thanks a lot for your help! Best regards, ? -- Faculty of Engineering at K.U. Leuven BIOTECH at TU Dresden Email: liuenlong20 at gmail.com; enlong.liu at student.kuleuven.be; enlong.liu at biotech.tu-dresden.de Mobile Phone: +4917666191322 Mailing Address: Zi. 0108R, Budapester Stra?e 24, 01069, Dresden, Germany -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ???.png Type: image/png Size: 17975 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: tunneling_pure_BNT30.dat Type: application/octet-stream Size: 9849 bytes Desc: not available URL: From rosuav at gmail.com Fri May 16 05:40:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 May 2014 19:40:25 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: <87d2fe9j53.fsf@elektro.pacujo.net> References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <8761l7b05y.fsf@elektro.pacujo.net> <5375af57$0$29977$c3e8da3$5496439d@news.astraweb.com> <87k39m9pib.fsf@elektro.pacujo.net> <87d2fe9j53.fsf@elektro.pacujo.net> Message-ID: On Fri, May 16, 2014 at 7:18 PM, Marko Rauhamaa wrote: > If every bit of your Python text conveys information, obviously, it > can't be abstracted. I don't believe that to be the case, though. So > this AST should contain all *actual* information worth conveying and > strip away irrelevant stuff. > > Examples: > > * Function definition order. > > * Indentation depth. > > * Vertical empty space. * Logical layout as expressed by whitespace and specific line breaks. Compare these two assignment statements: area = (base*base + extension*extension + annex*annex + (annex-extension)*annex + triangle*triangle/2 + circle*circle*math.PI + sphere*sphere*4*math.PI) area = (base*base + extension*extension + annex*annex + (annex-extension)*annex + triangle*triangle/2 + circle*circle*math.PI + sphere*sphere*4*math.PI) Both are wrapped to sixty characters, which means they can be indented twenty without breaking PEP 8. One of them takes up only three lines, the other takes up four. But the first one groups the annex's terms, separates out the triangle, groups the circular elements, and presumably corresponds accurately to the (mythical) real-world geometry that it's implementing. How are you going to cope with this distinction? That's real, useful information, which the AST doesn't carry. (You might argue that each of these lines should have a comment at the end of it or above it, which would provide that grouping. But in that case, you lose the canonicalization of anything with trailing comments or interspersed comments, meaning that you effectively can't reformat anything with comments in it.) ChrisA From laurent.celati at gmail.com Fri May 16 06:18:28 2014 From: laurent.celati at gmail.com (dandrigo) Date: Fri, 16 May 2014 03:18:28 -0700 (PDT) Subject: Psycopg2 : error message. Message-ID: <1400235507987-5057062.post@n6.nabble.com> Dear all, I'm writing a python script for a web service. I have to connect to my postgres/postgis databases via Psycopg2. I writed a little first script just to connect to my pg/postgis db and drop a test db. But when i execute the python file, i have several error messages. Please read the 2 usefull files below : Dandrigo pg_test.py SS_dos.JPG In advance, thank you to throw light for me. Regards. -- View this message in context: http://python.6.x6.nabble.com/Psycopg2-error-message-tp5057062.html Sent from the Python - python-list mailing list archive at Nabble.com. From marko at pacujo.net Fri May 16 06:48:58 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 16 May 2014 13:48:58 +0300 Subject: PEP 8 : Maximum line Length : References: <5373f400$0$24922$e4fe514c@dreader36.news.xs4all.nl> <600f69c8-541f-4fae-a3db-4da33b776046@googlegroups.com> <87a9ajb36d.fsf@elektro.pacujo.net> <78ac407a-c429-4a7a-93c9-5d83e0f09cbb@googlegroups.com> <8761l7b05y.fsf@elektro.pacujo.net> <5375af57$0$29977$c3e8da3$5496439d@news.astraweb.com> <87k39m9pib.fsf@elektro.pacujo.net> <87d2fe9j53.fsf@elektro.pacujo.net> Message-ID: <8761l69exx.fsf@elektro.pacujo.net> Chris Angelico : > Compare these two assignment statements: > > area = (base*base + extension*extension > + annex*annex + (annex-extension)*annex > + triangle*triangle/2 > + circle*circle*math.PI + sphere*sphere*4*math.PI) > > area = (base*base + extension*extension + annex*annex > + (annex-extension)*annex + triangle*triangle/2 > + circle*circle*math.PI + sphere*sphere*4*math.PI) > > [...] > How are you going to cope with this distinction? That's real, useful > information, which the AST doesn't carry. Such nuances would be lost, yes. However, the nuances are constantly abused and misinterpreted anyway. Marko From davea at davea.name Fri May 16 07:14:36 2014 From: davea at davea.name (Dave Angel) Date: Fri, 16 May 2014 07:14:36 -0400 Subject: The possibility integration in Python without an equation, just an array-like file In-Reply-To: References: Message-ID: <5375F31C.5090101@davea.name> On 05/16/2014 04:49 AM, Enlong Liu wrote: > Dear All, > > I have a question about the integration with Python. The equation is as > below: > and I want to get values of I with respect of V. E_F is known. But for > T(E), I don't have explicit equation, but a .dat file containing > two columns, the first is E, and the second is T(E). It is also in the > attachment for reference. So is it possible to do integration in Python? > You posted in html, and you tried to make an attachment. Either of these will stop many people from seeing what you intended them to see. Presumably the rest of the explanation is in the source code, which you didn't include in your message. This is a text-mailing-list, and many of us cannot see attachments, and many others of us cannot see html. Please tell your email program to use plain text, not html. Please paste any attachments into the same text message, unless it's too big. In that case, you'd need to paste a link instead, but many people won't be able and/or willing to follow such links. -- DaveA From rosuav at gmail.com Fri May 16 07:39:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 May 2014 21:39:28 +1000 Subject: Psycopg2 : error message. In-Reply-To: <1400235507987-5057062.post@n6.nabble.com> References: <1400235507987-5057062.post@n6.nabble.com> Message-ID: On Fri, May 16, 2014 at 8:18 PM, dandrigo wrote: > Please read the 2 usefull files below : > > Dandrigo pg_test.py > > SS_dos.JPG These would be MUCH better included inline. Please, in future, copy and paste the *text* of the error message - don't post a screenshot. As to the actual problem: You're masking a potentially useful exception behind a bare except that just prints a generic message *and then continues*. This is a very bad idea. Don't do it. Take all that out and just attempt the connection; then you'll get a useful error. Same further down. Just don't. ChrisA From antoine at python.org Fri May 16 07:50:47 2014 From: antoine at python.org (Antoine Pitrou) Date: Fri, 16 May 2014 11:50:47 +0000 (UTC) Subject: Everything you did not want to know about Unicode in Python 3 References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b493$0$29977$c3e8da3$5496439d@news.astraweb.com> <5372BE8B.3070302@stoneleaf.us> Message-ID: Terry Reedy udel.edu> writes: > > On 5/13/2014 8:53 PM, Ethan Furman wrote: > > On 05/13/2014 05:10 PM, Steven D'Aprano wrote: > >> On Tue, 13 May 2014 10:08:42 -0600, Ian Kelly wrote: > >> > >>> Because Python 3 presents stdin and stdout as text streams however, it > >>> makes them more difficult to use with binary data, which is why Armin > >>> sets up all that extra code to make sure his file objects are binary. > >> > >> What surprises me is how hard that is. Surely there's a simpler way to > >> open stdin and stdout in binary mode? If not, there ought to be. > > > > Somebody already posted this: > > > > https://docs.python.org/3/library/sys.html#sys.stdin > > > > which talks about .detach(). > > I sent a message to Armin about this. And the documentation has now been fixed: http://bugs.python.org/issue21364 So something *can* come out of a python-list rantfest, it seems. Regards Antoine. From liuenlong20 at gmail.com Fri May 16 08:57:37 2014 From: liuenlong20 at gmail.com (Enlong Liu) Date: Fri, 16 May 2014 05:57:37 -0700 (PDT) Subject: The possibility integration in Python without an equation, just an array-like file In-Reply-To: References: Message-ID: <3ade3adc-75fa-4424-9c60-54097ae40460@googlegroups.com> Sorry for this inconvenience. Since my file is a little large, I think it will be more difficult for fellows to check. I will now paste the attachment below. The file for T(E) consists of two columns, the first is E and the second is T(E). What I want is to integrate this function in a certain range. E T(E) -6.25789500000000 8.96247678929291 -6.23789500000000 8.90487115888237 -6.21789500000000 7.96907432610510 -6.19789500000000 7.92011229305473 -6.17789500000000 6.99973958998368 -6.15789500000000 6.99959200703257 -6.13789500000000 6.99960349124858 -6.11789500000000 6.99960255937428 -6.09789500000000 7.02338574542792 -6.07789500000000 8.93135475951887 -6.05789500000000 9.96750726601798 -6.03789500000000 10.9408732001956 -6.01789500000000 10.9415058589703 -5.99789500000000 8.94537541754214 -5.97789500000000 10.8097100967606 -5.95789500000000 8.85226193360772 -5.93789500000000 6.99661653557932 -5.91789500000000 6.99654736394444 -5.89789500000000 6.99670347299879 -5.87789500000000 6.99673218445900 -5.85789500000000 6.99659826270511 -5.83789500000000 6.99623464091850 -5.81789500000000 6.99548818932425 -5.79789500000000 6.99394489936466 -5.77789500000000 6.99005017803712 -5.75789500000000 6.96962543581676 -5.73789500000000 5.99747630590266 -5.71789500000000 6.94845928621193 -5.69789500000000 6.98766975985479 -5.67789500000000 6.97758798116556 -5.65789500000000 6.95055436382018 -5.63789500000000 6.87176971154089 -5.61789500000000 6.54273589313568 -5.59789500000000 5.86175895258116 -5.57789500000000 5.11119282973331 -5.55789500000000 4.99981497444712 -5.53789500000000 4.99980834464660 -5.51789500000000 4.99980420721252 -5.49789500000000 4.99979886872216 -5.47789500000000 4.99978991290910 -5.45789500000000 4.99977459415969 -5.43789500000000 4.99974900970110 -5.41789500000000 4.99970628963861 -5.39789500000000 4.99963148201658 -5.37789500000000 4.99948355338835 -5.35789500000000 4.99911446459881 -5.33789500000000 4.99695076010531 -5.31789500000000 4.99843069856951 -5.29789500000000 4.99936037524651 -5.27789500000000 6.35475207677864 -5.25789500000000 6.82856665022716 -5.23789500000000 6.14018744222317 -5.21789500000000 6.36919461746248 -5.19789500000000 6.99756897433419 -5.17789500000000 6.99744749888663 -5.15789500000000 6.99680114447542 -5.13789500000000 6.99567111628791 -5.11789500000000 6.99382008170924 -5.09789500000000 6.99072617412210 -5.07789500000000 6.98523875355823 -5.05789500000000 6.97440300478140 -5.03789500000000 6.94799835685808 -5.01789500000000 6.83297555585804 -4.99789500000000 5.99940020401670 -4.97789500000000 5.99938810939229 -4.95789500000000 5.02927710403357 -4.93789500000000 4.99915975390103 -4.91789500000000 4.99890278935809 -4.89789500000000 4.99859914243363 -4.87789500000000 4.99821739336097 -4.85789500000000 4.99773235771017 -4.83789500000000 4.99710904566381 -4.81789500000000 4.99629369410517 -4.79789500000000 4.99519763548885 -4.77789500000000 4.99366188069830 -4.75789500000000 4.99136763606374 -4.73789500000000 4.98756326792036 -4.71789500000000 4.97994414169979 -4.69789500000000 4.95655109792192 -4.67789500000000 4.29448749155961 -4.65789500000000 3.99951693213742 -4.63789500000000 3.99942050837630 -4.61789500000000 3.99929275933828 -4.59789500000000 3.99907888035628 -4.57789500000000 4.91566360421753 -4.55789500000000 3.00063522267926 -4.53789500000000 3.99325633047260 -4.51789500000000 3.98716883843963 -4.49789500000000 3.99345892791020 -4.47789500000000 3.86300434156207 -4.45789500000000 2.98361846417016 -4.43789500000000 1.00328787566656 -4.41789500000000 0.999797612478520 -4.39789500000000 0.999727944291486 -4.37789500000000 0.999702219681149 -4.35789500000000 1.00016002999621 -4.33789500000000 1.99864445953476 -4.31789500000000 1.99860065378437 -4.29789500000000 1.99824848521827 -4.27789500000000 1.99649756321106 -4.25789500000000 1.95617313810368 -4.23789500000000 3.570896446978622E-004 -4.21789500000000 1.97744209232734 -4.19789500000000 1.99679585412003 -4.17789500000000 1.99842479205520 -4.15789500000000 1.99877213350223 -4.13789500000000 1.99891258930992 -4.11789500000000 1.99245903763110 -4.09789500000000 1.00042020485320 -4.07789500000000 1.99346260053212 -4.05789500000000 1.99529022218454 -4.03789500000000 1.99619467308276 -4.01789500000000 2.98692731072113 -3.99789500000000 2.99342575646381 -3.97789500000000 2.99511377004572 -3.95789500000000 2.99597797947674 -3.93789500000000 2.99653897767668 -3.91789500000000 2.99695098262430 -3.89789500000000 2.99727694889388 -3.87789500000000 2.99754767510197 -3.85789500000000 2.99778011719167 -3.83789500000000 2.99798442330902 -3.81789500000000 2.99816705707735 -3.79789500000000 2.99833233832487 -3.77789500000000 2.99848326713776 -3.75789500000000 2.99862199371746 -3.73789500000000 2.99875010070509 -3.71789500000000 2.99886878023708 -3.69789500000000 2.99897894901818 -3.67789500000000 2.99908132533735 -3.65789500000000 2.99917648165371 -3.63789500000000 2.99926488159352 -3.61789500000000 2.99934690561197 -3.59789500000000 2.99942286954705 -3.57789500000000 2.99949303781197 -3.55789500000000 2.99955763309114 -3.53789500000000 2.99961684390716 -3.51789500000000 2.99967083149013 -3.49789500000000 2.99971973759785 -3.47789500000000 2.99976369547298 -3.45789500000000 2.99980284682420 -3.43789500000000 2.99983736837377 -3.41789500000000 2.99986751113691 -3.39789500000000 2.99989365153947 -3.37789500000000 2.99991633937693 -3.35789500000000 2.99993629070310 -3.33789500000000 2.99995419962049 -3.31789500000000 2.99997018435098 -3.29789500000000 2.99998341819113 -3.27789500000000 3.00001064504626 -3.25789500000000 3.54110605014399 -3.23789500000000 3.95412236287359 -3.21789500000000 3.97367889482106 -3.19789500000000 4.61946526412397 -3.17789500000000 5.68414266040606 -3.15789500000000 5.62916331713924 -3.13789500000000 4.13198103763241 -3.11789500000000 4.67936064608229 -3.09789500000000 4.79767151863688 -3.07789500000000 3.00033719531157 -3.05789500000000 2.99547871695083 -3.03789500000000 2.99915615701496 -3.01789500000000 4.73072989912509 -2.99789500000000 4.91713261359818 -2.97789500000000 4.89867579329250 -2.95789500000000 4.47087307643605 -2.93789500000000 3.99091603911545 -2.91789500000000 5.81119541701557 -2.89789500000000 5.93109489768192 -2.87789500000000 5.93825547418363 -2.85789500000000 5.92019897656607 -2.83789500000000 5.79861607060496 -2.81789500000000 3.76515064453890 -2.79789500000000 3.18935409294165 -2.77789500000000 3.82926732895927 -2.75789500000000 3.58398483677936 -2.73789500000000 2.03211694868174 -2.71789500000000 2.99938865457082 -2.69789500000000 2.99878789344604 -2.67789500000000 2.99818412212921 -2.65789500000000 2.99774221894780 -2.63789500000000 2.99743396008636 -2.61789500000000 2.99874003537348 -2.59789500000000 2.99760685339435 -2.57789500000000 2.99741194400926 -2.55789500000000 2.99854255611774 -2.53789500000000 4.91569649652910 -2.51789500000000 4.94027859259799 -2.49789500000000 4.93056061607726 -2.47789500000000 4.88861078304332 -2.45789500000000 5.10007698404548 -2.43789500000000 4.51533588943211 -2.41789500000000 5.66703810392060 -2.39789500000000 5.79162900824220 -2.37789500000000 4.00025850649894 -2.35789500000000 3.99969972806110 -2.33789500000000 3.99956060303005 -2.31789500000000 3.99982474977923 -2.29789500000000 5.41542804727770 -2.27789500000000 5.02458000749128 -2.25789500000000 4.99752837619261 ? 2014?5?16????UTC+8??7?14?36??Dave Angel??? > On 05/16/2014 04:49 AM, Enlong Liu wrote: > > > Dear All, > > > > > > I have a question about the integration with Python. The equation is as > > > below: > > > and I want to get values of I with respect of V. E_F is known. But for > > > T(E), I don't have explicit equation, but a .dat file containing > > > two columns, the first is E, and the second is T(E). It is also in the > > > attachment for reference. So is it possible to do integration in Python? > > > > > You posted in html, and you tried to make an attachment. Either of > > these will stop many people from seeing what you intended them to see. > > > > Presumably the rest of the explanation is in the source code, which you > > didn't include in your message. This is a text-mailing-list, and many > > of us cannot see attachments, and many others of us cannot see html. > > > > Please tell your email program to use plain text, not html. > > > > Please paste any attachments into the same text message, unless it's too > > big. In that case, you'd need to paste a link instead, but many people > > won't be able and/or willing to follow such links. > > > > > > -- > > DaveA From buzzard at invalid.invalid Fri May 16 09:11:35 2014 From: buzzard at invalid.invalid (duncan smith) Date: Fri, 16 May 2014 14:11:35 +0100 Subject: The possibility integration in Python without an equation, just an array-like file In-Reply-To: <3ade3adc-75fa-4424-9c60-54097ae40460@googlegroups.com> References: <3ade3adc-75fa-4424-9c60-54097ae40460@googlegroups.com> Message-ID: <53760e87$0$28327$862e30e2@ngroups.net> On 16/05/14 13:57, Enlong Liu wrote: > Sorry for this inconvenience. Since my file is a little large, I think it will be more difficult for fellows to check. I will now paste the attachment below. > > The file for T(E) consists of two columns, the first is E and the second is T(E). What I want is to integrate this function in a certain range. > > E T(E) > -6.25789500000000 8.96247678929291 > -6.23789500000000 8.90487115888237 > -6.21789500000000 7.96907432610510 [snip] http://en.wikipedia.org/wiki/Numerical_integration Duncan From wxjmfauth at gmail.com Fri May 16 09:20:31 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 16 May 2014 06:20:31 -0700 (PDT) Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <8P7cv.78617$Sp6.8377@fx15.am4> <537172eb$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b493$0$29977$c3e8da3$5496439d@news.astraweb.com> <5372BE8B.3070302@stoneleaf.us> Message-ID: Le vendredi 16 mai 2014 13:50:47 UTC+2, Antoine Pitrou a ?crit?: > Terry Reedy udel.edu> writes: > > > > > > On 5/13/2014 8:53 PM, Ethan Furman wrote: > > > > On 05/13/2014 05:10 PM, Steven D'Aprano wrote: > > > >> On Tue, 13 May 2014 10:08:42 -0600, Ian Kelly wrote: > > > >> > > > >>> Because Python 3 presents stdin and stdout as text streams however, it > > > >>> makes them more difficult to use with binary data, which is why Armin > > > >>> sets up all that extra code to make sure his file objects are binary. > > > >> > > > >> What surprises me is how hard that is. Surely there's a simpler way to > > > >> open stdin and stdout in binary mode? If not, there ought to be. > > > > > > > > Somebody already posted this: > > > > > > > > https://docs.python.org/3/library/sys.html#sys.stdin > > > > > > > > which talks about .detach(). > > > > > > I sent a message to Armin about this. > > > > And the documentation has now been fixed: > > http://bugs.python.org/issue21364 > > > > So something *can* come out of a python-list rantfest, it seems. > > > > Regards > > > > Antoine. ====== http://www.unicode.org/ Avec mes meilleures salutations. From lmaguilera at estudiantes.uci.cu Fri May 16 10:10:17 2014 From: lmaguilera at estudiantes.uci.cu (Luis Miguel Rojas Aguilera) Date: Fri, 16 May 2014 10:10:17 -0400 Subject: urllib with x509 certs In-Reply-To: <50697b2c0907040327w23b7f0eal13934bc8d33c7231@mail.gmail.com> References: <50697b2c0907040327w23b7f0eal13934bc8d33c7231@mail.gmail.com> Message-ID: <53761C49.4060306@estudiantes.uci.cu> Hi, i tried what you suggest but still asking me for the password, this time twice. Please i need help so this is for my thesis. VII Escuela Internacional de Verano en la UCI del 30 de junio al 11 de julio de 2014. Ver www.uci.cu From invalid at invalid.invalid Fri May 16 10:46:23 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 16 May 2014 14:46:23 +0000 (UTC) Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> Message-ID: On 2014-05-14, alister wrote: > On Wed, 14 May 2014 10:08:57 +1000, Chris Angelico wrote: > >> On Wed, May 14, 2014 at 9:53 AM, Steven D'Aprano >> wrote: >>> With the current system, all of us here are technically violating >>> copyright every time we reply to an email and quote more than a small >>> percentage of it. >> >> Oh wow... so when someone quotes heaps of text without trimming, and >> adding blank lines, we can complain that it's a copyright violation - >> reproducing our work with unauthorized modifications and without >> permission... >> >> I never thought of it like that. > I think I could make a very strong case that anything sent to a public > forum with the intention of being broadcast has been placed into the > public domain by this action. At least in the US, there doesn't seem to be such a thing as "placing a work into the public domain". The copyright holder can transfer ownershipt to soembody else, but there is no "public domain" to which ownership can be trasferred. IIRC, there is a way under Germain copyright law to release certain rights. The mere act of widely widely distributing something does not in any way relinquish copyrights. -- Grant Edwards grant.b.edwards Yow! Am I elected yet? at gmail.com From johannes.schneider at galileo-press.de Fri May 16 11:01:04 2014 From: johannes.schneider at galileo-press.de (Johannes Schneider) Date: Fri, 16 May 2014 17:01:04 +0200 Subject: The possibility integration in Python without an equation, just an array-like file In-Reply-To: References: Message-ID: <53762830.5060700@galileo-press.de> If you do not have a closed form for T(E) you cannot calculate the exact value of I(V). Anyway. Assuming T is integrable you can approximate I(V). 1. Way to do: interpolate T(E) by a polynomial P and integrate P. For this you need the equation (coefficients and exponents) of P. Integrating is easy after that. 2. other way: Use Stair-functions: you can approximate the Value of IV() by the sum over T(E_i) * (E_{i+1} - E_i) s.t. E_0 = E_F-\frac{eV}{2} and E_n = E_F+\frac{eV}{2}. 3 one more way: use a computer algebra system like sage. bg, Johannes On 16.05.2014 10:49, Enlong Liu wrote: > Dear All, > > I have a question about the integration with Python. The equation is as > below: > and I want to get values of I with respect of V. E_F is known. But for > T(E), I don't have explicit equation, but a .dat file containing > two columns, the first is E, and the second is T(E). It is also in the > attachment for reference. So is it possible to do integration in Python? > > Thanks a lot for your help! > > Best regards, > ? > > -- > Faculty of Engineering at K.U. Leuven > BIOTECH at TU Dresden > Email:liuenlong20 at gmail.com ; > enlong.liu at student.kuleuven.be ; > enlong.liu at biotech.tu-dresden.de > Mobile Phone: +4917666191322 > Mailing Address: Zi. 0108R, Budapester Stra?e 24, 01069, Dresden, Germany > > -- Johannes Schneider Webentwicklung johannes.schneider at galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Gesch?ftsf?hrer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn From ernest.bonat at gmail.com Fri May 16 12:32:05 2014 From: ernest.bonat at gmail.com (Ernest Bonat, Ph.D.) Date: Fri, 16 May 2014 09:32:05 -0700 Subject: The possibility integration in Python without an equation, just an array-like file In-Reply-To: References: Message-ID: Hi Enlong You may try standard numerical integration solutions based on the E and T(E) columns data provided. Ernest Bonat, Ph.D. On Fri, May 16, 2014 at 1:49 AM, Enlong Liu wrote: > Dear All, > > I have a question about the integration with Python. The equation is as > below: > and I want to get values of I with respect of V. E_F is known. But for > T(E), I don't have explicit equation, but a .dat file containing > two columns, the first is E, and the second is T(E). It is also in the > attachment for reference. So is it possible to do integration in Python? > > Thanks a lot for your help! > > Best regards, > ? > > -- > Faculty of Engineering at K.U. Leuven > BIOTECH at TU Dresden > Email: liuenlong20 at gmail.com; enlong.liu at student.kuleuven.be; > enlong.liu at biotech.tu-dresden.de > Mobile Phone: +4917666191322 > Mailing Address: Zi. 0108R, Budapester Stra?e 24, 01069, Dresden, Germany > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- Thanks Ernest Bonat, Ph.D. Senior Software Engineer Senior Business Statistics Analyst Mobile: 503.730.4556 Email: ernest.bonat at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ???.png Type: image/png Size: 17975 bytes Desc: not available URL: From tjreedy at udel.edu Fri May 16 13:55:37 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 May 2014 13:55:37 -0400 Subject: The possibility integration in Python without an equation, just an array-like file In-Reply-To: References: Message-ID: On 5/16/2014 4:49 AM, Enlong Liu wrote: > Dear All, > > I have a question about the integration with Python. For numerical integration, you should look as numpy and scipy and perhaps associated packages. -- Terry Jan Reedy From buzzard at invalid.invalid Fri May 16 14:01:23 2014 From: buzzard at invalid.invalid (duncan smith) Date: Fri, 16 May 2014 19:01:23 +0100 Subject: The possibility integration in Python without an equation, just an array-like file In-Reply-To: References: Message-ID: <53765276$0$1349$862e30e2@ngroups.net> On 16/05/14 16:01, Johannes Schneider wrote: > If you do not have a closed form for T(E) you cannot calculate the exact > value of I(V). > > Anyway. Assuming T is integrable you can approximate I(V). > > 1. Way to do: > interpolate T(E) by a polynomial P and integrate P. For this you need > the equation (coefficients and exponents) of P. Integrating is easy > after that. > > 2. other way: > Use Stair-functions: you can approximate the Value of IV() by the sum > over T(E_i) * (E_{i+1} - E_i) s.t. E_0 = E_F-\frac{eV}{2} and E_n = > E_F+\frac{eV}{2}. > snip] Or piecewise polynomials (splines). Duncan From ernest.bonat at gmail.com Fri May 16 14:37:17 2014 From: ernest.bonat at gmail.com (Ernest Bonat, Ph.D.) Date: Fri, 16 May 2014 11:37:17 -0700 Subject: The possibility integration in Python without an equation, just an array-like file In-Reply-To: References: Message-ID: 1. There are a lot of spinet codes in many languages for numerical integration. I may find a good one in Python for you? try SciPy.org ( http://www.scipy.org/about.html) you may find something there. 2. Look at the wiki too: https://wiki.python.org/moin/NumericAndScientific. I hope this help a bit! Ernest Bonat, Ph.D. On Fri, May 16, 2014 at 10:55 AM, Terry Reedy wrote: > On 5/16/2014 4:49 AM, Enlong Liu wrote: > >> Dear All, >> >> I have a question about the integration with Python. >> > > For numerical integration, you should look as numpy and scipy and perhaps > associated packages. > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Thanks Ernest Bonat, Ph.D. Senior Software Engineer Senior Business Statistics Analyst Mobile: 503.730.4556 Email: ernest.bonat at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri May 16 21:07:07 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 May 2014 01:07:07 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> Message-ID: <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 May 2014 14:46:23 +0000, Grant Edwards wrote: > At least in the US, there doesn't seem to be such a thing as "placing a > work into the public domain". The copyright holder can transfer > ownershipt to soembody else, but there is no "public domain" to which > ownership can be trasferred. That's factually incorrect. In the US, sufficiently old works, or works of a certain age that were not explicitly registered for copyright, are in the public domain. Under a wide range of circumstances, works created by the federal government go immediately into the public domain. It is true that under the Mickey Mouse Copyright Grab Act[1] of , every time Mickey Mouse is about to reach the end of copyright, Congress retroactively extends copyright terms for another few decades, but that's another story. [1] Not the real name of the act. -- Steven D'Aprano http://import-that.dreamwidth.org/ From marko at pacujo.net Sat May 17 00:19:57 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 17 May 2014 07:19:57 +0300 Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877g5lm3yq.fsf@elektro.pacujo.net> Steven D'Aprano : > On Fri, 16 May 2014 14:46:23 +0000, Grant Edwards wrote: > >> At least in the US, there doesn't seem to be such a thing as "placing >> a work into the public domain". The copyright holder can transfer >> ownershipt to soembody else, but there is no "public domain" to which >> ownership can be trasferred. > > That's factually incorrect. In the US, sufficiently old works, or works > of a certain age that were not explicitly registered for copyright, are > in the public domain. Under a wide range of circumstances, works created > by the federal government go immediately into the public domain. Steven, you're not disputing Grant. I am. The sole copyright holder can simply state: "this work is in the Public Domain," or: "all rights relinquished," or some such. Ultimately, everything is decided by the courts, of course. Marko From roland at rptd.ch Fri May 16 20:27:19 2014 From: roland at rptd.ch (=?UTF-8?B?Um9sYW5kIFBsw7xzcw==?=) Date: Sat, 17 May 2014 02:27:19 +0200 Subject: Loading modules from files through C++ Message-ID: <5376ACE7.8030706@rptd.ch> I'm using Python in an embedded situation. In particular I have to load python scripts through a memory interface so regular python module loading can not be used. I got working so far a module loader object I've added using C++ to sys.meta_path . Now I'm totally stuck at the finally loading step. I've got this a C++ loader method "load_module(fullname)" which does load the requested module script files into a null-terminated string. I know that "load_module" has to return the module PyObject*. But I can't get the python source in the c-string into a module PyObject*. I've tried so far this: #CODE# return Py_CompileStringFlags( content.GetString(), lookupPath.GetPathNative(), Py_file_input, NULL ); #CODE# This did not result in a module that worked. In particular the module script in question contains a method "create". Using "dir(module)" on the returned value I see no "create" method and the type is a compiled string. So I tried this: #CODE# loadedModule = Py_InitModule3( fullname, NULL, "Loaded module" ); if( ! PyRun_StringFlags( content.GetString(), Py_file_input, loadedModule, loadedModule, NULL ) ){ if( PyErr_Occurred() ) PyErr_Print(); Py_INCREF( Py_None ); return Py_None; } Py_INCREF( loadedModule ); return loadedModule; #CODE# I concluded that I have to create the module myself and somehow eval/compile the c-string into the module. For this I figured out PyRun_StringFlags would be a suitable candidate. But doing the above I get an error: #CODE# Traceback (most recent call last): File "", line 22, in ImportError: __import__ not found #CODE# Looks like builtins are not existing. But from the internet I read that if code is parsed from a module both globals and locals are the module. The above code should do this but yet it fails. I tried also with PyEval_GetGlobals() and PyEval_GetBuiltins() I had no luck either except the function complaining about receiving NULL values. Can anybody help how in gods name one is supposed to create a module from an in-memory c-string when called from within load_module (or anywhere)? -- Yours sincerely Pl?ss Roland Leader and Head Programmer - Game: Epsylon ( http://www.indiedb.com/games/epsylon ) - Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine , http://dragengine.rptd.ch/wiki ) - Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php ) - As well as various Blender export scripts und game tools -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 263 bytes Desc: OpenPGP digital signature URL: From breamoreboy at yahoo.co.uk Sat May 17 04:35:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 17 May 2014 09:35:17 +0100 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <877g5lm3yq.fsf@elektro.pacujo.net> References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> <877g5lm3yq.fsf@elektro.pacujo.net> Message-ID: On 17/05/2014 05:19, Marko Rauhamaa wrote: > > The sole copyright holder can > simply state: "this work is in the Public Domain," or: "all rights > relinquished," or some such. Ultimately, everything is decided by the > courts, of course. > For examples see all the Python PEPs. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From robert.kern at gmail.com Sat May 17 04:57:06 2014 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 17 May 2014 09:57:06 +0100 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-05-17 02:07, Steven D'Aprano wrote: > On Fri, 16 May 2014 14:46:23 +0000, Grant Edwards wrote: > >> At least in the US, there doesn't seem to be such a thing as "placing a >> work into the public domain". The copyright holder can transfer >> ownershipt to soembody else, but there is no "public domain" to which >> ownership can be trasferred. > > That's factually incorrect. In the US, sufficiently old works, or works > of a certain age that were not explicitly registered for copyright, are > in the public domain. Under a wide range of circumstances, works created > by the federal government go immediately into the public domain. There is such a thing as the public domain in the US, and there are works in it, but there isn't really such a thing as "placing a work" there voluntarily, as Grant says. A work either is or isn't in the public domain. The author has no choice in the matter. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From rosuav at gmail.com Sat May 17 05:18:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 17 May 2014 19:18:55 +1000 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 17, 2014 at 6:57 PM, Robert Kern wrote: > There is such a thing as the public domain in the US, and there are works in > it, but there isn't really such a thing as "placing a work" there > voluntarily, as Grant says. A work either is or isn't in the public domain. > The author has no choice in the matter. Then what's copyright status on PEPs? The nearest thing to "assigning to public domain" that works across legislatures is probably CC0: http://creativecommons.org/about/cc0 ChrisA From robert.kern at gmail.com Sat May 17 05:29:00 2014 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 17 May 2014 10:29:00 +0100 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <877g5lm3yq.fsf@elektro.pacujo.net> References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> <877g5lm3yq.fsf@elektro.pacujo.net> Message-ID: On 2014-05-17 05:19, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Fri, 16 May 2014 14:46:23 +0000, Grant Edwards wrote: >> >>> At least in the US, there doesn't seem to be such a thing as "placing >>> a work into the public domain". The copyright holder can transfer >>> ownershipt to soembody else, but there is no "public domain" to which >>> ownership can be trasferred. >> >> That's factually incorrect. In the US, sufficiently old works, or works >> of a certain age that were not explicitly registered for copyright, are >> in the public domain. Under a wide range of circumstances, works created >> by the federal government go immediately into the public domain. > > Steven, you're not disputing Grant. I am. The sole copyright holder can > simply state: "this work is in the Public Domain," or: "all rights > relinquished," or some such. Ultimately, everything is decided by the > courts, of course. One can state many things, but that doesn't mean they have legal effect. The US Code has provisions for how works become copyrighted automatically, how they leave copyright automatically at the end of specific time periods, how some works automatically enter the public domain on their creation (i.e. works of the US federal government), but has nothing at all for how a private creator can voluntarily place their work into the public domain when it would otherwise not be. It used to, but does not any more. For a private individual to say about a work they just created that "this work is in the Public Domain" is, under US law, merely an erroneous statement of fact, not a speech act that effects a change in the legal status of the work. For another example of this distinction, saying "I am married" when I have not applied for, received, and solemnified a valid marriage license is just an erroneous statement of fact and does not make me legally married. Relinquishing your rights can have some effect, but not all rights can be relinquished, and this is not the same as putting your work into the public domain. Among other things, your heirs can sometimes reclaim those rights in some circumstances if you are not careful (and if they are valuable enough to bother reclaiming). If you wish to do something like this, I highly recommend (though IANAL and TINLA) using the CC0 Waiver from Creative Commons. It has thorough legalese for relinquishing all the rights that one can relinquish for the maximum terms that one can do so in as many jurisdictions as possible and acts as a license to use/distribute/etc. without restriction even if some rights cannot be relinquished. Even if US law were to change to provide for dedicating works to the public domain, I would probably still use the CC0 anyways to account for the high variability in how different jurisdictions around the world treat their own public domains. http://creativecommons.org/about/cc0 http://wiki.creativecommons.org/CC0_FAQ Note how they distinguish the CC0 Waiver from their Public Domain Mark: the Public Domain Mark is just a label for things that are known to be free of copyright worldwide but does not make a work so. The CC0 *does* have an operative effect that is substantially similar to the work being in the public domain. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From stefan-usenet at bytereef.org Sat May 17 07:01:25 2014 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Sat, 17 May 2014 13:01:25 +0200 Subject: Bug in Decimal?? Message-ID: <20140517110125.GA7785@sleipnir.bytereef.org> > I'll follow up directly with the author of mpdecimal, as this is > somewhat serious on a language that's so widely used as python. > But please test it and confirm, am I seeing ghost digits? This has already been settled on libmpdec-devel, but for the list: As Mark Dickinson has already explained, you need to increase the intermediate precision. For example: >>> from decimal import * >>> getcontext().prec=4000 >>> one=Decimal(1) >>> number=Decimal('1e-1007') >>> partial=(one+number)/(one-number) >>> getcontext().prec=2016 >>> partial.ln() Decimal('2.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000007E-1007') Otherwise 'partial' has an error that is too large when you pass it to the ln() function. Since decimal mostly follows IEEE 754 with arbitrary precision extensions, it cannot behave differently. Stefan Krah From ben at benfinney.id.au Sat May 17 07:05:34 2014 From: ben at benfinney.id.au (Ben Finney) Date: Sat, 17 May 2014 21:05:34 +1000 Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8538g87ji9.fsf@benfinney.id.au> Chris Angelico writes: > On Sat, May 17, 2014 at 6:57 PM, Robert Kern wrote: > > There is such a thing as the public domain in the US, and there are works in > > it, but there isn't really such a thing as "placing a work" there > > voluntarily, as Grant says. A work either is or isn't in the public domain. > > The author has no choice in the matter. > > Then what's copyright status on PEPs? My guess: They are in the default copyright status, with all rights reserved (i.e. everything that copyright law restricts, is forbidden to the recipient). But, if any of those copyright holders were ever to assert their copyright had been infringed by some recipient, the ?this work is in the public domain? or equivalent would be taken as a clear indication of the *intent* of the copyright holder. Ultimately, what matters is the determination of whatever judge you find yourself facing. To that end, clarifying in the copyright statement and license terms exactly what is permitted can be immensely helpful in foreshortening and, ideally, avoiding a future copyright suit. Copyright is a ridiculous burden on everyone ? to the extent that even those copyright holders who don't *want* those rights which the law reserves to the copyright holder, and want to divest themselves of the role of copyright holder, find it frustratingly difficult to do so effectively across jurisdictions. -- \ ?Computer perspective on Moore's Law: Human effort becomes | `\ twice as expensive roughly every two years.? ?anonymous | _o__) | Ben Finney From stefan_ml at behnel.de Sat May 17 07:58:53 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 17 May 2014 13:58:53 +0200 Subject: Loading modules from files through C++ In-Reply-To: <5376ACE7.8030706@rptd.ch> References: <5376ACE7.8030706@rptd.ch> Message-ID: Roland Pl?ss, 17.05.2014 02:27: > I'm using Python in an embedded situation. In particular I have to load > python scripts through a memory interface so regular python module > loading can not be used. I got working so far a module loader object > I've added using C++ to sys.meta_path . Now I'm totally stuck at the > finally loading step. > > I've got this a C++ loader method "load_module(fullname)" which does > load the requested module script files into a null-terminated string. I > know that "load_module" has to return the module PyObject*. But I can't > get the python source in the c-string into a module PyObject*. > [...] > Can anybody help how in gods name one is supposed to create a module > from an in-memory c-string when called from within load_module (or > anywhere)? Looks like you want to implement a SourceLoader: https://docs.python.org/3.4/library/importlib.html#importlib.abc.SourceLoader I recommend implementing this in Python code instead of C code, though. Much easier. Cython can help with the integration between both. Stefan From steve+comp.lang.python at pearwood.info Sat May 17 08:07:24 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 May 2014 12:07:24 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <537750fc$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 May 2014 09:57:06 +0100, Robert Kern wrote: > On 2014-05-17 02:07, Steven D'Aprano wrote: >> On Fri, 16 May 2014 14:46:23 +0000, Grant Edwards wrote: >> >>> At least in the US, there doesn't seem to be such a thing as "placing >>> a work into the public domain". The copyright holder can transfer >>> ownershipt to soembody else, but there is no "public domain" to which >>> ownership can be trasferred. >> >> That's factually incorrect. In the US, sufficiently old works, or works >> of a certain age that were not explicitly registered for copyright, are >> in the public domain. Under a wide range of circumstances, works >> created by the federal government go immediately into the public >> domain. > > There is such a thing as the public domain in the US, and there are > works in it, but there isn't really such a thing as "placing a work" > there voluntarily, as Grant says. A work either is or isn't in the > public domain. The author has no choice in the matter. That's incorrect. http://cr.yp.to/publicdomain.html Here's the money quote, from the 9th Circuit Court: It is well settled that rights gained under the Copyright Act may be abandoned. But abandonment of a right must be manifested by some overt act indicating an intention to abandon that right. There's also this: http://creativecommons.org/publicdomain/zero/1.0/ which counts as an overt act. By the way, there's more info on US copyright terms here: http://copyright.cornell.edu/resources/publicdomain.cfm although it doesn't specifically mention voluntarily abandonment of copyright. -- Steven D'Aprano http://import-that.dreamwidth.org/ From albert at spenarnc.xs4all.nl Sat May 17 08:52:44 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 17 May 2014 12:52:44 GMT Subject: PEP 8 : Maximum line Length : References: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> Message-ID: <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> In article , Chris Angelico wrote: >On Fri, May 16, 2014 at 12:17 AM, wrote: >> One another trick is to drop spaces around keywords >> >>>>> 99999and 12345or 9999999999if 'a'in'a' else 88888888or 777777 >> 12345 >> >> and pray, the tools from those who are wasting their time in >> writing code analyzers or syntax colorizers or doc strings >> collectors or ... are finally working. Depending of the tools >> the interpretation may vary, but definitely all are producing >> erroneous results. > >Yes. Another very effective way to get your code below 80 characters >is to shorten all names to a single letter. Since you don't need to >restrict yourself to monocase Roman letters (as I had to in my >earliest programming days, in BASIC), it's actually quite practical to >uniquely name everything in a single character; you could save >enormous amounts of horizontal space. Then, aggressively "import as" >to do the same with remote symbols (you might need two characters for >those), and you'll be able to write everything in just a few tight >symbols! That may be tong-in-cheek but mathematicians do exactly that. We use roman, greek and hebrew alphabets in normal italics and boldface and then some special characters for element-of, logical-or, integral signs, triangles and what not. Underbarred and upper twiggled, as a suffix a prefix or a superfix. All in the name of avoiding names longer than one character. When we run out then there are creative ways to combine known characters into Jacobi symbols and choose functions. There are even conventions that allow to leave out characters, like "juxtaposition means multiplication" and the Einstein summation convention. You have to invest but terseness pays off. Now translate E=mc^2 into Java. > >ChrisA -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From roland at rptd.ch Sat May 17 09:00:24 2014 From: roland at rptd.ch (=?UTF-8?B?Um9sYW5kIFBsw7xzcw==?=) Date: Sat, 17 May 2014 15:00:24 +0200 Subject: Loading modules from files through C++ In-Reply-To: References: <5376ACE7.8030706@rptd.ch> Message-ID: <53775D68.2010009@rptd.ch> That doesn't work in 2.x, doesn't it? On 05/17/2014 01:58 PM, Stefan Behnel wrote: > Roland Pl?ss, 17.05.2014 02:27: >> I'm using Python in an embedded situation. In particular I have to load >> python scripts through a memory interface so regular python module >> loading can not be used. I got working so far a module loader object >> I've added using C++ to sys.meta_path . Now I'm totally stuck at the >> finally loading step. >> >> I've got this a C++ loader method "load_module(fullname)" which does >> load the requested module script files into a null-terminated string. I >> know that "load_module" has to return the module PyObject*. But I can't >> get the python source in the c-string into a module PyObject*. >> [...] >> Can anybody help how in gods name one is supposed to create a module >> from an in-memory c-string when called from within load_module (or >> anywhere)? > Looks like you want to implement a SourceLoader: > > https://docs.python.org/3.4/library/importlib.html#importlib.abc.SourceLoader > > I recommend implementing this in Python code instead of C code, though. > Much easier. Cython can help with the integration between both. > > Stefan > > -- Yours sincerely Pl?ss Roland Leader and Head Programmer - Game: Epsylon ( http://www.indiedb.com/games/epsylon ) - Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine , http://dragengine.rptd.ch/wiki ) - Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php ) - As well as various Blender export scripts und game tools -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 263 bytes Desc: OpenPGP digital signature URL: From albert at spenarnc.xs4all.nl Sat May 17 09:01:06 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 17 May 2014 13:01:06 GMT Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x References: Message-ID: <53775d92$0$27160$e4fe514c@dreader35.news.xs4all.nl> In article , Andrew Konstantaras wrote: >-=-=-=-=-=- > >I guess I am missing something big as I am looking for a shorthand way >of doing the following: > > dctA = dict(x=x, y=y, ... n=n) > >This is, as I understand it a very natural way of using a dictionary. >It seems that this syntax is unnecessarily redundant and hence my goal >of writing something more compact. Perhaps the way I am doing it is a >little unorthodox, but the ultimate use of a dictionary is, as I >understand it, completely in line with how dictionaries were designed to >be used. In my other code, I often use these dictionaries to pass >arguments to functions and return results. It allows me great >flexibility without breaking existing code. I pack a dictionary before >passing and unpack when retrieving. Okay very well. I suggest you use the m4 preprocessor. This will allow you to get a maximum of compactness without compromising the Python language. Implementations of it are available on MS-Windows too. > >I will give the locals approach a try, it seems a little more clumsy >than simply passing the variables to the function. > >Thanks again for your input. > >---Andrew??? > Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From rosuav at gmail.com Sat May 17 09:18:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 17 May 2014 23:18:21 +1000 Subject: PEP 8 : Maximum line Length : In-Reply-To: <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> References: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> Message-ID: On Sat, May 17, 2014 at 10:52 PM, Albert van der Horst wrote: > That may be tong-in-cheek but mathematicians do exactly that. We > use roman, greek and hebrew alphabets in normal italics and boldface > and then some special characters for element-of, logical-or, integral signs, > triangles and what not. Underbarred and upper twiggled, as a suffix a prefix > or a superfix. All in the name of avoiding names longer than one character. > > When we run out then there are creative ways to combine known characters > into Jacobi symbols and choose functions. > > There are even conventions that allow to leave out characters, like > "juxtaposition means multiplication" and the Einstein summation convention. This, I think, is the main reason for the one-character variable name convention. Why else are there subscripts? Instead of using "V0" (two-character name), you use "V?" (one-character name with a subscript tag on it) to avoid collision with multiplication. > Now translate E=mc^2 into Java. Dunno, but in Python it would be: assert E==m*c*c And would probably fail, because that's all floating point :) ChrisA From stefan_ml at behnel.de Sat May 17 09:26:53 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 17 May 2014 15:26:53 +0200 Subject: Loading modules from files through C++ In-Reply-To: <53775D68.2010009@rptd.ch> References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> Message-ID: Roland Pl?ss, 17.05.2014 15:00: > On 05/17/2014 01:58 PM, Stefan Behnel wrote: >> Roland Pl?ss, 17.05.2014 02:27: >>> I'm using Python in an embedded situation. In particular I have to load >>> python scripts through a memory interface so regular python module >>> loading can not be used. I got working so far a module loader object >>> I've added using C++ to sys.meta_path . Now I'm totally stuck at the >>> finally loading step. >>> >>> I've got this a C++ loader method "load_module(fullname)" which does >>> load the requested module script files into a null-terminated string. I >>> know that "load_module" has to return the module PyObject*. But I can't >>> get the python source in the c-string into a module PyObject*. >>> [...] >>> Can anybody help how in gods name one is supposed to create a module >>> from an in-memory c-string when called from within load_module (or >>> anywhere)? >> Looks like you want to implement a SourceLoader: >> >> https://docs.python.org/3.4/library/importlib.html#importlib.abc.SourceLoader >> >> I recommend implementing this in Python code instead of C code, though. >> Much easier. Cython can help with the integration between both. > > That doesn't work in 2.x, doesn't it? Is there a reason you have to use Py2? Anyway, PEP 302 predates Py3 by a couple of years: http://legacy.python.org/dev/peps/pep-0302/ Stefan From python.list at tim.thechases.com Sat May 17 09:28:24 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 17 May 2014 08:28:24 -0500 Subject: PEP 8 : Maximum line Length : In-Reply-To: <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> References: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <20140517082824.689c7c78@bigbox.christie.dr> On 2014-05-17 12:52, Albert van der Horst wrote: > Now translate E=mc^2 into Java. I suspect it would be something like public class Einstein { private double mass=0, energy=0; public class Relativity implements IEquation { Relativity(double mass) { set_mass(mass); } public double getEnergy() {return energy;} public double setEnergy(double newEnergy) { energy = newEnergy; mass = newEnergy / (units.SPEED_OF_LIGHT * units.SPEED_OF_LIGHT); } public double get_mass() {return mass;} public double setMass(double newMass) { mass = newMass; energy = newMass * (units.SPEED_OF_LIGHT * units.SPEED_OF_LIGHT); } } public static void main(String[] args) { Relativity relativity = new Relativity( Integer.parseInt(args[1]) ); System.out.println(relativity.getEnergy()) } } (untested, as it has been a long time since I've touched any Java code) -tkc -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From roland at rptd.ch Sat May 17 09:49:47 2014 From: roland at rptd.ch (=?UTF-8?B?Um9sYW5kIFBsw7xzcw==?=) Date: Sat, 17 May 2014 15:49:47 +0200 Subject: Loading modules from files through C++ In-Reply-To: References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> Message-ID: <537768FB.7060303@rptd.ch> I'm willing to go to Py3 but only if the solution to the problem is simpler than getting it fixed in Py2. So some questions first: - does this importlib stuff you showed there apply to C++ land (I need to fully drive it from C++ not Python code)? - is the C++ land of Py3 similar to Py2 or totally different? On 05/17/2014 03:26 PM, Stefan Behnel wrote: > Roland Pl?ss, 17.05.2014 15:00: >> On 05/17/2014 01:58 PM, Stefan Behnel wrote: >>> Roland Pl?ss, 17.05.2014 02:27: >>>> I'm using Python in an embedded situation. In particular I have to load >>>> python scripts through a memory interface so regular python module >>>> loading can not be used. I got working so far a module loader object >>>> I've added using C++ to sys.meta_path . Now I'm totally stuck at the >>>> finally loading step. >>>> >>>> I've got this a C++ loader method "load_module(fullname)" which does >>>> load the requested module script files into a null-terminated string. I >>>> know that "load_module" has to return the module PyObject*. But I can't >>>> get the python source in the c-string into a module PyObject*. >>>> [...] >>>> Can anybody help how in gods name one is supposed to create a module >>>> from an in-memory c-string when called from within load_module (or >>>> anywhere)? >>> Looks like you want to implement a SourceLoader: >>> >>> https://docs.python.org/3.4/library/importlib.html#importlib.abc.SourceLoader >>> >>> I recommend implementing this in Python code instead of C code, though. >>> Much easier. Cython can help with the integration between both. >> That doesn't work in 2.x, doesn't it? > Is there a reason you have to use Py2? > > Anyway, PEP 302 predates Py3 by a couple of years: > > http://legacy.python.org/dev/peps/pep-0302/ > > Stefan > > -- Yours sincerely Pl?ss Roland Leader and Head Programmer - Game: Epsylon ( http://www.indiedb.com/games/epsylon ) - Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine , http://dragengine.rptd.ch/wiki ) - Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php ) - As well as various Blender export scripts und game tools -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 263 bytes Desc: OpenPGP digital signature URL: From roy at panix.com Sat May 17 09:46:43 2014 From: roy at panix.com (Roy Smith) Date: Sat, 17 May 2014 09:46:43 -0400 Subject: PEP 8 : Maximum line Length : References: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> Message-ID: In article , Tim Chase wrote: > On 2014-05-17 12:52, Albert van der Horst wrote: > > Now translate E=mc^2 into Java. > > I suspect it would be something like > > public class Einstein { > private double mass=0, energy=0; > public class Relativity implements IEquation { > Relativity(double mass) { > set_mass(mass); > } > public double getEnergy() {return energy;} > public double setEnergy(double newEnergy) { > energy = newEnergy; > mass = newEnergy / (units.SPEED_OF_LIGHT * units.SPEED_OF_LIGHT); > } > public double get_mass() {return mass;} > public double setMass(double newMass) { > mass = newMass; > energy = newMass * (units.SPEED_OF_LIGHT * units.SPEED_OF_LIGHT); > } > } > > public static void main(String[] args) { > Relativity relativity = new Relativity( > Integer.parseInt(args[1]) > ); > System.out.println(relativity.getEnergy()) > } > } > > > (untested, as it has been a long time since I've touched any Java code) > > -tkc Not good enough. Einstein should really be a singleton, so you need something like an AbstractScientistFactory, which implements Singleton. And you really should be importing SPEED_OF_LIGHT_IN_VACUUM_METERS_PER_SECOND from org.universe.physics.constants. And you need to declare that Einstein.getEnergy() raises NumericValueOutOfBoundsError if mass is negative (and FlatEarthError if the code is run in certain states south of the Mason-Dixie line). From roy at panix.com Sat May 17 09:49:58 2014 From: roy at panix.com (Roy Smith) Date: Sat, 17 May 2014 09:49:58 -0400 Subject: PEP 8 : Maximum line Length : References: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> Message-ID: In article , Chris Angelico wrote: > On Sat, May 17, 2014 at 10:52 PM, Albert van der Horst > wrote: > > That may be tong-in-cheek but mathematicians do exactly that. We > > use roman, greek and hebrew alphabets in normal italics and boldface > > and then some special characters for element-of, logical-or, integral signs, > > triangles and what not. Underbarred and upper twiggled, as a suffix a prefix > > or a superfix. All in the name of avoiding names longer than one character. > > > > When we run out then there are creative ways to combine known characters > > into Jacobi symbols and choose functions. > > > > There are even conventions that allow to leave out characters, like > > "juxtaposition means multiplication" and the Einstein summation convention. > > This, I think, is the main reason for the one-character variable name > convention. Why else are there subscripts? Instead of using "V0" > (two-character name), you use "V?" (one-character name with a > subscript tag on it) to avoid collision with multiplication. > > > Now translate E=mc^2 into Java. > > Dunno, but in Python it would be: > > assert E==m*c*c > > And would probably fail, because that's all floating point :) > > ChrisA Nah. Python has relativistic duck typing: >>> c = 186000 >>> m = 100 >>> E = 3459600000000L >>> assert E==m*c*c >>> From stefan_ml at behnel.de Sat May 17 10:01:22 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 17 May 2014 16:01:22 +0200 Subject: Loading modules from files through C++ In-Reply-To: <537768FB.7060303@rptd.ch> References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> Message-ID: Hi, please avoid top-posting. Roland Pl?ss, 17.05.2014 15:49: > On 05/17/2014 03:26 PM, Stefan Behnel wrote: >> Roland Pl?ss, 17.05.2014 15:00: >>> On 05/17/2014 01:58 PM, Stefan Behnel wrote: >>>> Roland Pl?ss, 17.05.2014 02:27: >>>>> I'm using Python in an embedded situation. In particular I have to load >>>>> python scripts through a memory interface so regular python module >>>>> loading can not be used. I got working so far a module loader object >>>>> I've added using C++ to sys.meta_path . Now I'm totally stuck at the >>>>> finally loading step. >>>>> >>>>> I've got this a C++ loader method "load_module(fullname)" which does >>>>> load the requested module script files into a null-terminated string. I >>>>> know that "load_module" has to return the module PyObject*. But I can't >>>>> get the python source in the c-string into a module PyObject*. >>>>> [...] >>>>> Can anybody help how in gods name one is supposed to create a module >>>>> from an in-memory c-string when called from within load_module (or >>>>> anywhere)? >>>> Looks like you want to implement a SourceLoader: >>>> >>>> https://docs.python.org/3.4/library/importlib.html#importlib.abc.SourceLoader >>>> >>>> I recommend implementing this in Python code instead of C code, though. >>>> Much easier. Cython can help with the integration between both. >>> That doesn't work in 2.x, doesn't it? >> Is there a reason you have to use Py2? >> >> Anyway, PEP 302 predates Py3 by a couple of years: >> >> http://legacy.python.org/dev/peps/pep-0302/ > > I'm willing to go to Py3 but only if the solution to the problem is > simpler than getting it fixed in Py2. So some questions first: > > - does this importlib stuff you showed there apply to C++ land (I need > to fully drive it from C++ not Python code)? As I said, implementing this in Python code is much simpler than doing it in C/C++ code. Basically, stop where you got the C string and do the rest in Python. All your C code has to do is to take a module lookup request from your custom Python module Finder and return a byte string with the code. Then let your Python code wrap that in a Loader and return it to the import machinery. > - is the C++ land of Py3 similar to Py2 or totally different? Much the same, just slight differences. As I said, Cython can help with the integration and would mostly cover the differences for you. Stefan From breamoreboy at yahoo.co.uk Sat May 17 10:02:30 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 17 May 2014 15:02:30 +0100 Subject: PEP 8 : Maximum line Length : In-Reply-To: <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> References: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> Message-ID: On 17/05/2014 13:52, Albert van der Horst wrote: > > Now translate E=mc^2 into Java. > I can't do that as I simply don't understand it. What has the Marylebone Cricket Club got to do with E? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From roy at panix.com Sat May 17 10:06:19 2014 From: roy at panix.com (Roy Smith) Date: Sat, 17 May 2014 10:06:19 -0400 Subject: PEP 8 : Maximum line Length : References: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> Message-ID: In article , Mark Lawrence wrote: > On 17/05/2014 13:52, Albert van der Horst wrote: > > > > Now translate E=mc^2 into Java. > > > > I can't do that as I simply don't understand it. What has the > Marylebone Cricket Club got to do with E? A wicket looks like an E on its side. Does that help? From steve+comp.lang.python at pearwood.info Sat May 17 10:15:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 May 2014 14:15:01 GMT Subject: Everything you did not want to know about Unicode in Python 3 References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> <877g5lm3yq.fsf@elektro.pacujo.net> Message-ID: <53776ee4$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 May 2014 10:29:00 +0100, Robert Kern wrote: > One can state many things, but that doesn't mean they have legal effect. > The US Code has provisions for how works become copyrighted > automatically, how they leave copyright automatically at the end of > specific time periods, how some works automatically enter the public > domain on their creation (i.e. works of the US federal government), but > has nothing at all for how a private creator can voluntarily place their > work into the public domain when it would otherwise not be. It used to, > but does not any more. The case for abandonment was stated as "well settled" in 1998 (Micro-Star v. Formgen Inc). Unless there has been a major legal change in the years since then, I don't think it is true that authors cannot abandon copyright. > For a private individual to say about a work they just created that > "this work is in the Public Domain" is, under US law, merely an > erroneous statement of fact, not a speech act that effects a change in > the legal status of the work. For another example of this distinction, > saying "I am married" when I have not applied for, received, and > solemnified a valid marriage license is just an erroneous statement of > fact and does not make me legally married. There may be something to what you say, although I think we're now arguing fine semantic details. See: https://en.wikipedia.org/wiki/Wikipedia:Granting_work_into_the_public_domain To play Devil's Advocate in favour of your assertion, it may be that abandoning copyright does not literally put the work in the public domain, but merely makes it "quack like the public domain". That is to say, the author still, in some abstract but legally meaningless sense, has copyright in the work *but* has given unlimited usage rights. (I don't actually think that is the case, at least not in the US.) It's this tiny bit of residual uncertainty that leads some authorities to say that it is "hard" to release a work into the public domain, particularly in a world-wide context, and that merely stating "this is in the public domain" is not sufficient to remove all legal doubt over the status, and that a more overt and explicit release *may* be required. Hence the CC0 licence which you refer to. The human readable summary says in part: The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. http://creativecommons.org/publicdomain/zero/1.0/ while the actual legal licence comes in at almost 800 words. This is basically the same as "I release this to the public domain" only longer. (The CC0 licence is longer than you might expect, because it is assumed that it may have to apply in countries where you *really cannot* relinquish copyright. But we're specifically talking about the US, where the 9th Circuit says you can.) > Relinquishing your rights can have some effect, but not all rights can > be relinquished, Outside of the US, so-called "moral rights" or "reputation rights" cannot generally be relinquished, except perhaps in work-for-hire and perhaps not even then. (E.g. if you're a ghost writer.) The situation in the US is a bit murky -- there are no official moral rights per se, and copyright only controls usage rights such as copying, distribution and so forth. But this doesn't mean that you can (for example) claim authorship of a public domain work unless you actually wrote it. In any case, we're discussing copyright, not other rights. > and this is not the same as putting your work into the > public domain. One might "not be the same" while still being "effectively the same". For example, the U.S. Copyright Office states that "one may not grant their work into the public domain. However, a copyright owner may release all of their rights to their work by stating the work may be freely reproduced, distributed, etc." as if it were in in the public domain. But note that the Copyright Office does not make the final decision whether you can relinquish copyright or not. That's up to the courts. > Among other things, your heirs can sometimes reclaim > those rights in some circumstances if you are not careful (and if they > are valuable enough to bother reclaiming). That's a good point. A simplistic "I release this to the public domain" statement *may* (I emphasise the uncertainty) leave some doubt that it is *sufficiently overt* to prevent your heirs from disagreeing and coming after your users for infringement. Then the courts have to get involved, and it's all ugliness and only the lawyers win. Hence the advice to be as explicit and overt as possible. > If you wish to do something like this, I highly recommend (though IANAL > and TINLA) using the CC0 Waiver from Creative Commons. It has thorough > legalese for relinquishing all the rights that one can relinquish for > the maximum terms that one can do so in as many jurisdictions as > possible and acts as a license to use/distribute/etc. without > restriction even if some rights cannot be relinquished. I agree with all of that not-legal-advice. And I too am not a lawyer. > Even if US law > were to change to provide for dedicating works to the public domain, This I disagree with -- the 9th Circuit Court says the US already provides for that. What we don't disagree with is that it *may* be trickier than a naive non- lawyer (including me!) thinks to satisfy the Court's "overt act" test. Given that uncertainty, overkill may be safer than underkill. The CC0 licence, at nearly 800 words, is probably overkill for the US, but it's more certain. > I would probably still use the CC0 anyways to account for the high > variability in how different jurisdictions around the world treat their > own public domains. Yes to all that. > http://creativecommons.org/about/cc0 > http://wiki.creativecommons.org/CC0_FAQ > > Note how they distinguish the CC0 Waiver from their Public Domain Mark: > the Public Domain Mark is just a label for things that are known to be > free of copyright worldwide but does not make a work so. The CC0 *does* > have an operative effect that is substantially similar to the work being > in the public domain. -- Steven D'Aprano http://import-that.dreamwidth.org/ From breamoreboy at yahoo.co.uk Sat May 17 10:21:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 17 May 2014 15:21:06 +0100 Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> Message-ID: On 17/05/2014 15:06, Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> On 17/05/2014 13:52, Albert van der Horst wrote: >>> >>> Now translate E=mc^2 into Java. >>> >> >> I can't do that as I simply don't understand it. What has the >> Marylebone Cricket Club got to do with E? > > A wicket looks like an E on its side. Does that help? > Ah, now I get it, thanks for that :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From albert at spenarnc.xs4all.nl Sat May 17 10:26:06 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 17 May 2014 14:26:06 GMT Subject: Values and objects References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5377717e$0$27137$e4fe514c@dreader35.news.xs4all.nl> In article <536decca$0$29980$c3e8da3$5496439d at news.astraweb.com>, >Personally, I don't imagine that there ever could be a language where >variables were first class values *exactly* the same as ints, strings, >floats etc. Otherwise, how could you tell the difference between a >function which operated on the variable itself, and one which operated on >the value contained by the value? The best you can do is for variables to >be "second class" -- you can do these things to them, but you need >special syntax or declarations to tell the compiler you're operating on >the variable rather than the variable's value. E.g. Pascal and Algol have >syntax for instructing the compiler when to pass a variable as a value, >and when to pass the value. C gives you nothing. You're talking about Algol, but there is a great distinction between Algol60 and Algol68. Algol68 through the ref keyword goes a long way towards making variables first class citizens. E.g. although `` int i'' in Algol68 means practically the same as in C, it is defined as being an abbreviation of 'ref' 'int' i = 'loc' 'int'; This means so much that i is a reference to an otherwise unnamed int that is allocated locally. Furthermore you can't break the tie between i and that int (because you use =, you could have used := ) Because I refers to that location you can change it by i:=1; Note that the left side *must* be a reference. You can't change an int, you can only change the content of a memory place you can refer to. Now you can define 'ref' 'int' pi; pi := i; van Wijngaarden and crue pretty much nailed it, IMO. >-- >Steven D'Aprano >http://import-that.dreamwidth.org/ Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From roland at rptd.ch Sat May 17 11:28:05 2014 From: roland at rptd.ch (=?UTF-8?B?Um9sYW5kIFBsw7xzcw==?=) Date: Sat, 17 May 2014 17:28:05 +0200 Subject: Loading modules from files through C++ In-Reply-To: References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> Message-ID: <53778005.8030105@rptd.ch> On 05/17/2014 04:01 PM, Stefan Behnel wrote: > Hi, > > please avoid top-posting. > > > Roland Pl?ss, 17.05.2014 15:49: >> On 05/17/2014 03:26 PM, Stefan Behnel wrote: >>> Roland Pl?ss, 17.05.2014 15:00: >>>> On 05/17/2014 01:58 PM, Stefan Behnel wrote: >>>>> Roland Pl?ss, 17.05.2014 02:27: >>>>>> I'm using Python in an embedded situation. In particular I have to load >>>>>> python scripts through a memory interface so regular python module >>>>>> loading can not be used. I got working so far a module loader object >>>>>> I've added using C++ to sys.meta_path . Now I'm totally stuck at the >>>>>> finally loading step. >>>>>> >>>>>> I've got this a C++ loader method "load_module(fullname)" which does >>>>>> load the requested module script files into a null-terminated string. I >>>>>> know that "load_module" has to return the module PyObject*. But I can't >>>>>> get the python source in the c-string into a module PyObject*. >>>>>> [...] >>>>>> Can anybody help how in gods name one is supposed to create a module >>>>>> from an in-memory c-string when called from within load_module (or >>>>>> anywhere)? >>>>> Looks like you want to implement a SourceLoader: >>>>> >>>>> https://docs.python.org/3.4/library/importlib.html#importlib.abc.SourceLoader >>>>> >>>>> I recommend implementing this in Python code instead of C code, though. >>>>> Much easier. Cython can help with the integration between both. >>>> That doesn't work in 2.x, doesn't it? >>> Is there a reason you have to use Py2? >>> >>> Anyway, PEP 302 predates Py3 by a couple of years: >>> >>> http://legacy.python.org/dev/peps/pep-0302/ >> I'm willing to go to Py3 but only if the solution to the problem is >> simpler than getting it fixed in Py2. So some questions first: >> >> - does this importlib stuff you showed there apply to C++ land (I need >> to fully drive it from C++ not Python code)? > As I said, implementing this in Python code is much simpler than doing it > in C/C++ code. Basically, stop where you got the C string and do the rest > in Python. All your C code has to do is to take a module lookup request > from your custom Python module Finder and return a byte string with the > code. Then let your Python code wrap that in a Loader and return it to the > import machinery. I don't get how this is supposed to work. I'm running it as fully embedded Python. There is no main script. The builtin modules are added as C++ bound classes and a user made main script is loaded but not run directly (I'm hooking into a create object). For this purpose I load the script module using C++ code using PyImport_ImportModule(moduleName). At this time the module loading code has to kick in already (I've added this one by C++ too before). The problem is now that in this call I end up in my C++ loader version where there is no Python script involved. I came to the conclusion that I can solve this only by having the C++ end properly load the module. I could add Python code with PyRun_SimpleString but then I'm down to the same problem as before: how to evaluate code so it is attached to a module or type-class? As I understand it the problem is the same as before just pushed around a bit. >> - is the C++ land of Py3 similar to Py2 or totally different? > Much the same, just slight differences. As I said, Cython can help with the > integration and would mostly cover the differences for you. Sounds good. I'll give it a try > > Stefan > > -- Yours sincerely Pl?ss Roland Leader and Head Programmer - Game: Epsylon ( http://www.indiedb.com/games/epsylon ) - Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine , http://dragengine.rptd.ch/wiki ) - Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php ) - As well as various Blender export scripts und game tools -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 263 bytes Desc: OpenPGP digital signature URL: From stefan_ml at behnel.de Sat May 17 11:49:06 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 17 May 2014 17:49:06 +0200 Subject: Loading modules from files through C++ In-Reply-To: <53778005.8030105@rptd.ch> References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> <53778005.8030105@rptd.ch> Message-ID: Roland Pl?ss, 17.05.2014 17:28: > On 05/17/2014 04:01 PM, Stefan Behnel wrote: >> Roland Pl?ss, 17.05.2014 15:49: >>> On 05/17/2014 03:26 PM, Stefan Behnel wrote: >>>> Roland Pl?ss, 17.05.2014 15:00: >>>>> On 05/17/2014 01:58 PM, Stefan Behnel wrote: >>>>>> Roland Pl?ss, 17.05.2014 02:27: >>>>>>> I'm using Python in an embedded situation. In particular I have to load >>>>>>> python scripts through a memory interface so regular python module >>>>>>> loading can not be used. I got working so far a module loader object >>>>>>> I've added using C++ to sys.meta_path . Now I'm totally stuck at the >>>>>>> finally loading step. >>>>>>> >>>>>>> I've got this a C++ loader method "load_module(fullname)" which does >>>>>>> load the requested module script files into a null-terminated string. I >>>>>>> know that "load_module" has to return the module PyObject*. But I can't >>>>>>> get the python source in the c-string into a module PyObject*. >>>>>>> [...] >>>>>>> Can anybody help how in gods name one is supposed to create a module >>>>>>> from an in-memory c-string when called from within load_module (or >>>>>>> anywhere)? >>>>>> Looks like you want to implement a SourceLoader: >>>>>> >>>>>> https://docs.python.org/3.4/library/importlib.html#importlib.abc.SourceLoader >>>>>> >>>>>> I recommend implementing this in Python code instead of C code, though. >>>>>> Much easier. Cython can help with the integration between both. >>>>> That doesn't work in 2.x, doesn't it? >>>> Is there a reason you have to use Py2? >>>> >>>> Anyway, PEP 302 predates Py3 by a couple of years: >>>> >>>> http://legacy.python.org/dev/peps/pep-0302/ >>> I'm willing to go to Py3 but only if the solution to the problem is >>> simpler than getting it fixed in Py2. So some questions first: >>> >>> - does this importlib stuff you showed there apply to C++ land (I need >>> to fully drive it from C++ not Python code)? >> As I said, implementing this in Python code is much simpler than doing it >> in C/C++ code. Basically, stop where you got the C string and do the rest >> in Python. All your C code has to do is to take a module lookup request >> from your custom Python module Finder and return a byte string with the >> code. Then let your Python code wrap that in a Loader and return it to the >> import machinery. > > I don't get how this is supposed to work. I'm running it as fully > embedded Python. There is no main script. The builtin modules are added > as C++ bound classes and a user made main script is loaded but not run > directly (I'm hooking into a create object). For this purpose I load the > script module using C++ code using PyImport_ImportModule(moduleName). At > this time the module loading code has to kick in already (I've added > this one by C++ too before). The problem is now that in this call I end > up in my C++ loader version where there is no Python script involved. I > came to the conclusion that I can solve this only by having the C++ end > properly load the module. I could add Python code with > PyRun_SimpleString but then I'm down to the same problem as before: how > to evaluate code so it is attached to a module or type-class? As I > understand it the problem is the same as before just pushed around a bit. No, just run some Python code (using PyRun_SimpleString() if you have to) and let it do whatever you like. Such as, defining a Finder class and injecting it into the import hook. Just provide it with the entry point of your C++ loader as a (CFunction) object when you execute it, and then let it call that function at need whenever the Finder gets executed. Alternatively, compile your Python integration code with Cython and link it into your main program as yet another binary extension module. Stefan From roland at rptd.ch Sat May 17 12:28:18 2014 From: roland at rptd.ch (=?UTF-8?B?Um9sYW5kIFBsw7xzcw==?=) Date: Sat, 17 May 2014 18:28:18 +0200 Subject: Loading modules from files through C++ In-Reply-To: References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> <53778005.8030105@rptd.ch> Message-ID: <53778E22.3040701@rptd.ch> On 05/17/2014 05:49 PM, Stefan Behnel wrote: > Roland Pl?ss, 17.05.2014 17:28: >> On 05/17/2014 04:01 PM, Stefan Behnel wrote: >>> Roland Pl?ss, 17.05.2014 15:49: >>>> On 05/17/2014 03:26 PM, Stefan Behnel wrote: >>>>> Roland Pl?ss, 17.05.2014 15:00: >>>>>> On 05/17/2014 01:58 PM, Stefan Behnel wrote: >>>>>>> Roland Pl?ss, 17.05.2014 02:27: >>>>>>>> I'm using Python in an embedded situation. In particular I have to load >>>>>>>> python scripts through a memory interface so regular python module >>>>>>>> loading can not be used. I got working so far a module loader object >>>>>>>> I've added using C++ to sys.meta_path . Now I'm totally stuck at the >>>>>>>> finally loading step. >>>>>>>> >>>>>>>> I've got this a C++ loader method "load_module(fullname)" which does >>>>>>>> load the requested module script files into a null-terminated string. I >>>>>>>> know that "load_module" has to return the module PyObject*. But I can't >>>>>>>> get the python source in the c-string into a module PyObject*. >>>>>>>> [...] >>>>>>>> Can anybody help how in gods name one is supposed to create a module >>>>>>>> from an in-memory c-string when called from within load_module (or >>>>>>>> anywhere)? >>>>>>> Looks like you want to implement a SourceLoader: >>>>>>> >>>>>>> https://docs.python.org/3.4/library/importlib.html#importlib.abc.SourceLoader >>>>>>> >>>>>>> I recommend implementing this in Python code instead of C code, though. >>>>>>> Much easier. Cython can help with the integration between both. >>>>>> That doesn't work in 2.x, doesn't it? >>>>> Is there a reason you have to use Py2? >>>>> >>>>> Anyway, PEP 302 predates Py3 by a couple of years: >>>>> >>>>> http://legacy.python.org/dev/peps/pep-0302/ >>>> I'm willing to go to Py3 but only if the solution to the problem is >>>> simpler than getting it fixed in Py2. So some questions first: >>>> >>>> - does this importlib stuff you showed there apply to C++ land (I need >>>> to fully drive it from C++ not Python code)? >>> As I said, implementing this in Python code is much simpler than doing it >>> in C/C++ code. Basically, stop where you got the C string and do the rest >>> in Python. All your C code has to do is to take a module lookup request >>> from your custom Python module Finder and return a byte string with the >>> code. Then let your Python code wrap that in a Loader and return it to the >>> import machinery. >> I don't get how this is supposed to work. I'm running it as fully >> embedded Python. There is no main script. The builtin modules are added >> as C++ bound classes and a user made main script is loaded but not run >> directly (I'm hooking into a create object). For this purpose I load the >> script module using C++ code using PyImport_ImportModule(moduleName). At >> this time the module loading code has to kick in already (I've added >> this one by C++ too before). The problem is now that in this call I end >> up in my C++ loader version where there is no Python script involved. I >> came to the conclusion that I can solve this only by having the C++ end >> properly load the module. I could add Python code with >> PyRun_SimpleString but then I'm down to the same problem as before: how >> to evaluate code so it is attached to a module or type-class? As I >> understand it the problem is the same as before just pushed around a bit. > No, just run some Python code (using PyRun_SimpleString() if you have to) > and let it do whatever you like. Such as, defining a Finder class and > injecting it into the import hook. Just provide it with the entry point of > your C++ loader as a (CFunction) object when you execute it, and then let > it call that function at need whenever the Finder gets executed. > > Alternatively, compile your Python integration code with Cython and link it > into your main program as yet another binary extension module. > > Stefan > > I'm not using Cython so that's out of question. Concerning the injection how would this work? From the PEP I assume it would have to look like this: # CODE # import sys class VFSModuleLoader: def find_module(fullname, path=None): return self if VFS.exists( vfsPathFromFullname(fullname) ) else None def load_module(fullname): sourceCode = VFS.read( vfsPathFromFullname(fullname)) ??? # CODE # How does ??? work? If I use "eval" I end up with the code inside VFSModuleLoader.load_modules as context but it should go into the global context as an own module. -- Yours sincerely Pl?ss Roland Leader and Head Programmer - Game: Epsylon ( http://www.indiedb.com/games/epsylon ) - Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine , http://dragengine.rptd.ch/wiki ) - Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php ) - As well as various Blender export scripts und game tools -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 263 bytes Desc: OpenPGP digital signature URL: From breamoreboy at yahoo.co.uk Sat May 17 12:59:30 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 17 May 2014 17:59:30 +0100 Subject: Problem building 3.5 on Windows Message-ID: First time in months I've tried building, first time I've ever had a problem that I can't solve for myself. I'm using Visual C++ 2010 Express. 1>------ Build started: Project: make_versioninfo, Configuration: Debug Win32 ------ 1> make_versioninfo.c 1>..\PC\make_versioninfo.c(1): fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory 2>------ Build started: Project: kill_python, Configuration: Debug Win32 ------ 2> kill_python.c 2>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\windows.h(151): fatal error C1083: Cannot open include file: 'excpt.h': No such file or directory 3>------ Build started: Project: make_buildinfo, Configuration: Release Win32 ------ 3> make_buildinfo.c 3>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\windows.h(151): fatal error C1083: Cannot open include file: 'excpt.h': No such file or directory etc. What stupid thing have I forgotten, apart from switching to *nix? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From stefan_ml at behnel.de Sat May 17 13:05:06 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 17 May 2014 19:05:06 +0200 Subject: Loading modules from files through C++ In-Reply-To: <53778E22.3040701@rptd.ch> References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> <53778005.8030105@rptd.ch> <53778E22.3040701@rptd.ch> Message-ID: Roland Pl?ss, 17.05.2014 18:28: > On 05/17/2014 05:49 PM, Stefan Behnel wrote: >> Roland Pl?ss, 17.05.2014 17:28: >>> On 05/17/2014 04:01 PM, Stefan Behnel wrote: >>>> Roland Pl?ss, 17.05.2014 15:49: >>>>> On 05/17/2014 03:26 PM, Stefan Behnel wrote: >>>>>> Roland Pl?ss, 17.05.2014 15:00: >>>>>>> On 05/17/2014 01:58 PM, Stefan Behnel wrote: >>>>>>>> Roland Pl?ss, 17.05.2014 02:27: >>>>>>>>> I'm using Python in an embedded situation. In particular I have to load >>>>>>>>> python scripts through a memory interface so regular python module >>>>>>>>> loading can not be used. I got working so far a module loader object >>>>>>>>> I've added using C++ to sys.meta_path . Now I'm totally stuck at the >>>>>>>>> finally loading step. >>>>>>>>> >>>>>>>>> I've got this a C++ loader method "load_module(fullname)" which does >>>>>>>>> load the requested module script files into a null-terminated string. I >>>>>>>>> know that "load_module" has to return the module PyObject*. But I can't >>>>>>>>> get the python source in the c-string into a module PyObject*. >>>>>>>>> [...] >>>>>>>>> Can anybody help how in gods name one is supposed to create a module >>>>>>>>> from an in-memory c-string when called from within load_module (or >>>>>>>>> anywhere)? >>>>>>>> Looks like you want to implement a SourceLoader: >>>>>>>> >>>>>>>> https://docs.python.org/3.4/library/importlib.html#importlib.abc.SourceLoader >>>>>>>> >>>>>>>> I recommend implementing this in Python code instead of C code, though. >>>>>>>> Much easier. Cython can help with the integration between both. >>>>>>> That doesn't work in 2.x, doesn't it? >>>>>> Is there a reason you have to use Py2? >>>>>> >>>>>> Anyway, PEP 302 predates Py3 by a couple of years: >>>>>> >>>>>> http://legacy.python.org/dev/peps/pep-0302/ >>>>> I'm willing to go to Py3 but only if the solution to the problem is >>>>> simpler than getting it fixed in Py2. So some questions first: >>>>> >>>>> - does this importlib stuff you showed there apply to C++ land (I need >>>>> to fully drive it from C++ not Python code)? >>>> As I said, implementing this in Python code is much simpler than doing it >>>> in C/C++ code. Basically, stop where you got the C string and do the rest >>>> in Python. All your C code has to do is to take a module lookup request >>>> from your custom Python module Finder and return a byte string with the >>>> code. Then let your Python code wrap that in a Loader and return it to the >>>> import machinery. >>> I don't get how this is supposed to work. I'm running it as fully >>> embedded Python. There is no main script. The builtin modules are added >>> as C++ bound classes and a user made main script is loaded but not run >>> directly (I'm hooking into a create object). For this purpose I load the >>> script module using C++ code using PyImport_ImportModule(moduleName). At >>> this time the module loading code has to kick in already (I've added >>> this one by C++ too before). The problem is now that in this call I end >>> up in my C++ loader version where there is no Python script involved. I >>> came to the conclusion that I can solve this only by having the C++ end >>> properly load the module. I could add Python code with >>> PyRun_SimpleString but then I'm down to the same problem as before: how >>> to evaluate code so it is attached to a module or type-class? As I >>> understand it the problem is the same as before just pushed around a bit. >> No, just run some Python code (using PyRun_SimpleString() if you have to) >> and let it do whatever you like. Such as, defining a Finder class and >> injecting it into the import hook. Just provide it with the entry point of >> your C++ loader as a (CFunction) object when you execute it, and then let >> it call that function at need whenever the Finder gets executed. >> >> Alternatively, compile your Python integration code with Cython and link it >> into your main program as yet another binary extension module. > > I'm not using Cython so that's out of question. Concerning the injection > how would this work? From the PEP I assume it would have to look like this: > > # CODE # > import sys > class VFSModuleLoader: > def find_module(fullname, path=None): > return self if VFS.exists( vfsPathFromFullname(fullname) ) else None > def load_module(fullname): > sourceCode = VFS.read( vfsPathFromFullname(fullname)) > ??? > # CODE # > > How does ??? work? If I use "eval" I end up with the code inside > VFSModuleLoader.load_modules as context but it should go into the global > context as an own module. Yeah, well, the import machinery is rather badly exposed in Py2. This got much cleaner in Py3, especially 3.3/3.4. Here's a hacky way to do it in Py2: import imp module = imp.new_module(module_name) module.__importer__ = self exec source_code in module.__dict__ return module Found here: http://hg.python.org/cpython/file/568041fd8090/Lib/imputil.py#l284 You may have to set a couple of more special attributes on the module (__name__? __path__? __package__? others?), but the above should at least work. Stefan From rosuav at gmail.com Sat May 17 13:05:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 May 2014 03:05:30 +1000 Subject: Problem building 3.5 on Windows In-Reply-To: References: Message-ID: On Sun, May 18, 2014 at 2:59 AM, Mark Lawrence wrote: > 1>..\PC\make_versioninfo.c(1): fatal error C1083: Cannot open include file: > 'stdio.h': No such file or directory > > What stupid thing have I forgotten, apart from switching to *nix? :) Well, apart from that... I'd guess you have a pathing problem. Since stdio.h is a standard compiler-provided header, I'd advise locating it on disk, then checking if that path is in the INCLUDE env var. Not sure if the Python build process overrides that, though, but it's a start. ChrisA From rustompmody at gmail.com Sat May 17 13:46:28 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 17 May 2014 10:46:28 -0700 (PDT) Subject: PEP 8 : Maximum line Length : In-Reply-To: References: <51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com> <53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <7e8afb04-d563-4cac-9957-32bd6b0d4dec@googlegroups.com> On Saturday, May 17, 2014 7:36:19 PM UTC+5:30, Roy Smith wrote: > > Mark Lawrence wrote: > > > Now translate E=mc^2 into Java. > > > > > > > I can't do that as I simply don't understand it. What has the > > Marylebone Cricket Club got to do with E? > > A wicket looks like an E on its side. Does that help? Heh! Imaginative! Now spend your life meditating on all the glyphs that inhabit unicode. And mon cher u-no-hoo will award you with an epiphany. From breamoreboy at yahoo.co.uk Sat May 17 15:06:28 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 17 May 2014 20:06:28 +0100 Subject: Problem building 3.5 on Windows In-Reply-To: References: Message-ID: On 17/05/2014 18:05, Chris Angelico wrote: > On Sun, May 18, 2014 at 2:59 AM, Mark Lawrence wrote: >> 1>..\PC\make_versioninfo.c(1): fatal error C1083: Cannot open include file: >> 'stdio.h': No such file or directory >> >> What stupid thing have I forgotten, apart from switching to *nix? :) > > Well, apart from that... I'd guess you have a pathing problem. Since > stdio.h is a standard compiler-provided header, I'd advise locating it > on disk, then checking if that path is in the INCLUDE env var. Not > sure if the Python build process overrides that, though, but it's a > start. > > ChrisA > Solved as you got me looking in a different direction. It certainly helps if you have an up to date version of the SDK :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Sat May 17 15:08:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 May 2014 05:08:40 +1000 Subject: Problem building 3.5 on Windows In-Reply-To: References: Message-ID: On Sun, May 18, 2014 at 5:06 AM, Mark Lawrence wrote: > Solved as you got me looking in a different direction. It certainly helps > if you have an up to date version of the SDK :) Hah. I don't know which versions of Visual Studio Express go with which versions of Python, but I know there is a strict correspondence (in terms of official builds and support, at least). ChrisA From breamoreboy at yahoo.co.uk Sat May 17 16:24:03 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 17 May 2014 21:24:03 +0100 Subject: Problem building 3.5 on Windows In-Reply-To: References: Message-ID: On 17/05/2014 20:08, Chris Angelico wrote: > On Sun, May 18, 2014 at 5:06 AM, Mark Lawrence wrote: >> Solved as you got me looking in a different direction. It certainly helps >> if you have an up to date version of the SDK :) > > Hah. I don't know which versions of Visual Studio Express go with > which versions of Python, but I know there is a strict correspondence > (in terms of official builds and support, at least). > > ChrisA > I have Visual Studio Express 2010 but the SDK was 7.0 instead of 7.1. I'm now waiting for the Visual Studio Express 2010 SP1 which fixes the linker problem. And I've just got "restart now to finsih installing" after maybe one hour:) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From robert.kern at gmail.com Sat May 17 17:01:14 2014 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 17 May 2014 22:01:14 +0100 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <53776ee4$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> <877g5lm3yq.fsf@elektro.pacujo.net> <53776ee4$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-05-17 15:15, Steven D'Aprano wrote: > On Sat, 17 May 2014 10:29:00 +0100, Robert Kern wrote: > >> One can state many things, but that doesn't mean they have legal effect. >> The US Code has provisions for how works become copyrighted >> automatically, how they leave copyright automatically at the end of >> specific time periods, how some works automatically enter the public >> domain on their creation (i.e. works of the US federal government), but >> has nothing at all for how a private creator can voluntarily place their >> work into the public domain when it would otherwise not be. It used to, >> but does not any more. > > The case for abandonment was stated as "well settled" in 1998 (Micro-Star > v. Formgen Inc). Unless there has been a major legal change in the years > since then, I don't think it is true that authors cannot abandon > copyright. Good old Micro-Star v. Formgen Inc. A perennial favorite. No, that case did not settle this question. There is a statement in the opinion that would suggest this, but (and this seems to be a reoccurring theme) it's inclusion in the opinion did not create precedent to that effect. The statement that you refer to is, as far as my NAL eyes can tell, what the lawyers call "dictum": a statement made by a judicial opinion but is unnecessary to decide the case and therefore not precedential. FormGen explicitly registered the copyright to the works in question, and the case was decided on whether or not the Micro-Star-redistributed works counted as derivative works (yes). Now, if the case were about an author that affirmatively dedicated his work to the public domain and then sued someone who redistributed it, then such a statement would have a precedential effect (because then the judge would decide in favor of the defendant on the basis of that statement). The quote that you refer to references a previous case, which follows similar lines, and also predates the "automatic copyright" regime post-Berne Convention, so it's not even clear to me that it should have been precedential to Micro-Star. Even if this case did so decide (which, I will grant it more or less did later by codifying such a rule in their jury instructions for such cases), it would only have effect in the 9th Circuit of the US and not even in the rest of the US, much less worldwide. Why bother when the CC0 gives you the desired effect with more assurance to your audience? >> For a private individual to say about a work they just created that >> "this work is in the Public Domain" is, under US law, merely an >> erroneous statement of fact, not a speech act that effects a change in >> the legal status of the work. For another example of this distinction, >> saying "I am married" when I have not applied for, received, and >> solemnified a valid marriage license is just an erroneous statement of >> fact and does not make me legally married. > > There may be something to what you say, although I think we're now > arguing fine semantic details. Sure, it's the law. Fine semantic details are important. However, the difference between speech acts and statements of fact is a pretty gross semantic distinction and not just splitting semantic hairs. The act of making some statements (e.g. declaring that a work you own the copyright to is available under a given license) actually makes a change in the legal status of something. Most statements don't. Which ones do and don't are defined by statute and (in common law countries like the US) court decisions. Deciding which is which is often hairy, but that's an epistemological problem, not a semantic one. :-) > See: > > https://en.wikipedia.org/wiki/Wikipedia:Granting_work_into_the_public_domain > > To play Devil's Advocate in favour of your assertion, it may be that > abandoning copyright does not literally put the work in the public > domain, but merely makes it "quack like the public domain". That is to > say, the author still, in some abstract but legally meaningless sense, > has copyright in the work *but* has given unlimited usage rights. (I > don't actually think that is the case, at least not in the US.) > > It's this tiny bit of residual uncertainty that leads some authorities to > say that it is "hard" to release a work into the public domain, > particularly in a world-wide context, and that merely stating "this is in > the public domain" is not sufficient to remove all legal doubt over the > status, and that a more overt and explicit release *may* be required. > Hence the CC0 licence which you refer to. The human readable summary says > in part: > > The person who associated a work with this deed has dedicated > the work to the public domain by waiving all of his or her > rights to the work worldwide under copyright law, including > all related and neighboring rights, to the extent allowed by > law. > > You can copy, modify, distribute and perform the work, even > for commercial purposes, all without asking permission. > > http://creativecommons.org/publicdomain/zero/1.0/ > > while the actual legal licence comes in at almost 800 words. This is > basically the same as "I release this to the public domain" only longer. Quite so. Except that the CC0 statement may actually survive probate court if your heirs decide that whatever you released is valuable enough to claw back. Yes, your heirs can disregard many of the statements (even some bona fide speech acts!) that you make during your life if they can demonstrate that it recklessly diminished their inheritance. A simple statement that a work is in the public domain is much more risky in that situation because it does not fall back on standard licensing law when the abandonment of copyright fails. The CC0 has your back in that case. > (The CC0 licence is longer than you might expect, because it is assumed > that it may have to apply in countries where you *really cannot* > relinquish copyright. But we're specifically talking about the US, where > the 9th Circuit says you can.) The 9th Circuit speaks for the 9th Circuit, not the entire US jurisdiction. They often wish otherwise, but there you go. :-) >> Relinquishing your rights can have some effect, but not all rights can >> be relinquished, > > Outside of the US, so-called "moral rights" or "reputation rights" cannot > generally be relinquished, except perhaps in work-for-hire and perhaps > not even then. (E.g. if you're a ghost writer.) The situation in the US > is a bit murky -- there are no official moral rights per se, and > copyright only controls usage rights such as copying, distribution and so > forth. But this doesn't mean that you can (for example) claim authorship > of a public domain work unless you actually wrote it. > > In any case, we're discussing copyright, not other rights. > > >> and this is not the same as putting your work into the >> public domain. > > One might "not be the same" while still being "effectively the same". For > example, the U.S. Copyright Office states that "one may not grant their > work into the public domain. However, a copyright owner may release all > of their rights to their work by stating the work may be freely > reproduced, distributed, etc." as if it were in in the public domain. I agree. The CC0 is about the closest that you can get to this. I enter this discussion primarily to contest the assert that the simple, one-sentence "this work is in the public domain" declarations will reliably have this effect. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From robert.kern at gmail.com Sat May 17 17:07:49 2014 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 17 May 2014 22:07:49 +0100 Subject: Everything you did not want to know about Unicode in Python 3 In-Reply-To: <537750fc$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <82899649-014a-4309-b06e-b981fc6921fa@googlegroups.com> <201405130145.05995.gheskett@wdtv.com> <857g5q9pvk.fsf@benfinney.id.au> <53722081$0$29980$c3e8da3$5496439d@news.astraweb.com> <5372b091$0$29977$c3e8da3$5496439d@news.astraweb.com> <5xJcv.77901$dT1.66255@fx12.am4> <5376b63b$0$29977$c3e8da3$5496439d@news.astraweb.com> <537750fc$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-05-17 13:07, Steven D'Aprano wrote: > On Sat, 17 May 2014 09:57:06 +0100, Robert Kern wrote: > >> On 2014-05-17 02:07, Steven D'Aprano wrote: >>> On Fri, 16 May 2014 14:46:23 +0000, Grant Edwards wrote: >>> >>>> At least in the US, there doesn't seem to be such a thing as "placing >>>> a work into the public domain". The copyright holder can transfer >>>> ownershipt to soembody else, but there is no "public domain" to which >>>> ownership can be trasferred. >>> >>> That's factually incorrect. In the US, sufficiently old works, or works >>> of a certain age that were not explicitly registered for copyright, are >>> in the public domain. Under a wide range of circumstances, works >>> created by the federal government go immediately into the public >>> domain. >> >> There is such a thing as the public domain in the US, and there are >> works in it, but there isn't really such a thing as "placing a work" >> there voluntarily, as Grant says. A work either is or isn't in the >> public domain. The author has no choice in the matter. > > That's incorrect. > > http://cr.yp.to/publicdomain.html Thanks for the link. While it has not really changed my opinion (as discussed at length in my other reply), I did not know that the 9th Circuit had formalized the "overt act" test in their civil procedure rules, so there is at least one jurisdiction in the US that does currently work like this. None of the others do, to my knowledge, and this is the product of judicial common law, not statutory law, so it's still pretty shaky. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From cmpython at gmail.com Sat May 17 19:53:39 2014 From: cmpython at gmail.com (CM) Date: Sat, 17 May 2014 16:53:39 -0700 (PDT) Subject: using a new computer and bringing needed libraries to it Message-ID: If I want to switch my work from one computer to a new one, and I have lots of various libraries installed on the original computer, what's the best way to switch that all to the new computer? I'm hoping there is some simple way like just copying the Python/Lib/site-packages folder, but I'm also guessing this isn't sufficient. I was hoping I wouldn't have to just one-by-one install all of those libraries again on the newer computer. I probably want to develop on BOTH these computers for the time being, too. One is at home and one is at a "remote site"/secret lair. And then I'll be doing it again when I buy a newer computer at some point. Thanks. From varun7rs at gmail.com Sat May 17 19:56:42 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Sat, 17 May 2014 16:56:42 -0700 (PDT) Subject: Can't figure out 'instance has no attribute' error Message-ID: Hello Friends, I am working on this code but I kind of get the same error over and over again. Could any of you help me fix this part of the error? File RW1: class PHY_NETWORK: def __init__(self, nodes, edges): self.nodes = nodes self.edges = edges def addNode(self, node): self.nodes.append( node ) def addEdge(self, edge): self.edges.append( edge ) File RW3: def createnetwork(graph): doc = parse( args.paramFile ) noderef = [] num = 0 nodelist = doc.getElementsByTagName("node") for node in nodelist: noderef.append(node.getAttribute("id")) proc = random.randint(3500, 5000) stor = random.randint(7200, 8200) switch = random.randint(7000, 10000) num = num + 1 totaldemands = random.randint(1, 5) graph.addNode(PHY_NODES( node.getAttribute("id"), int(num), float(xCoordinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch), int(totaldemands))) linkid = 0 linklist = doc.getElementsByTagName("link") for link in linklist : linkid = linkid + 1 Source = link.getElementsByTagName("source") [0] Destination = link.getElementsByTagName("target") [0] Capacity = link.getElementsByTagName("capacity") [0] SourceID = noderef.index(Source.firstChild.data) + 1 DestinationID = noderef.index(Destination.firstChild.data) + 1 graph.addEdge( PHY_LINKS( linkid, Source.firstChild.data, Destination.firstChild.data, DestinationID, SourceID, float(Capacity.firstChild.data) )) global args args = parser.parse_args() samplenetwork = PHY_NETWORK([], []) for i in range(1, 100): createnetwork(samplenetwork) exportXmlFile(samplenetwork, args.output, 'a' ) if __name__ == "__main__": main(sys.argv[1:]) srva at hades:~$ python RW3.py --output topology.xml --xml germany50.xml Traceback (most recent call last): File "RW3.py", line 157, in main(sys.argv[1:]) File "RW3.py", line 152, in main createnetwork(samplenetwork) File "RW3.py", line 31, in createnetwork graph.addNode(PHY_NODES( node.getAttribute("id"), int(num), float(xCoordinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch), int(totaldemands))) AttributeError: PHY_NETWORK instance has no attribute 'addNode' The error that it give back is as above. I have the classes defined in RW1 file and I am importing the classes onto RW3 file and yet, It doesn't seem to work. I really am in need of your valuable suggestions. Thank You From ned at nedbatchelder.com Sat May 17 20:16:01 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 17 May 2014 20:16:01 -0400 Subject: Can't figure out 'instance has no attribute' error In-Reply-To: References: Message-ID: On 5/17/14 7:56 PM, varun7rs at gmail.com wrote: > Hello Friends, > > I am working on this code but I kind of get the same error over and over again. Could any of you help me fix this part of the error? > > File RW1: > class PHY_NETWORK: > def __init__(self, nodes, edges): > self.nodes = nodes > self.edges = edges > > def addNode(self, node): > self.nodes.append( node ) > > def addEdge(self, edge): > self.edges.append( edge ) > ... > > > srva at hades:~$ python RW3.py --output topology.xml --xml germany50.xml > Traceback (most recent call last): > File "RW3.py", line 157, in > main(sys.argv[1:]) > File "RW3.py", line 152, in main > createnetwork(samplenetwork) > File "RW3.py", line 31, in createnetwork > graph.addNode(PHY_NODES( node.getAttribute("id"), int(num), float(xCoordinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch), int(totaldemands))) > AttributeError: PHY_NETWORK instance has no attribute 'addNode' > > > The error that it give back is as above. I have the classes defined in RW1 file and I am importing the classes onto RW3 file and yet, It doesn't seem to work. I really am in need of your valuable suggestions. Thank You > You've set your editor to display tabs as 4 spaces, but then you've sometimes used tabs in your file, and sometimes 4 spaces. Look at how your code is indented in your post: the addNode and addEdge definitions are indented with tab characters instead of spaces, so Python thinks they are eight spaces in. This makes them defined inside of __init__, rather than as part of your class. Set your editor to insert spaces when you use the Tab key, and set it to use 4-space indents. Then find all the tab characters in your file and replace them with the proper number of spaces. -- Ned Batchelder, http://nedbatchelder.com From ned at nedbatchelder.com Sat May 17 20:17:05 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 17 May 2014 20:17:05 -0400 Subject: using a new computer and bringing needed libraries to it In-Reply-To: References: Message-ID: On 5/17/14 7:53 PM, CM wrote: > If I want to switch my work from one computer to a new one, and I have lots of various libraries installed on the original computer, what's the best way to switch that all to the new computer? I'm hoping there is some simple way like just copying the Python/Lib/site-packages folder, but I'm also guessing this isn't sufficient. I was hoping I wouldn't have to just one-by-one install all of those libraries again on the newer computer. > > I probably want to develop on BOTH these computers for the time being, too. One is at home and one is at a "remote site"/secret lair. And then I'll be doing it again when I buy a newer computer at some point. > > Thanks. > Make a list of the packages you need. Put it in a file called requirements.txt. Then install them with: $ pip install -r requirements.txt Keep that file up-to-date as you add new requirements. -- Ned Batchelder, http://nedbatchelder.com From rhodri at wildebst.org.uk Sat May 17 20:24:57 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Sun, 18 May 2014 01:24:57 +0100 Subject: Can't figure out 'instance has no attribute' error References: Message-ID: On Sun, 18 May 2014 00:56:42 +0100, wrote: > Hello Friends, > > I am working on this code but I kind of get the same error over and over > again. Could any of you help me fix this part of the error? Shuffling your post around to make an explanation easier, the traceback is: > srva at hades:~$ python RW3.py --output topology.xml --xml germany50.xml > Traceback (most recent call last): > File "RW3.py", line 157, in > main(sys.argv[1:]) > File "RW3.py", line 152, in main > createnetwork(samplenetwork) > File "RW3.py", line 31, in createnetwork > graph.addNode(PHY_NODES( node.getAttribute("id"), int(num), > float(xCoordinates.firstChild.data), > float(yCoordinates.firstChild.data), float(proc), float(stor), > float(switch), int(totaldemands))) > AttributeError: PHY_NETWORK instance has no attribute 'addNode' So Python thinks that PHY_NETWORK has no "addNode", but you do. Do you perchance have the tab width in your editor set to 4? I ask, because I imagine that you see this: > File RW1: > class PHY_NETWORK: > def __init__(self, nodes, edges): > self.nodes = nodes > self.edges = edges > def addNode(self, node): > self.nodes.append( node ) [snippety snip] I however saw your post like this: > File RW1: > class PHY_NETWORK: > def __init__(self, nodes, edges): > self.nodes = nodes > self.edges = edges > def addNode(self, node): > self.nodes.append( node ) [snippety snip] I've replaced the tabs with spaces to make it clearer. Basically, you've got a mix of tabs and spaces, which is always a bad idea, and as a result Python thinks that addNode is an attribute of PHY_NETWORK.__init__, not of PHY_NETWORK. You need to go through and replace all your tab characters with four spaces, and stop using tabs. -- Rhodri James *-* Wildebeest Herder to the Masses From gary.herron at islandtraining.com Sat May 17 20:16:46 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sat, 17 May 2014 17:16:46 -0700 Subject: Can't figure out 'instance has no attribute' error In-Reply-To: References: Message-ID: <5377FBEE.9030304@islandtraining.com> On 05/17/2014 04:56 PM, varun7rs at gmail.com wrote: > Hello Friends, > > I am working on this code but I kind of get the same error over and over again. Could any of you help me fix this part of the error? It's an indentation error: In the following the three function defs for __init__, addNode and addEdge should all be at the same indentation level. Instead, you have the later two defined *inside* the __init__. Gary Herron > > File RW1: > class PHY_NETWORK: > def __init__(self, nodes, edges): > self.nodes = nodes > self.edges = edges > > def addNode(self, node): > self.nodes.append( node ) > > def addEdge(self, edge): > self.edges.append( edge ) > > File RW3: > def createnetwork(graph): > > > doc = parse( args.paramFile ) > noderef = [] > num = 0 > nodelist = doc.getElementsByTagName("node") > for node in nodelist: > noderef.append(node.getAttribute("id")) > proc = random.randint(3500, 5000) > stor = random.randint(7200, 8200) > switch = random.randint(7000, 10000) > num = num + 1 > totaldemands = random.randint(1, 5) > graph.addNode(PHY_NODES( node.getAttribute("id"), int(num), float(xCoordinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch), int(totaldemands))) > > > linkid = 0 > linklist = doc.getElementsByTagName("link") > for link in linklist : > linkid = linkid + 1 > Source = link.getElementsByTagName("source") [0] > Destination = link.getElementsByTagName("target") [0] > Capacity = link.getElementsByTagName("capacity") [0] > SourceID = noderef.index(Source.firstChild.data) + 1 > DestinationID = noderef.index(Destination.firstChild.data) + 1 > graph.addEdge( PHY_LINKS( linkid, Source.firstChild.data, Destination.firstChild.data, DestinationID, SourceID, float(Capacity.firstChild.data) )) > > > global args > args = parser.parse_args() > > samplenetwork = PHY_NETWORK([], []) > for i in range(1, 100): > createnetwork(samplenetwork) > exportXmlFile(samplenetwork, args.output, 'a' ) > > > if __name__ == "__main__": > main(sys.argv[1:]) > > > srva at hades:~$ python RW3.py --output topology.xml --xml germany50.xml > Traceback (most recent call last): > File "RW3.py", line 157, in > main(sys.argv[1:]) > File "RW3.py", line 152, in main > createnetwork(samplenetwork) > File "RW3.py", line 31, in createnetwork > graph.addNode(PHY_NODES( node.getAttribute("id"), int(num), float(xCoordinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch), int(totaldemands))) > AttributeError: PHY_NETWORK instance has no attribute 'addNode' > > > The error that it give back is as above. I have the classes defined in RW1 file and I am importing the classes onto RW3 file and yet, It doesn't seem to work. I really am in need of your valuable suggestions. Thank You From tjreedy at udel.edu Sat May 17 20:29:18 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 May 2014 20:29:18 -0400 Subject: using a new computer and bringing needed libraries to it In-Reply-To: References: Message-ID: On 5/17/2014 7:53 PM, CM wrote: > If I want to switch my work from one computer to a new one, and I > have lots of various libraries installed on the original computer, > what's the best way to switch that all to the new computer? I'm > hoping there is some simple way like just copying the > Python/Lib/site-packages folder, but I'm also guessing this isn't > sufficient. Have your tried it? Since Python only cares about the contents of site-packages, copying should be fine, at least as far as python is concerned. I have copied pythonx.y/Lib/site-packages to pythonx.(y+1)/Lib/site-packages more than once. In each site-packages, I also have python.pth containing, in my case, "F:/Python". packages and modules in F:/Python are imported the same as if they were in each site-packages. This avoids copying and lets me try the same file on multiple versions. Copying does not copy registry entries or anything outside of site-packages. I do not know whether pip, for instance, does either. -- Terry Jan Reedy From rosuav at gmail.com Sat May 17 20:30:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 May 2014 10:30:26 +1000 Subject: using a new computer and bringing needed libraries to it In-Reply-To: References: Message-ID: On Sun, May 18, 2014 at 10:17 AM, Ned Batchelder wrote: > Make a list of the packages you need. Put it in a file called > requirements.txt. Then install them with: > > $ pip install -r requirements.txt > > Keep that file up-to-date as you add new requirements. +1. And the "keep up-to-date" bit can be done very well with source control; that way, you don't need to wonder whether you added one over here or deleted one over there - the commit history will tell you. ChrisA From ben at benfinney.id.au Sat May 17 22:01:43 2014 From: ben at benfinney.id.au (Ben Finney) Date: Sun, 18 May 2014 12:01:43 +1000 Subject: Pip requirements: Machine-readable configuration versus human-audience documentation (was: using a new computer and bringing needed libraries to it) References: Message-ID: <85r43r6e0o.fsf_-_@benfinney.id.au> Ned Batchelder writes: > Make a list of the packages you need. Put it in a file called > requirements.txt. Then install them with: > > $ pip install -r requirements.txt > > Keep that file up-to-date as you add new requirements. Since these requirements are specifically for Python, more specifically for Pip, and even more specifically are supposed to be in a machine-readable foramt and not just an arbitrary free-form text document, can we recommend instead some more specific filename? ?requirements.txt? is already used in many projects to document *for a human reader* the project-wide requirements, not jsut for Python, and we should not arrogate a general name like that to a specific tool like Pip. I'd recommend (and have already begun to use) the name ?pip_requirements? or the like. I know that there is heaps of Pip-specific documentation out there already recommending the more general name, but I'd like that to change. -- \ ?I believe our future depends powerfully on how well we | `\ understand this cosmos, in which we float like a mote of dust | _o__) in the morning sky.? ?Carl Sagan, _Cosmos_, 1980 | Ben Finney From nospam at nspam.invalid Sat May 17 23:13:11 2014 From: nospam at nspam.invalid (Bill Cunningham) Date: Sat, 17 May 2014 23:13:11 -0400 Subject: Python and Math Message-ID: Does Python have good mathematical capabilities? I am interested in learning a second language for mathematical purposes. I am considering looking at python, perl, fortran, Adas out. It looked too complicated to learn. Perl looked easy and I haven't really looked into python. Bill From rustompmody at gmail.com Sat May 17 23:26:04 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 17 May 2014 20:26:04 -0700 (PDT) Subject: Python and Math In-Reply-To: References: Message-ID: <09bbda59-9c37-44b0-acfc-0571d4fe8fcb@googlegroups.com> On Sunday, May 18, 2014 8:43:11 AM UTC+5:30, Bill Cunningham wrote: > Does Python have good mathematical capabilities? I am interested in > > learning a second language for mathematical purposes. I am considering > > looking at python, perl, fortran, Adas out. It looked too complicated to > > learn. Perl looked easy and I haven't really looked into python. > What does the word 'mathematical' connote for you? On the whole the term is so wide that its hard to answer without some more context. For example there's numpy,scipy for numerical and scientific* computing, there's sage, ipython etc. Today many people who want a general purpose programming language with a mathematical flair, choose Haskell For statistics R is quite unbeatable (I am told), which is not python or any of the others you mention. Then there are specialized theorem proving systems. Another question you should answer is "Whats the first programming language you know?" From rustompmody at gmail.com Sat May 17 23:29:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 17 May 2014 20:29:27 -0700 (PDT) Subject: using a new computer and bringing needed libraries to it In-Reply-To: References: Message-ID: On Sunday, May 18, 2014 5:47:05 AM UTC+5:30, Ned Batchelder wrote: > On 5/17/14 7:53 PM, CM wrote: > > > If I want to switch my work from one computer to a new one, and I > > have lots of various libraries installed on the original computer, > > what's the best way to switch that all to the new computer? I'm > > hoping there is some simple way like just copying the > > Python/Lib/site-packages folder, but I'm also guessing this isn't > > sufficient. I was hoping I wouldn't have to just one-by-one > > install all of those libraries again on the newer computer. > > I probably want to develop on BOTH these computers for the time > > being, too. One is at home and one is at a "remote site"/secret > > lair. And then I'll be doing it again when I buy a newer computer > > at some point. > > Make a list of the packages you need. Put it in a file called > requirements.txt. Then install them with: > > > $ pip install -r requirements.txt > > > Keep that file up-to-date as you add new requirements. What about things installed at a lower level than pip, eg apt-get? From rosuav at gmail.com Sat May 17 23:33:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 May 2014 13:33:02 +1000 Subject: Python and Math In-Reply-To: References: Message-ID: On Sun, May 18, 2014 at 1:13 PM, Bill Cunningham wrote: > Does Python have good mathematical capabilities? I am interested in > learning a second language for mathematical purposes. I am considering > looking at python, perl, fortran, Adas out. It looked too complicated to > learn. Perl looked easy and I haven't really looked into python. Absolutely it does! In the built-in types, your integer has arbitrary precision, and there is an arbitrary-precision Decimal type in the standard library. There is also, naturally, a standard set of trig functions and so on. With additional libraries, you can get numeric and scientific functionality (lots of which is written in Fortran, as I understand it), giving incredibly high performance for a high level language; look into SciPy and NumPy. Strongly recommend Python for numeric work. ChrisA From jcasale at activenetwerx.com Sun May 18 00:08:00 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 18 May 2014 04:08:00 +0000 Subject: Problem building 3.5 on Windows In-Reply-To: References: , Message-ID: <5F31294B-2669-475F-899B-62ED4F05C169@activenetwerx.com> Mark, Excuse the format of this post, stuck on the road only with an iPhone but in the event it helps, http://blog.vrplumber.com/b/2014/02/12/step-2-get-amd64-compatible-vs-2010/ may be useful. Jlc -------------- next part -------------- An HTML attachment was scrubbed... URL: From gary.herron at islandtraining.com Sun May 18 00:12:17 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sat, 17 May 2014 21:12:17 -0700 Subject: Python and Math In-Reply-To: References: Message-ID: <53783321.3080404@islandtraining.com> On 05/17/2014 08:13 PM, Bill Cunningham wrote: > Does Python have good mathematical capabilities? I am interested in > learning a second language for mathematical purposes. I am considering > looking at python, perl, fortran, Adas out. It looked too complicated to > learn. Perl looked easy and I haven't really looked into python. > > Bill Depends on what you mean by mathematics. The language itself has a reasonable set of numeric types and operations on those types, but what really makes Python shine is the libraries built on Python and their capabilities. Beside the several already mentioned, I'll add Sage: www.sagemath.org/index.html which presents a consistent Python interface to nearly 100 OpenSource mathematical packages containing symbolic manipulation of all sorts of algebra, calculus, linear algebra, plotting, rings and groups, and much *much* more. Gary Herron From steve+comp.lang.python at pearwood.info Sun May 18 00:51:43 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 May 2014 04:51:43 GMT Subject: Python and Math References: Message-ID: <53783c5f$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 May 2014 23:13:11 -0400, Bill Cunningham wrote: > Does Python have good mathematical capabilities? I am interested in > learning a second language for mathematical purposes. I am considering > looking at python, perl, fortran, Adas out. It looked too complicated to > learn. Perl looked easy and I haven't really looked into python. Yes, Python is excellent for mathematics. Python is rapidly taking over as the language of choice for scientific computing: http://www.talyarkoni.org/blog/2013/11/18/the-homogenization-of-scientific-computing-or-why-python-is-steadily-eating-other-languages-lunch/ You say you want to learn a *second* language, but you don't say what your first language is. Nor do you say what sort of mathematics you wish to do, or at what level. Depending on what you want to do, you might be best off with Mathematica, if you can afford it. Otherwise, there's an Open Source and free alternative, Sage, which uses Python. You may find that the IPython interactive interface to Python is useful. It presents an interface which should be familiar to anyone with experience with Mathematica. For symbolic maths, I like Sympy, where you can do things like this: py> from sympy import * py> x, y = symbols('x y') py> diff(cos(3*x+1), x) -3*sin(3*x + 1) py> integrate(-3*sin(3*x+1), x) cos(3*x + 1) There is also Numpy and Scipy, for heavy-duty numerical mathematics. I recommend that you start with Python 3.4, as it is the latest version of Python, and also because I'm the author of the statistics standard library. It's not a full-blown professional statistics language like R, Matlab or SAS, but if you need basic scientific calculator level statistics it is useful. Feedback on the library is always welcome. As far as other languages go, I think that Fortran is still an excellent language if you need to write high-powered, low-level numeric functions, but if you just want to *use* pre-existing libraries, you are better off with a high-level language like Python which offers interfaces to Fortran libraries. Numpy and Scipy are very good for that. As far as Perl goes, I find that it suffers from the same weakness as R: http://www.talyarkoni.org/blog/2012/06/08/r-the-master-troll-of-statistical-languages/ that is, the learning curve is far to steep for my liking. I find Perl too inconsistent, with far too many special cases and tricks, and not enough of a consistent design. It's not as bad as PHP, but it gives me the impression of a language where the only design principle is "Oh, that looks cool. Hand me the welding iron, and I'll weld it on somewhere. Anywhere will do." -- Steven D'Aprano http://import-that.dreamwidth.org/ From nospam at nspam.invalid Sun May 18 01:04:44 2014 From: nospam at nspam.invalid (Bill Cunningham) Date: Sun, 18 May 2014 01:04:44 -0400 Subject: Python and Math References: <09bbda59-9c37-44b0-acfc-0571d4fe8fcb@googlegroups.com> Message-ID: "Rustom Mody" wrote in message news:09bbda59-9c37-44b0-acfc-0571d4fe8fcb at googlegroups.com... > What does the word 'mathematical' connote for you? > On the whole the term is so wide that its hard to answer without some > more context. > > For example there's numpy,scipy for numerical and scientific* computing, > there's sage, ipython etc. > > > Today many people who want a general purpose programming language with > a mathematical flair, choose Haskell > > For statistics R is quite unbeatable (I am told), which is not python > or any of the others you mention. > > Then there are specialized theorem proving systems. > > Another question you should answer is "Whats the first programming > language you know?" Well linear algebra and gaussian elemination. Expanding and factoring equations of all degrees and identities. Not so much statistics. Some geometry. Euclidean and spatial. Bill From nospam at nspam.invalid Sun May 18 01:33:06 2014 From: nospam at nspam.invalid (Bill Cunningham) Date: Sun, 18 May 2014 01:33:06 -0400 Subject: Python and Math References: <53783c5f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:53783c5f$0$29977$c3e8da3 > You say you want to learn a *second* language, but you don't say what > your first language is. Nor do you say what sort of mathematics you wish > to do, or at what level. Depending on what you want to do, you might be > best off with Mathematica, if you can afford it. Otherwise, there's an > Open Source and free alternative, Sage, which uses Python. I have spent a lot of time with C. But it's hard for me to learn and there are various factors there. That sage looked good. But as a language for *nixs and their respective APIs sockets, sys calls and such there's C. Fortran might still be a choice. Perl looks really easy. But I haven't gotten into any of these because I'm still halding out for one that appeals to me. Bill From samjnaa at gmail.com Sun May 18 02:26:22 2014 From: samjnaa at gmail.com (Shriramana Sharma) Date: Sat, 17 May 2014 23:26:22 -0700 (PDT) Subject: Why should __prepare__ be explicitly decorated as a @classmethod? Message-ID: <2a4ea789-1661-4515-89c2-4259efd186a6@googlegroups.com> Hello. I did search for this but couldn't find the info anywhere else, so I'm asking here. Please point out if I've missed some other source of the same info: https://docs.python.org/3/reference/datamodel.html#basic-customization documents that __new__ is special-cased so that while it is actually a static method, it need not be decorated as such. I have a similar question. IIUC __prepare__ is always a class method to be used in metaclasses, so why isn't it also special-cased so that it need not be decorated as a such? Thanks. From rosuav at gmail.com Sun May 18 03:18:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 May 2014 17:18:22 +1000 Subject: Why should __prepare__ be explicitly decorated as a @classmethod? In-Reply-To: <2a4ea789-1661-4515-89c2-4259efd186a6@googlegroups.com> References: <2a4ea789-1661-4515-89c2-4259efd186a6@googlegroups.com> Message-ID: On Sun, May 18, 2014 at 4:26 PM, Shriramana Sharma wrote: > https://docs.python.org/3/reference/datamodel.html#basic-customization documents that __new__ is special-cased so that while it is actually a static method, it need not be decorated as such. I have a similar question. IIUC __prepare__ is always a class method to be used in metaclasses, so why isn't it also special-cased so that it need not be decorated as a such? Special cases aren't special enough to break the rules. The less special cases a language has, the more likely it is to fit inside your brain, and that's a good thing. ChrisA From ben at benfinney.id.au Sun May 18 03:39:58 2014 From: ben at benfinney.id.au (Ben Finney) Date: Sun, 18 May 2014 17:39:58 +1000 Subject: using a new computer and bringing needed libraries to it References: Message-ID: <85mwef5ycx.fsf@benfinney.id.au> Rustom Mody writes: > On Sunday, May 18, 2014 5:47:05 AM UTC+5:30, Ned Batchelder wrote: > > Make a list of the [Python-specific] packages you need. Put it in a > > file called requirements.txt. [?] > > What about things installed at a lower level than pip, eg apt-get? That's an important issue. Requirements of a project, such as packages that need to be installed from the operating system (e.g. ?you need Python 3.2 or later for this project?), are ideal for documenting in plain human-targeted text in a document called ?requirements.txt?. Which is why I advocate using a *different* filename, more explicit about its special purpose (e.g. ?pip_requirements?), for the Pip-specific (and thereby Python-specific) machine-readable configuration file. -- \ ?But Marge, what if we chose the wrong religion? Each week we | `\ just make God madder and madder.? ?Homer, _The Simpsons_ | _o__) | Ben Finney From roy at panix.com Sun May 18 09:25:20 2014 From: roy at panix.com (Roy Smith) Date: Sun, 18 May 2014 09:25:20 -0400 Subject: Python and Math References: <53783c5f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <53783c5f$0$29977$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > You may find that the IPython interactive interface to Python is useful. > It presents an interface which should be familiar to anyone with > experience with Mathematica. I second the IPython suggestion. I don't use it that often, but when I'm doing interactive number crunching, it's my tool of choice. The ability to interactively go back and edit some block of code, then re-execute it, is really handy when exploring a dataset. And the tight integration of graphing/plotting libraries is awesome. I tend to use it in the mode where I'm running the compute kernel on a remote machine (typically a big machine in a data center somewhere) and the display portion in a browser on my desktop. From feliphil at gmx.net Sun May 18 09:59:29 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Sun, 18 May 2014 15:59:29 +0200 Subject: Python and Math References: Message-ID: <20140518155929.2e0d5e491d39c597472f8071@gmx.net> > Does Python have good mathematical capabilities? SAGE: http://www.sagemath.org/ Sincerely, Wolfgang From breamoreboy at yahoo.co.uk Sun May 18 10:05:02 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 18 May 2014 15:05:02 +0100 Subject: Python and Math In-Reply-To: References: <53783c5f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18/05/2014 14:25, Roy Smith wrote: > In article <53783c5f$0$29977$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> You may find that the IPython interactive interface to Python is useful. >> It presents an interface which should be familiar to anyone with >> experience with Mathematica. > > I second the IPython suggestion. I don't use it that often, but when > I'm doing interactive number crunching, it's my tool of choice. The > ability to interactively go back and edit some block of code, then > re-execute it, is really handy when exploring a dataset. And the tight > integration of graphing/plotting libraries is awesome. > Big +1 from me. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From invalid at invalid.invalid Sun May 18 11:40:46 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 18 May 2014 15:40:46 +0000 (UTC) Subject: Python and Math References: Message-ID: On 2014-05-18, Bill Cunningham wrote: > Does Python have good mathematical capabilities? No. It has very good numerical computation capabilities, but it does not really do "math" (at least not what a mathemetician would consider "math"). > I am interested in learning a second language for mathematical > purposes. If you want to do calculations on numbers (integral, real, complex, vectors, matrixes), analyze and visualize data (stuff that was traditionally done in Fortran), then Python is brilliant. If you want to do "math" (as in the study of number theory, topologies, proofs, and so on) then no. Python is not a good choice. -- Grant From nospam at nspam.invalid Sun May 18 14:09:43 2014 From: nospam at nspam.invalid (Bill Cunningham) Date: Sun, 18 May 2014 14:09:43 -0400 Subject: Python and Math References: Message-ID: "Grant Edwards" wrote in message news:llak9u$8rs$1 at reader1.panix.com... > On 2014-05-18, Bill Cunningham wrote: > >> Does Python have good mathematical capabilities? > > No. > > It has very good numerical computation capabilities, but it does not > really do "math" (at least not what a mathemetician would consider > "math"). > >> I am interested in learning a second language for mathematical >> purposes. > > If you want to do calculations on numbers (integral, real, complex, > vectors, matrixes), analyze and visualize data (stuff that was > traditionally done in Fortran), then Python is brilliant. > > If you want to do "math" (as in the study of number theory, > topologies, proofs, and so on) then no. Python is not a good choice. linear algebra, expanding and factoring equations of all degrees. Geometry. Bill From robert.kern at gmail.com Sun May 18 14:42:02 2014 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 18 May 2014 19:42:02 +0100 Subject: Python and Math In-Reply-To: References: Message-ID: On 2014-05-18 16:40, Grant Edwards wrote: > On 2014-05-18, Bill Cunningham wrote: > >> Does Python have good mathematical capabilities? > > No. > > It has very good numerical computation capabilities, but it does not > really do "math" (at least not what a mathemetician would consider > "math"). Many mathematicians would disagree. http://sagemath.org/ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From varun7rs at gmail.com Sun May 18 15:02:27 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Sun, 18 May 2014 12:02:27 -0700 (PDT) Subject: Can't figure out 'instance has no attribute' error In-Reply-To: References: Message-ID: On Sunday, 18 May 2014 01:56:42 UTC+2, varu... at gmail.com wrote: > Hello Friends, > > > > I am working on this code but I kind of get the same error over and over again. Could any of you help me fix this part of the error? > > > > File RW1: > > class PHY_NETWORK: > > def __init__(self, nodes, edges): > > self.nodes = nodes > > self.edges = edges > > > > def addNode(self, node): > > self.nodes.append( node ) > > > > def addEdge(self, edge): > > self.edges.append( edge ) > > > > File RW3: > > def createnetwork(graph): > > > > > > doc = parse( args.paramFile ) > > noderef = [] > > num = 0 > > nodelist = doc.getElementsByTagName("node") > > for node in nodelist: > > noderef.append(node.getAttribute("id")) > > proc = random.randint(3500, 5000) > > stor = random.randint(7200, 8200) > > switch = random.randint(7000, 10000) > > num = num + 1 > > totaldemands = random.randint(1, 5) > > graph.addNode(PHY_NODES( node.getAttribute("id"), int(num), float(xCoordinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch), int(totaldemands))) > > > > > > linkid = 0 > > linklist = doc.getElementsByTagName("link") > > for link in linklist : > > linkid = linkid + 1 > > Source = link.getElementsByTagName("source") [0] > > Destination = link.getElementsByTagName("target") [0] > > Capacity = link.getElementsByTagName("capacity") [0] > > SourceID = noderef.index(Source.firstChild.data) + 1 > > DestinationID = noderef.index(Destination.firstChild.data) + 1 > > graph.addEdge( PHY_LINKS( linkid, Source.firstChild.data, Destination.firstChild.data, DestinationID, SourceID, float(Capacity.firstChild.data) )) > > > > > > global args > > args = parser.parse_args() > > > > samplenetwork = PHY_NETWORK([], []) > > for i in range(1, 100): > > createnetwork(samplenetwork) > > exportXmlFile(samplenetwork, args.output, 'a' ) > > > > > > if __name__ == "__main__": > > main(sys.argv[1:]) > > > > > > srva at hades:~$ python RW3.py --output topology.xml --xml germany50.xml > > Traceback (most recent call last): > > File "RW3.py", line 157, in > > main(sys.argv[1:]) > > File "RW3.py", line 152, in main > > createnetwork(samplenetwork) > > File "RW3.py", line 31, in createnetwork > > graph.addNode(PHY_NODES( node.getAttribute("id"), int(num), float(xCoordinates.firstChild.data), float(yCoordinates.firstChild.data), float(proc), float(stor), float(switch), int(totaldemands))) > > AttributeError: PHY_NETWORK instance has no attribute 'addNode' > > > > > > The error that it give back is as above. I have the classes defined in RW1 file and I am importing the classes onto RW3 file and yet, It doesn't seem to work. I really am in need of your valuable suggestions. Thank You Thank you very much Ned, Rodri and Gary. I changed the settings of gedit text editor as mentioned in the Zed Shaw tutorial. I think this is causing me the problem. I'll follow your advice. From rosuav at gmail.com Sun May 18 15:10:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 May 2014 05:10:13 +1000 Subject: Can't figure out 'instance has no attribute' error In-Reply-To: References: Message-ID: On Mon, May 19, 2014 at 5:02 AM, wrote: > Thank you very much Ned, Rodri and Gary. I changed the settings of gedit text editor as mentioned in the Zed Shaw tutorial. I think this is causing me the problem. I'll follow your advice. > I find that there are better editors than gedit. My personal preference is SciTE; one of its syntax highlighting features is a nice big warning if the indentation doesn't make sense from one line to the next. So if you switch from spaces to tabs, or mismatch indents, or anything, it gives you this blue marker right through the faulty indented section. Pick an editor with that kind of feature, and you'll find your job way easier. ChrisA From roland at rptd.ch Sun May 18 15:41:03 2014 From: roland at rptd.ch (=?UTF-8?B?Um9sYW5kIFBsw7xzcw==?=) Date: Sun, 18 May 2014 21:41:03 +0200 Subject: Loading modules from files through C++ In-Reply-To: References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> <53778005.8030105@rptd.ch> <53778E22.3040701@rptd.ch> Message-ID: <53790CCF.1070905@rptd.ch> On 05/17/2014 07:05 PM, Stefan Behnel wrote: > Roland Pl?ss, 17.05.2014 18:28: >> On 05/17/2014 05:49 PM, Stefan Behnel wrote: >>> Roland Pl?ss, 17.05.2014 17:28: >>>> On 05/17/2014 04:01 PM, Stefan Behnel wrote: >>>>> Roland Pl?ss, 17.05.2014 15:49: >>>>>> On 05/17/2014 03:26 PM, Stefan Behnel wrote: >>>>>>> Roland Pl?ss, 17.05.2014 15:00: >>>>>>>> On 05/17/2014 01:58 PM, Stefan Behnel wrote: >>>>>>>>> Roland Pl?ss, 17.05.2014 02:27: >>>>>>>>>> I'm using Python in an embedded situation. In particular I have to load >>>>>>>>>> python scripts through a memory interface so regular python module >>>>>>>>>> loading can not be used. I got working so far a module loader object >>>>>>>>>> I've added using C++ to sys.meta_path . Now I'm totally stuck at the >>>>>>>>>> finally loading step. >>>>>>>>>> >>>>>>>>>> I've got this a C++ loader method "load_module(fullname)" which does >>>>>>>>>> load the requested module script files into a null-terminated string. I >>>>>>>>>> know that "load_module" has to return the module PyObject*. But I can't >>>>>>>>>> get the python source in the c-string into a module PyObject*. >>>>>>>>>> [...] >>>>>>>>>> Can anybody help how in gods name one is supposed to create a module >>>>>>>>>> from an in-memory c-string when called from within load_module (or >>>>>>>>>> anywhere)? >>>>>>>>> Looks like you want to implement a SourceLoader: >>>>>>>>> >>>>>>>>> https://docs.python.org/3.4/library/importlib.html#importlib.abc.SourceLoader >>>>>>>>> >>>>>>>>> I recommend implementing this in Python code instead of C code, though. >>>>>>>>> Much easier. Cython can help with the integration between both. >>>>>>>> That doesn't work in 2.x, doesn't it? >>>>>>> Is there a reason you have to use Py2? >>>>>>> >>>>>>> Anyway, PEP 302 predates Py3 by a couple of years: >>>>>>> >>>>>>> http://legacy.python.org/dev/peps/pep-0302/ >>>>>> I'm willing to go to Py3 but only if the solution to the problem is >>>>>> simpler than getting it fixed in Py2. So some questions first: >>>>>> >>>>>> - does this importlib stuff you showed there apply to C++ land (I need >>>>>> to fully drive it from C++ not Python code)? >>>>> As I said, implementing this in Python code is much simpler than doing it >>>>> in C/C++ code. Basically, stop where you got the C string and do the rest >>>>> in Python. All your C code has to do is to take a module lookup request >>>>> from your custom Python module Finder and return a byte string with the >>>>> code. Then let your Python code wrap that in a Loader and return it to the >>>>> import machinery. >>>> I don't get how this is supposed to work. I'm running it as fully >>>> embedded Python. There is no main script. The builtin modules are added >>>> as C++ bound classes and a user made main script is loaded but not run >>>> directly (I'm hooking into a create object). For this purpose I load the >>>> script module using C++ code using PyImport_ImportModule(moduleName). At >>>> this time the module loading code has to kick in already (I've added >>>> this one by C++ too before). The problem is now that in this call I end >>>> up in my C++ loader version where there is no Python script involved. I >>>> came to the conclusion that I can solve this only by having the C++ end >>>> properly load the module. I could add Python code with >>>> PyRun_SimpleString but then I'm down to the same problem as before: how >>>> to evaluate code so it is attached to a module or type-class? As I >>>> understand it the problem is the same as before just pushed around a bit. >>> No, just run some Python code (using PyRun_SimpleString() if you have to) >>> and let it do whatever you like. Such as, defining a Finder class and >>> injecting it into the import hook. Just provide it with the entry point of >>> your C++ loader as a (CFunction) object when you execute it, and then let >>> it call that function at need whenever the Finder gets executed. >>> >>> Alternatively, compile your Python integration code with Cython and link it >>> into your main program as yet another binary extension module. >> I'm not using Cython so that's out of question. Concerning the injection >> how would this work? From the PEP I assume it would have to look like this: >> >> # CODE # >> import sys >> class VFSModuleLoader: >> def find_module(fullname, path=None): >> return self if VFS.exists( vfsPathFromFullname(fullname) ) else None >> def load_module(fullname): >> sourceCode = VFS.read( vfsPathFromFullname(fullname)) >> ??? >> # CODE # >> >> How does ??? work? If I use "eval" I end up with the code inside >> VFSModuleLoader.load_modules as context but it should go into the global >> context as an own module. > Yeah, well, the import machinery is rather badly exposed in Py2. This got > much cleaner in Py3, especially 3.3/3.4. > > Here's a hacky way to do it in Py2: > > import imp > module = imp.new_module(module_name) > module.__importer__ = self > exec source_code in module.__dict__ > return module > > Found here: > > http://hg.python.org/cpython/file/568041fd8090/Lib/imputil.py#l284 > > You may have to set a couple of more special attributes on the module > (__name__? __path__? __package__? others?), but the above should at least work. > > Stefan > > This exec source_code in module.__dict__ , should this not also be doable with PyEval_EvalCode? I've found a snippet like this: # CODE #| PyCodeObject*code =(PyCodeObject*)Py_CompileString(s,"test",Py_file_input); PyObject*main_module =PyImport_AddModule("__main__"); PyObject*global_dict =PyModule_GetDict(main_module); PyObject*local_dict =PyDict_New(); PyObject*obj =PyEval_EvalCode(code,global_dict,local_dict);| # CODE # If I would use a newly created module instead of PyImport_AddModule with the appropriate name would this not evaluate the code (in my case a string not a code object) in the right code space? Or did I misunderstand the snippet there? -- Yours sincerely Pl?ss Roland Leader and Head Programmer - Game: Epsylon ( http://www.indiedb.com/games/epsylon ) - Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine , http://dragengine.rptd.ch/wiki ) - Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php ) - As well as various Blender export scripts und game tools -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 263 bytes Desc: OpenPGP digital signature URL: From benjamin at python.org Sun May 18 20:49:18 2014 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 18 May 2014 17:49:18 -0700 Subject: [RELEASED] Python 2.7.7 release candidate 1 Message-ID: <1400460558.31367.118834865.1A1F5777@webmail.messagingengine.com> Greetings Python users, Python 2.7.7 release candidate 1 is now available for download. Python 2.7.7 is a regularly scheduled bugfix release for the Python 2.7 series. The 2.7.7 release contains fixes for two severe, if arcane, potential security vulnerabilities. The first was the possibility of reading arbitrary process memory using JSONDecoder.raw_decode. [1] (No other json APIs are affected.) The second security issue is an integer overflow in the strop module. [2] (If you don't know what the strop module is, go ahead and forget it now.) This release also includes months of accumulated normal bugfixes. All the changes in Python 2.7.7 are described in detail in the Misc/NEWS file of the source tarball. You can view it online at http://hg.python.org/cpython/raw-file/e32e3a9f3902/Misc/NEWS Downloads are at https://python.org/download/releases/2.7.7/ This is a testing release. Assuming no horrible bugs are found, 2.7.7 final will be released in two weeks time. Please consider testing your applications and libraries with the release candidate and reporting bugs to http://bugs.python.org/ Enjoy, Benjamin Peterson 2.7 Release Manager [1] http://bugs.python.org/issue21529 [2] http://bugs.python.org/issue21530 From rosuav at gmail.com Sun May 18 21:40:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 May 2014 11:40:45 +1000 Subject: Loading modules from files through C++ In-Reply-To: <53790CCF.1070905@rptd.ch> References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> <53778005.8030105@rptd.ch> <53778E22.3040701@rptd.ch> <53790CCF.1070905@rptd.ch> Message-ID: On Mon, May 19, 2014 at 5:41 AM, Roland Pl?ss wrote: > This exec source_code in module.__dict__ , should this not also be doable > with PyEval_EvalCode? General principle: The more code you write in Python and the less in C/C++, the happier and more productive you will be. Drop into Python as soon as you can, and do all the work from there. You won't have to worry about RAM (de)allocation, Unicode (especially if you use Python 3 rather than 2), integer overflow, etc, etc, etc. Only write lower-level code for the bits that actually demand it; and as Stefan has pointed out, Cython is a great help there. (Which reminds me. I still need some "excuse project" to justify my learning Cython. It's good-looking tech but everything I can imagine writing seems to already exist.) ChrisA From vincent at vincentdavis.net Sun May 18 21:53:02 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Sun, 18 May 2014 19:53:02 -0600 Subject: bz2.decompress as file handle Message-ID: I have a file compressed with bz2 and a function that expects a file handle. When I decompress the bz2 file I get a string (binary) not a file handle. Here is what I have that does not work. There is no error (thats a seperate issue) CelFile.read just fails to read the data(string). from Bio.Affy import CelFile from bz2 import decompress, with open('Tests/Affy/affy_v3_ex.CEL.bz2', 'rb') as handle: cel_data = decompress(handle.read()) c = CelFile.read(cel_data) ?? ?Thanks? Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun May 18 22:32:56 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 18 May 2014 21:32:56 -0500 Subject: bz2.decompress as file handle In-Reply-To: References: Message-ID: <20140518213256.5a0f2d71@bigbox.christie.dr> On 2014-05-18 19:53, Vincent Davis wrote: > I have a file compressed with bz2 and a function that expects a > file handle. When I decompress the bz2 file I get a string (binary) > not a file handle. > from bz2 import decompress, > > with open('Tests/Affy/affy_v3_ex.CEL.bz2', 'rb') as handle: > cel_data = decompress(handle.read()) When I try (without the Bio.Affy which isn't part of the stdlib), I get correct bytes from this: tim at bigbox:~$ echo hello world > test.txt tim at bigbox:~$ bzip2 -9 test.txt tim at bigbox:~$ python3 Python 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from bz2 import decompress >>> with open('test.txt.bz2', 'rb') as f: ... data = decompress(f.read()) ... >>> data b'hello world\n' > c = CelFile.read(cel_data) So either you have bad data in the file to begin with, or your CelFile.read() function has a bug in it. -tkc From vincent at vincentdavis.net Sun May 18 22:38:02 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Sun, 18 May 2014 20:38:02 -0600 Subject: bz2.decompress as file handle In-Reply-To: <20140518213256.5a0f2d71@bigbox.christie.dr> References: <20140518213256.5a0f2d71@bigbox.christie.dr> Message-ID: Well after posting, I think I figured it out. The key is to use StringIO to get a file handle on the string. The fact that it is binary just complicates it a little. with open('Tests/Affy/affy_v3_ex.CEL.bz2', 'rb') as handle: cel_data = StringIO(decompress(handle.read()).decode('ascii')) Vincent Davis 720-301-3003 On Sun, May 18, 2014 at 8:32 PM, Tim Chase wrote: > On 2014-05-18 19:53, Vincent Davis wrote: > > I have a file compressed with bz2 and a function that expects a > > file handle. When I decompress the bz2 file I get a string (binary) > > not a file handle. > > > from bz2 import decompress, > > > > with open('Tests/Affy/affy_v3_ex.CEL.bz2', 'rb') as handle: > > cel_data = decompress(handle.read()) > > When I try (without the Bio.Affy which isn't part of the stdlib), I > get correct bytes from this: > > tim at bigbox:~$ echo hello world > test.txt > tim at bigbox:~$ bzip2 -9 test.txt > tim at bigbox:~$ python3 > Python 3.2.3 (default, Feb 20 2013, 14:44:27) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> from bz2 import decompress > >>> with open('test.txt.bz2', 'rb') as f: > ... data = decompress(f.read()) > ... > >>> data > b'hello world\n' > > > > c = CelFile.read(cel_data) > > So either you have bad data in the file to begin with, or your > CelFile.read() function has a bug in it. > > -tkc > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Sun May 18 23:44:12 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 18 May 2014 21:44:12 -0600 Subject: bz2.decompress as file handle In-Reply-To: References: <20140518213256.5a0f2d71@bigbox.christie.dr> Message-ID: On Sun, May 18, 2014 at 8:38 PM, Vincent Davis wrote: > Well after posting, I think I figured it out. > The key is to use StringIO to get a file handle on the string. The fact that > it is binary just complicates it a little. > > with open('Tests/Affy/affy_v3_ex.CEL.bz2', 'rb') as handle: > cel_data = StringIO(decompress(handle.read()).decode('ascii')) You can just use bz2.open: >>> with bz2.open('test.txt.bz2', 'rt', encoding='ascii') as f: ... print(f.read()) ... hello! From vincent at vincentdavis.net Mon May 19 00:02:02 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Sun, 18 May 2014 22:02:02 -0600 Subject: bz2.decompress as file handle In-Reply-To: References: <20140518213256.5a0f2d71@bigbox.christie.dr> Message-ID: On Sun, May 18, 2014 at 9:44 PM, Ian Kelly wrote: > You can just use bz2.open: > > >>> with bz2.open('test.txt.bz2', 'rt', encoding='ascii') as f: > ... print(f.read()) > ?Thanks I like that better then my solution. ? Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From satishmlwizpro at gmail.com Mon May 19 02:53:21 2014 From: satishmlwizpro at gmail.com (satishmlwizpro at gmail.com) Date: Sun, 18 May 2014 23:53:21 -0700 (PDT) Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. Message-ID: Hi, Consider /src/alias/a.c /src/alias/b.c /src/xml/p.xml /src/xml/c.xml /src/h.c as source directory and /dest/alias /dest/xml /dest as destination directory. These are given in a csv file like /src/alias/a.c, /dest/alias /src/alias/b.c, /dest/alias /src/xml/p.xml, /dest/xml /src/xml/c.xml, /dest/xml /src/h.c, /dest Python code should read csv file. Copy files from source to destination(files in /src/alias should be copied to /dest/alias and not to /dest/xml i.e., directory names should be the same). If /dest contains same files as /src, then they code should give us a warning and such files shouldn't be copied. Other files should only be copied. Could you kindly help? From rosuav at gmail.com Mon May 19 03:01:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 May 2014 17:01:05 +1000 Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: References: Message-ID: On Mon, May 19, 2014 at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing code and then post when you have problems, or investigate some shell commands (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole job. Or pay someone to do the job for you. ChrisA From victor.stinner at gmail.com Mon May 19 03:54:28 2014 From: victor.stinner at gmail.com (Victor Stinner) Date: Mon, 19 May 2014 09:54:28 +0200 Subject: [python-committers] [RELEASED] Python 3.4.1 In-Reply-To: <53799E17.7040805@hastings.org> References: <53799E17.7040805@hastings.org> Message-ID: It's not easy to find the changelog. I found this page: https://docs.python.org/3.4/whatsnew/changelog.html Victor 2014-05-19 8:00 GMT+02:00 Larry Hastings : > > > On behalf of the Python development community and the Python 3.4 release > team, I'm pleased to announce the availability of Python 3.4.1. Python > 3.4.1 has over three hundred bugfixes and other improvements over 3.4.0. One > notable change: the version of OpenSSL bundled with the Windows installer no > longer has the "HeartBleed" vulnerability. > > You can download it here: > > https://www.python.org/download/releases/3.4.1 > > > > /arry > > _______________________________________________ > python-committers mailing list > python-committers at python.org > https://mail.python.org/mailman/listinfo/python-committers > From satishmlwizpro at gmail.com Mon May 19 04:08:36 2014 From: satishmlwizpro at gmail.com (Satish ML) Date: Mon, 19 May 2014 01:08:36 -0700 (PDT) Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: References: Message-ID: <24bc5790-ed38-4e3e-9c8a-8282d3b7f453@googlegroups.com> On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > On Mon, May 19, 2014 at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing code and then post when you have problems, or investigate some shell commands (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole job. Or pay someone to do the job for you. ChrisA Consider xls file contains source and destination directory paths. import xlrd, sys, subprocess file_location = "C:\Users\User1\Desktop\input.xls" workbook = xlrd.open_workbook(file_location) sheet = workbook.sheet_by_index(0) sheet.cell_value(0, 0) for row in range(sheet.nrows): values = [] values.append(sheet.cell_value(row, 1)) destination = [] destination.append(sheet.cell_value(row, 2)) for s in values: for d in destination: What next after this? shutil.copy(src, dest) doesn't work because it overwrites dest files. From satishmlwizpro at gmail.com Mon May 19 05:02:36 2014 From: satishmlwizpro at gmail.com (Satish ML) Date: Mon, 19 May 2014 02:02:36 -0700 (PDT) Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: References: Message-ID: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > On Mon, May 19, 2014 at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing code and then post when you have problems, or investigate some shell commands (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole job. Or pay someone to do the job for you. ChrisA Hi ChrisAngelico, Consider that source and destination directories are given in a .xls(excel) file. This is the code import xlrd, sys, subprocess file_location = "C:\Users\salingeg\Desktop\input.xls" workbook = xlrd.open_workbook(file_location) sheet = workbook.sheet_by_index(0) sheet.cell_value(0, 0) for row in range(sheet.nrows): values = [] values.append(sheet.cell_value(row, 1)) destination = [] destination.append(sheet.cell_value(row, 2)) for s in values: for d in destination: If I am using cp or xcopy command, it will copy all files from s to d. shutil.copy(s, d) can't be used here because it overwrites files in d. Kindly help. From fabien.maussion at gmail.com Mon May 19 06:15:22 2014 From: fabien.maussion at gmail.com (Fabien) Date: Mon, 19 May 2014 12:15:22 +0200 Subject: Python and Math References: Message-ID: Hi everyone, I am new on this forum (I come from IDL and am starting to learn python) This thread perfectly illustrates why Python is so scary to newcomers: one question, three answers: yes, no, maybe. Python-fans sure would argue "freedom of choice" is the most important, but "being able to find the right tool for me in less than three days" surely is important too. The paradox of choice ;-) Fabien From mail at timgolden.me.uk Mon May 19 06:30:57 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 19 May 2014 11:30:57 +0100 Subject: Python and Math In-Reply-To: References: Message-ID: <5379DD61.4010104@timgolden.me.uk> On 19/05/2014 11:15, Fabien wrote: > Hi everyone, > > I am new on this forum (I come from IDL and am starting to learn python) > > This thread perfectly illustrates why Python is so scary to newcomers: > one question, three answers: yes, no, maybe. Welcome to the Python world, Fabien. But I'm sure you realise that question as general-purpose as "is Python good for Maths?" is pretty much *bound* to generate different kinds of answers. I'm not sure why it should be seen as scary. If anything, the variety of responses reflects the diversity of Python's userbase. The casual mathematician sees Python as perfectly adequate using built-in tools alone. The more advanced mathematician sees it as helpful with the addition of some specialist libraries. The most advanced user would prefer some specialised language or toolset more entirely devoted to this one area of interest. And you could repeat the same situation with any number of other areas: Image Processing, Websites, Network-based message passing, Data mining, financial market management, web-scraping, etc. For some, Python has more or less useful built-in support. For some, there are well-established or highly-regarded 3rd-party libraries and communities. For some, you might be better advised to look at a different toolset, especially if you want something which comes ready-made. As I say, though, welcome to Python! TJG From miki.tebeka at gmail.com Mon May 19 08:20:43 2014 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 19 May 2014 05:20:43 -0700 (PDT) Subject: [RELEASED] Python 2.7.7 release candidate 1 In-Reply-To: References: Message-ID: > (If you don't know what the strop > module is, go ahead and forget it now.) +1 QOTW :) From breamoreboy at yahoo.co.uk Mon May 19 08:31:41 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 19 May 2014 13:31:41 +0100 Subject: [RELEASED] Python 2.7.7 release candidate 1 In-Reply-To: References: Message-ID: On 19/05/2014 13:20, Miki Tebeka wrote: >> (If you don't know what the strop >> module is, go ahead and forget it now.) > +1 QOTW :) > IIRC the strop module was targetted at users such as myself :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rustompmody at gmail.com Mon May 19 08:46:36 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 19 May 2014 05:46:36 -0700 (PDT) Subject: Python and Math In-Reply-To: References: Message-ID: <79ce1e96-e345-4a87-87cb-9bb3345cccbb@googlegroups.com> On Monday, May 19, 2014 3:45:22 PM UTC+5:30, Fabien wrote: > Hi everyone, > I am new on this forum (I come from IDL and am starting to learn python) > This thread perfectly illustrates why Python is so scary to newcomers: > one question, three answers: yes, no, maybe. > Python-fans sure would argue "freedom of choice" is the most important, > but "being able to find the right tool for me in less than three days" > surely is important too. The paradox of choice ;-) Point taken. So let me try to give pointwise answers to the OP's questions Expanding and factoring equations of all degrees: http://docs.sympy.org/dev/modules/polys/wester.html Numpy for gaussian elimination: https://gist.github.com/tkralphs/7554375 illustrates some of numpy's array-level features. One thing about numpy that bugs me is that the docs never say how much is taken straight from APL. So here is the APL (which I dont claim to understand): http://dfns.dyalog.com/n_gauss_jordan.htm Here is an online APL you can run straight from the browser: http://baruchel.hd.free.fr/apps/apl/ The more general question: On Sunday, May 18, 2014 9:10:46 PM UTC+5:30, Grant Edwards wrote: > On 2014-05-18, Bill Cunningham wrote: > > Does Python have good mathematical capabilities? > No. > It has very good numerical computation capabilities, but it does not > really do "math" (at least not what a mathemetician would consider > "math"). vs Robert's > Many mathematicians would disagree. > > http://sagemath.org/ Traditionally mathematicians do two kinds of things - calculating and proving. Normal mathematicians dont make too much of a distinction between the two. The more extremists in the one camp look down - as usual - on the other thus: The provers call the calculators as "Just applied not pure mathematicians" The calculators say of the provers: "They are not mathematicians but logicians" (or philosophers)" [Chris had a funny quote on this a few weeks ago] After computers, a new area emerged - explorers - which straddles proving and calculating. In short, Grant is speaking from the prover angle whereas Robert is speaking from the calculator angle. There is one more point here: Does language-X (in this case python) have a theoretically sound (ie mathematical) foundation? Mathematicians coming to CS never bother with this whereas computer scientists, especially theoretical CSists, at some point or other invariably come to this. Since its not clear whether this question is being asked, I'm not saying anything more on it. From rosuav at gmail.com Mon May 19 09:09:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 May 2014 23:09:49 +1000 Subject: Python and Math In-Reply-To: <79ce1e96-e345-4a87-87cb-9bb3345cccbb@googlegroups.com> References: <79ce1e96-e345-4a87-87cb-9bb3345cccbb@googlegroups.com> Message-ID: On Mon, May 19, 2014 at 10:46 PM, Rustom Mody wrote: > The provers call the calculators as "Just applied not pure mathematicians" > The calculators say of the provers: "They are not mathematicians but logicians" > (or philosophers)" [Chris had a funny quote on this a few weeks ago] Which Chris? I don't remember either reading or writing such a quote, and would like to. There are a good few Chrises on this list :) ChrisA From rustompmody at gmail.com Mon May 19 09:15:20 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 19 May 2014 06:15:20 -0700 (PDT) Subject: Python and Math In-Reply-To: References: <79ce1e96-e345-4a87-87cb-9bb3345cccbb@googlegroups.com> Message-ID: <316d1f50-0383-4de5-bcf7-91e19bc1f297@googlegroups.com> On Monday, May 19, 2014 6:39:49 PM UTC+5:30, Chris Angelico wrote: > On Mon, May 19, 2014 at 10:46 PM, Rustom Mody wrote: > > The provers call the calculators as "Just applied not pure mathematicians" > > The calculators say of the provers: "They are not mathematicians but logicians" > > (or philosophers)" [Chris had a funny quote on this a few weeks ago] > Which Chris? I don't remember either reading or writing such a quote, > and would like to. There are a good few Chrises on this list :) You!! Something about mathematicians philosophers and waste-paper baskets From rosuav at gmail.com Mon May 19 09:24:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 May 2014 23:24:18 +1000 Subject: Python and Math In-Reply-To: <316d1f50-0383-4de5-bcf7-91e19bc1f297@googlegroups.com> References: <79ce1e96-e345-4a87-87cb-9bb3345cccbb@googlegroups.com> <316d1f50-0383-4de5-bcf7-91e19bc1f297@googlegroups.com> Message-ID: On Mon, May 19, 2014 at 11:15 PM, Rustom Mody wrote: > On Monday, May 19, 2014 6:39:49 PM UTC+5:30, Chris Angelico wrote: >> On Mon, May 19, 2014 at 10:46 PM, Rustom Mody wrote: >> > The provers call the calculators as "Just applied not pure mathematicians" >> > The calculators say of the provers: "They are not mathematicians but logicians" >> > (or philosophers)" [Chris had a funny quote on this a few weeks ago] > >> Which Chris? I don't remember either reading or writing such a quote, >> and would like to. There are a good few Chrises on this list :) > > You!! > Something about mathematicians philosophers and waste-paper baskets Oh! Yes, I remember now. Old joke I found someplace. Physicists need heaps of sensitive (and expensive) equipment... mathematicians need only pencils, paper, and waste-paper baskets. And philosophers don't even need waste-paper baskets. ChrisA From varun7rs at gmail.com Mon May 19 09:42:02 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Mon, 19 May 2014 06:42:02 -0700 (PDT) Subject: Problem in writing demands to the xml file Message-ID: <94945828-0caf-4534-bdaa-5371bdda6dbe@googlegroups.com> Hello Friends, I am still working on the script to write data onto the xml file and now I've got a problem. This is how my xml file looks now but I intend to add attributes to demands. I am not able to do it properly. substrate> My class for nodes. I have a class for DEMAND but I don't want to populate the post with all of it. class PHY_NODES: def __init__(self, nodeID, nodenum, x, y, capacity_proc, capacity_stor, capacity_switch, totaldemand, demands): self.id = nodeID self.nodenum = nodenum self.x = x self.y = y self.capacity_proc = capacity_proc self.capacity_stor = capacity_stor self.capacity_switch = capacity_switch self.totaldemand = totaldemand self.demands = demands def addDemand (self, demand): self.demands.append( demand ) The problem I have is in writing the demands. I generate the necessary stuff for it but when I try and append it, it doesn't seem to work. I'd be glad to share my files if you need them. Could you please help me fix this? Thank You From vinay_sajip at yahoo.co.uk Mon May 19 10:24:35 2014 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 19 May 2014 15:24:35 +0100 (BST) Subject: [ANN]: distlib 0.1.9 released on PyPI Message-ID: <1400509475.10474.YahooMailNeo@web172405.mail.ir2.yahoo.com> I've just released version 0.1.9 of distlib on PyPI [1]. For newcomers, distlib is a library of packaging functionality which is intended to be usable as the basis for third-party packaging tools. The main changes in this release are as follows: ??? Fixed issue #47: Updated binary launchers to fix double-quoting bug ??? where script executable paths have spaces. ??? Added ``keystore`` keyword argument to signing and verification APIs. A more detailed change log is available at [2]. Please try it out, and if you find any problems or have any suggestions for improvements, please give some feedback using the issue tracker! [3] Regards, Vinay Sajip [1] https://pypi.python.org/pypi/distlib/0.1.9 [2] http://pythonhosted.org/distlib/overview.html#change-log-for-distlib [3] https://bitbucket.org/pypa/distlib/issues/new From wxjmfauth at gmail.com Mon May 19 10:56:11 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 19 May 2014 07:56:11 -0700 (PDT) Subject: Python and Math In-Reply-To: References: Message-ID: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> Le lundi 19 mai 2014 12:15:22 UTC+2, Fabien a ?crit?: > Hi everyone, > > > > I am new on this forum (I come from IDL and am starting to learn python) > > > > This thread perfectly illustrates why Python is so scary to newcomers: > > one question, three answers: yes, no, maybe. > > > > Python-fans sure would argue "freedom of choice" is the most important, > > but "being able to find the right tool for me in less than three days" > > surely is important too. The paradox of choice ;-) > > > > Fabien ---------- Yesterday, I spent one hour attemepting to install IPython for Py3.3 (win 7), I failed. I do not even succeed to understand how. Pip, setuptools, whl or manualy with from the zip... completely lost. There is always something not working. This morning I installed Py 3.4.1. I do not even succeed to put it to work. I know Python since v 1.5.6 ! I'm able to write "Numerical Recipes" in Python, (I did it in Py2 and Py3), I'm unable to install a piece of software (like Python) to work with. I'm just wondering if finally the better solution is not to stick with an "MS C#". jmf From xdegaye at gmail.com Mon May 19 09:36:16 2014 From: xdegaye at gmail.com (Xavier de Gaye) Date: Mon, 19 May 2014 15:36:16 +0200 Subject: ANN: pdb-clone 1.6 - a fast clone of pdb with the remote debugging and attach features Message-ID: <537A08D0.9080902@gmail.com> pdb-clone 1.6 has been released at Pypi: https://pypi.python.org/pypi/pdb-clone Features: * Improve significantly pdb performance. With breakpoints, pdb-clone runs just above the speed of the interpreter while pdb runs at 10 to 100 times the speed of the interpreter. * Instrument the code with a `set_trace_remote()` hard-coded breakpoint and run the `pdb-attach` script from another terminal to start a remote debugging session. Or, when the code has not been instrumented, run `pdb-attach` with the `--pid` option to start the remote debugging session at any time and attach to the process main thread. * Fix pdb long standing bugs entered in the python issue tracker. * Add a bdb comprehensive test suite (more than 70 tests) and run both the Python pdb and pdb-clone bdb test suites. * Three versions of pdb-clone are supported: * The _py3_ version of pdb-clone runs on python3 from python 3.2 onward. * The _py2.7_ vesion runs on python 2.7. * The _py2.4_ version runs on all python versions from 2.4 to 2.7 included. The pdb command line interface remains unchanged except for the new `detach` pdb command. All the versions of pdb-clone implement the most recent python3 features of pdb. From gheskett at wdtv.com Mon May 19 10:22:54 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Mon, 19 May 2014 10:22:54 -0400 Subject: Python and Math In-Reply-To: References: <316d1f50-0383-4de5-bcf7-91e19bc1f297@googlegroups.com> Message-ID: <201405191022.54219.gheskett@wdtv.com> On Monday 19 May 2014 09:24:18 Chris Angelico did opine And Gene did reply: > On Mon, May 19, 2014 at 11:15 PM, Rustom Mody wrote: > > On Monday, May 19, 2014 6:39:49 PM UTC+5:30, Chris Angelico wrote: > >> On Mon, May 19, 2014 at 10:46 PM, Rustom Mody wrote: > >> > The provers call the calculators as "Just applied not pure > >> > mathematicians" The calculators say of the provers: "They are not > >> > mathematicians but logicians" (or philosophers)" [Chris had a > >> > funny quote on this a few weeks ago] > >> > >> Which Chris? I don't remember either reading or writing such a > >> quote, and would like to. There are a good few Chrises on this list > >> :) > > > > You!! > > Something about mathematicians philosophers and waste-paper baskets > > Oh! Yes, I remember now. Old joke I found someplace. Physicists need > heaps of sensitive (and expensive) equipment... mathematicians need > only pencils, paper, and waste-paper baskets. And philosophers don't > even need waste-paper baskets. > > ChrisA I gotta grin and like it, that does boil it down to the pure essence. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From larry at hastings.org Mon May 19 02:00:55 2014 From: larry at hastings.org (Larry Hastings) Date: Sun, 18 May 2014 23:00:55 -0700 Subject: [RELEASED] Python 3.4.1 Message-ID: <53799E17.7040805@hastings.org> On behalf of the Python development community and the Python 3.4 release team, I'm pleased to announce the availability of Python 3.4.1. Python 3.4.1 has over three hundred bugfixes and other improvements over 3.4.0. One notable change: the version of OpenSSL bundled with the Windows installer no longer has the "HeartBleed" vulnerability. You can download it here: https://www.python.org/download/releases/3.4.1 //arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From p.f.moore at gmail.com Mon May 19 11:11:23 2014 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 19 May 2014 16:11:23 +0100 Subject: [Distutils] [ANN]: distlib 0.1.9 released on PyPI In-Reply-To: <1400509475.10474.YahooMailNeo@web172405.mail.ir2.yahoo.com> References: <1400509475.10474.YahooMailNeo@web172405.mail.ir2.yahoo.com> Message-ID: On 19 May 2014 15:24, Vinay Sajip wrote: > Fixed issue #47: Updated binary launchers to fix double-quoting bug > where script executable paths have spaces. Note that this issue affects pip / virtualenv in that creating a virtualenv in a path with spaces can result in pip not working in that virtualenv. We should revendor distlib for the next pip/virtualenv release (if one of the Unix devs could do that, that would be safer, I've managed to break line endings trying to do a revendor on Windows in the past :-() Paul From rustompmody at gmail.com Mon May 19 12:09:24 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 19 May 2014 09:09:24 -0700 (PDT) Subject: Python and Math In-Reply-To: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> Message-ID: <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> On Monday, May 19, 2014 8:26:11 PM UTC+5:30, jmf wrote: > Yesterday, I spent one hour attemepting to install IPython > for Py3.3 (win 7), I failed. I do not even succeed to > understand how. Pip, setuptools, whl or manualy with from the > zip... completely lost. There is always something not working. > This morning I installed Py 3.4.1. I do not even > succeed to put it to work. > I know Python since v 1.5.6 ! > I'm able to write "Numerical Recipes" in Python, > (I did it in Py2 and Py3), I'm unable to install > a piece of software (like Python) to work with. So what're you waiting for? Ask here and someone or other will help you get your system running. From mdickinson at enthought.com Mon May 19 12:10:26 2014 From: mdickinson at enthought.com (Mark Dickinson) Date: Mon, 19 May 2014 16:10:26 +0000 (UTC) Subject: Bug in Decimal?? References: <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com> Message-ID: isp.com> writes: > I've tested on all platforms I know of and confirmed it. The wrong digit > occurs in the middle of the number. Propagation error would have a bad digit > near the end, and garbage after that. Here there's a perfect sequence of > numbers, but with one single digit changed in the middle of the number. No > error propagation in a series expansion can do that. I can see how it might be surprising if you don't think about it too hard, but I'm afraid that you're wrong here: error propagation is *exactly* what's causing the effects you're seeing. Here's another way of looking at it: if you truncate the Taylor series about 0 for (1 + x) / (1 - x) to k (>= 1) terms, you get the polynomial (1 + x - 2x^k) / (1 - x). For example, taking k to be 3, we're getting (1 + x - 2x^3) / (1 - x). Given that the particular value of x you're testing with has the form 10**, rounding your intermediate result to the working precision has exactly the effect of truncating the series at some k. Now you can compute and compare (by hand, via Wolfram alpha, or however you like) the Taylor series expansions for log((1 + x) / (1 - x)) and log((1 + x - 2x^3) / (1 - x)). For the first you'll see: 2x + 2/3 x^3 + 2/5 x^5 - 2/7 x^7 + 2/9 x^9 - ... and for the second you'll get: 2x - 4/3 x^3 + 2 x^4 - 8/5 x^5 + 16/7 x^7 - ... The difference between the two series is: -2x^3 + 2x^4 - 2x^5 + 2x^7 - 4x^8 + ... So again with x a small power of 10, you're going to see a single-digit error from the -2x^3 term, and another single-digit error further along from the 2x^3 term, and so on. Here's a simpler example of the same phenomenon. Note how the error propagation leads to a single incorrect digit in the *middle* of the digit string. Python 3.4.0 (default, Mar 25 2014, 11:07:05) [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from decimal import Decimal >>> x = Decimal('1e-15') >>> y = (1 - 2 * x) / (1 - x) >>> 2 * x + (y - 1) * (1 - x) # Mathematically, expect to get 'x' back. Decimal('1.000000000000001000000000000E-15') >>> x Decimal('1E-15') -- Mark From roland at rptd.ch Mon May 19 12:37:46 2014 From: roland at rptd.ch (=?UTF-8?B?Um9sYW5kIFBsw7xzcw==?=) Date: Mon, 19 May 2014 18:37:46 +0200 Subject: Loading modules from files through C++ In-Reply-To: References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> <53778005.8030105@rptd.ch> <53778E22.3040701@rptd.ch> <53790CCF.1070905@rptd.ch> Message-ID: <537A335A.3000801@rptd.ch> On 05/19/2014 03:40 AM, Chris Angelico wrote: > On Mon, May 19, 2014 at 5:41 AM, Roland Pl?ss wrote: >> This exec source_code in module.__dict__ , should this not also be doable >> with PyEval_EvalCode? > General principle: The more code you write in Python and the less in > C/C++, the happier and more productive you will be. > > Drop into Python as soon as you can, and do all the work from there. > You won't have to worry about RAM (de)allocation, Unicode (especially > if you use Python 3 rather than 2), integer overflow, etc, etc, etc. > Only write lower-level code for the bits that actually demand it; and > as Stefan has pointed out, Cython is a great help there. > > (Which reminds me. I still need some "excuse project" to justify my > learning Cython. It's good-looking tech but everything I can imagine > writing seems to already exist.) > > ChrisA Cython is out of question since link time dependencies has to be kept at an utmost minimum. An concerning doing things from python code it's simply not possible (or I don't know how this should work). Python is fully embedded including any file actions (virtual file system). The launch comes from C++ land. No interpreter is involved. The main work is done outside Python and only dropped in python to do higher logic. This also means the very first python code run requires a C++ script file loading before this first code can ever run. I can't run code that doesn't yet exist in the reach of the python VM. That's the main problem. This is why I need to figure out how to push that first code into Python in a way I can construct an object (from a predefined class). From there on all calls into Python land are solely done trough function calls on this one object obtained in the beginning. I see no other way to handle the problem. -- Yours sincerely Pl?ss Roland Leader and Head Programmer - Game: Epsylon ( http://www.indiedb.com/games/epsylon ) - Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine , http://dragengine.rptd.ch/wiki ) - Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php ) - As well as various Blender export scripts und game tools -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 263 bytes Desc: OpenPGP digital signature URL: From chris_news at arcor.de Mon May 19 14:32:05 2014 From: chris_news at arcor.de (Christian) Date: Mon, 19 May 2014 20:32:05 +0200 Subject: Python CGI Message-ID: Hi, I'd like to use Python for CGI-Scripts. Is there a manual how to setup Python with Fast-CGI? I'd like to make sure that Python scripts aren't executed by www-user, but the user who wrote the script. -- Gru?, Christian From burak.arslan at arskom.com.tr Mon May 19 14:53:24 2014 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Mon, 19 May 2014 21:53:24 +0300 Subject: Python CGI In-Reply-To: References: Message-ID: <537A5324.1000107@arskom.com.tr> On 05/19/14 21:32, Christian wrote: > Hi, > > I'd like to use Python for CGI-Scripts. Is there a manual how to setup > Python with Fast-CGI? Look for Mailman fastcgi guides. Here's one for gentoo, but I imagine it'd be easily applicable to other disros: https://www.rfc1149.net/blog/2010/12/30/configuring-mailman-with-nginx-on-gentoo/ hth, burak From wxjmfauth at gmail.com Mon May 19 15:07:42 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 19 May 2014 12:07:42 -0700 (PDT) Subject: Python and Math In-Reply-To: <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> Message-ID: <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> Le lundi 19 mai 2014 18:09:24 UTC+2, Rustom Mody a ?crit?: > On Monday, May 19, 2014 8:26:11 PM UTC+5:30, jmf wrote: > > > > > Yesterday, I spent one hour attemepting to install IPython > > > for Py3.3 (win 7), I failed. I do not even succeed to > > > understand how. Pip, setuptools, whl or manualy with from the > > > zip... completely lost. There is always something not working. > > > > > This morning I installed Py 3.4.1. I do not even > > > succeed to put it to work. > > > > > I know Python since v 1.5.6 ! > > > > > I'm able to write "Numerical Recipes" in Python, > > > (I did it in Py2 and Py3), I'm unable to install > > > a piece of software (like Python) to work with. > > > > So what're you waiting for? > > Ask here and someone or other will help you get your system running. -------- You know. You are right. I can only agree. Just ask. The problem I see, is why I only "succeded" to just find on Google, so many people who are just asking... From mail at timgolden.me.uk Mon May 19 15:18:54 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 19 May 2014 20:18:54 +0100 Subject: Python and Math In-Reply-To: <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> Message-ID: <537A591E.8020908@timgolden.me.uk> On 19/05/2014 20:07, wxjmfauth at gmail.com wrote: >>> Yesterday, I spent one hour attemepting to install IPython >> >>> for Py3.3 (win 7), I failed. I do not even succeed to >> >>> understand how. Pip, setuptools, whl or manualy with from the >> >>> zip... completely lost. There is always something not working. >> >> >> >>> This morning I installed Py 3.4.1. I do not even >> >>> succeed to put it to work. I realise that this probably isn't very helpful, but I've just successfully installed ipython on Python 3.3 and Python 3.4 (Win7 32-bit) by simply doing: py -3.3 -mpip install ipython py -3.4 -mpip install ipython Since I don't have the various c:\pythonxx\scripts folders on my path, I did then have to launch it explictly: c:\python33\scripts\ipython but it was no harder than that. What problems are you experiencing? TJG From sunitha_byju at hotmail.com Mon May 19 16:46:44 2014 From: sunitha_byju at hotmail.com (Sunitha Byju) Date: Mon, 19 May 2014 16:46:44 -0400 Subject: Need help with executing DB query in two different places in a test Message-ID: I am trying to automate an ecom website. I need to run DB query after placing each order. I don't know how to run different queries after each order. Can someone help me out with having queries after each order submission or test? If you notice, I'm calling self.database_verification() after test 1. So for the second test the query would be different, something like, Select * from PORTFOLIO_ORDER where MEMBER = 'USA' AND SYMBOL = 'TOP' OR SYMBOL = 'Sweater. Basically for the sequence of orders, i would have different queries. So what is the best way to write the code? class OrderInputScreen(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() driver = self.driver driver.get("http://testserver:8080/OrderInputScreen/login#/") driver.maximize_window() def database_verification(self): con = cx_Oracle.connect('user/user at testDB123') cur = con.cursor() cur.execute("Select * from US_ORDER where SYMBOL = 'TOP' and SIZE = 'M'") for result in cur: print result[2:8] cur.close() #USA single Order and verification def __test_single_order(self): driver = self.driver elem = driver.find_element_by_name("username") elem.send_keys("TEST") elemPassword = driver.find_element_by_name("password") elemPassword.send_keys("TEST") elem.submit() member = driver.find_element_by_xpath("//form/div/dl/dd[1]/input") member.click() member.send_keys("USA") PayType = driver.find_element_by_xpath ("//form/div/dl/dd[2]/input") PayType.click() PayType.send_keys("USD") clickPayType = driver.find_element_by_xpath ("//form/div/dl/dd/ul/li/a") clickPayType.click() Symbol = driver.find_element_by_xpath ("//form/div/dl/dd[3]/input") Symbol.click() Symbol.send_keys("TOP") Quantity = driver.find_element_by_name ("quantity") Quantity.click() Quantity.send_keys("10") Price = driver.find_element_by_name ("price") Price.click() Price.send_keys("56.99") Size = driver.find_element_by_xpath ("//form/div/dl/dd[6]/select/option[text()='M']") Size.click() SubmitButton = driver.find_element_by_xpath ("//form/div/dl/dd[11]/div[2]") SubmitButton.click() ActualOrderMsg = driver.find_element_by_xpath ("//span/p").text print ActualOrderMsg textPresent = driver.find_element_by_xpath ("//span/p[contains(text(), 'Successfuly added to processing!')]") self.database_verification() #USA -multiple orders and verification def test_Multiple_order(self): #Order0 driver = self.driver elem = driver.find_element_by_name("username") elem.send_keys("TEST") elemPassword = driver.find_element_by_name("password") elemPassword.send_keys("TEST") elem.submit() member = driver.find_element_by_xpath("//form/div/dl/dd[1]/input") member.click() member.send_keys("USA") PayType = driver.find_element_by_xpath ("//form/div/dl/dd[2]/input") PayType.click() PayType.send_keys("USD") clickPayType = driver.find_element_by_xpath ("//form/div/dl/dd/ul/li/a") clickPayType.click() Symbol = driver.find_element_by_xpath ("//form/div/dl/dd[3]/input") Symbol.click() Symbol.send_keys("TOP") Quantity = driver.find_element_by_name ("quantity") Quantity.click() Quantity.send_keys("1") Price = driver.find_element_by_name ("price") Price.click() Price.send_keys("16.99") Size = driver.find_element_by_xpath ("//form/div/dl/dd[6]/select/option[text()='S']") Size.click() SubmitButton = driver.find_element_by_xpath ("//form/div/dl/dd[11]/div[2]") SubmitButton.click() ActualOrderMsg = driver.find_element_by_xpath ("//span/p").text print ActualOrderMsg textPresent = driver.find_element_by_xpath ("//span/p[contains(text(), 'Successfuly added to processing!')]" #Order1 AddOrder1 = driver.find_element_by_xpath("//div/div[2]/form/div[2]/button[1]") AddOrder1.click() member = driver.find_element_by_xpath("//form/div/dl/dd[1]/input") member.click() member.send_keys("USA") PayType = driver.find_element_by_xpath ("//form/div/dl/dd[2]/input") PayType.click() PayType.send_keys("USD") clickPayType = driver.find_element_by_xpath ("//form/div/dl/dd/ul/li/a") clickPayType.click() Symbol = driver.find_element_by_xpath ("//form/div/dl/dd[3]/input") Symbol.click() Symbol.send_keys("Sweater") Quantity = driver.find_element_by_name ("quantity") Quantity.click() Quantity.send_keys("2") Price = driver.find_element_by_name ("price") Price.click() Price.send_keys("26.99") Size = driver.find_element_by_xpath ("//form/div/dl/dd[6]/select/option[text()='M']") Size.click() SubmitButton = driver.find_element_by_xpath ("//form/div/dl/dd[11]/div[2]") SubmitButton.click() ActualOrderMsg = driver.find_element_by_xpath ("//span/p").text print ActualOrderMsg textPresent = driver.find_element_by_xpath ("//span/p[contains(text(), 'Successfuly added to processing!')]" #Order2 AddOrder2 = driver.find_element_by_xpath("//div/div[2]/form/div[3]/button[1]") AddOrder2.click() member = driver.find_element_by_xpath("//form/div/dl/dd[1]/input") member.click() member.send_keys("USA") PayType = driver.find_element_by_xpath ("//form/div/dl/dd[2]/input") PayType.click() PayType.send_keys("USD") clickPayType = driver.find_element_by_xpath ("//form/div/dl/dd/ul/li/a") clickPayType.click() Symbol = driver.find_element_by_xpath ("//form/div/dl/dd[3]/input") Symbol.click() Symbol.send_keys("Sweater") Quantity = driver.find_element_by_name ("quantity") Quantity.click() Quantity.send_keys("1") Price = driver.find_element_by_name ("price") Price.click() Price.send_keys("26.99") Size = driver.find_element_by_xpath ("//form/div/dl/dd[6]/select/option[text()='S']") Size.click() SubmitButton = driver.find_element_by_xpath ("//form/div/dl/dd[11]/div[2]") SubmitButton.click() ActualOrderMsg = driver.find_element_by_xpath ("//span/p").text print ActualOrderMsg textPresent = driver.find_element_by_xpath ("//span/p[contains(text(), 'Successfuly added to processing!')]") Thanks,SB -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.org.uk Mon May 19 17:30:36 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Mon, 19 May 2014 22:30:36 +0100 Subject: Problem in writing demands to the xml file References: <94945828-0caf-4534-bdaa-5371bdda6dbe@googlegroups.com> Message-ID: On Mon, 19 May 2014 14:42:02 +0100, wrote: > The problem I have is in writing the demands. I generate the necessary > stuff for it but when I try and append it, it doesn't seem to work. I'd > be glad to share my files if you need them. Could you please help me fix > this? When you say, "It doesn't seem to work," what do you mean? What are you expecting it to do? What does it actually do? Is there a traceback? -- Rhodri James *-* Wildebeest Herder to the Masses From cs at zip.com.au Mon May 19 19:03:38 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 20 May 2014 09:03:38 +1000 Subject: Python and Math In-Reply-To: <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> References: <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> Message-ID: <20140519230338.GA10003@cskk.homeip.net> On 19May2014 12:07, wxjmfauth at gmail.com wrote: >Le lundi 19 mai 2014 18:09:24 UTC+2, Rustom Mody a ?crit?: >> > Yesterday, I spent one hour attemepting to install IPython >> > for Py3.3 (win 7), I failed. I do not even succeed to >> > understand how. Pip, setuptools, whl or manualy with from the >> > zip... completely lost. There is always something not working. [...] >> >> So what're you waiting for? >> Ask here and someone or other will help you get your system running. > >You know. You are right. I can only agree. Just ask. >The problem I see, is why I only "succeded" to just find >on Google, so many people who are just asking... I have the same core skill: finding others with my question, not others with my needed answer. That the SO can usually find others with the answer when I cannot shows that there may be a mindset issue here. Cheers, Cameron Simpson Did microsoft take you today? Where do you want them to go? From jcasale at activenetwerx.com Mon May 19 19:48:04 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Mon, 19 May 2014 23:48:04 +0000 Subject: Exception problem with module In-Reply-To: <53736acb$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5372b2ae$0$29977$c3e8da3$5496439d@news.astraweb.com> <53736acb$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> Well I am not sure what advantage this has for the user, not my code as >> I don't advocate the import to begin with it, its fine spelled as it was >> from where it was... > > The advantage for the user is: /snip Hey Steven, Sorry for the late reply (travelling). My comment wasn't clear, I was ranting against the import of the exception in the second module, non the less how it was imported and not why it was not ok. Basically, it was no better than leaving it where it was, spelled as it was and requiring the user to import it from where it was defined. It turned out to be some faulty logic in the second module where the __setattr__ call was made that was preventing it from being set... jlc From mikejohnryan08 at gmail.com Mon May 19 21:05:34 2014 From: mikejohnryan08 at gmail.com (mikejohnryan08 at gmail.com) Date: Mon, 19 May 2014 18:05:34 -0700 (PDT) Subject: Clip Raster Image Pair by Overlapping Area using Python Message-ID: <96220021-03b7-4016-bbf1-f660b9590dab@googlegroups.com> Hello, I have a set of aerial images which I am trying to clip by their overlapping areas, for use in a more involved program I am writing with PIL. What would be the best method with Python to extract the overlapping area from a pair of images? I know there are libraries out there that could do this, but I couldn't find any so far. I need to execute this through Python as it will be part of a batch processing script. Any ideas/advice would be great! Thanks so much in advance. From rosuav at gmail.com Mon May 19 21:17:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 May 2014 11:17:05 +1000 Subject: Clip Raster Image Pair by Overlapping Area using Python In-Reply-To: <96220021-03b7-4016-bbf1-f660b9590dab@googlegroups.com> References: <96220021-03b7-4016-bbf1-f660b9590dab@googlegroups.com> Message-ID: On Tue, May 20, 2014 at 11:05 AM, wrote: > I have a set of aerial images which I am trying to clip by their overlapping areas, for use in a more involved program I am writing with PIL. > > What would be the best method with Python to extract the overlapping area from a pair of images? I know there are libraries out there that could do this, but I couldn't find any so far. > The problem is that they won't absolutely perfectly match, so you need some sort of similarity check. That's hard - very hard. I suggest you find a stand-alone program that will do that part of the job; it'll be easier than finding a Python library for it. ChrisA From mikejohnryan08 at gmail.com Mon May 19 21:30:48 2014 From: mikejohnryan08 at gmail.com (mikejohnryan08 at gmail.com) Date: Mon, 19 May 2014 18:30:48 -0700 (PDT) Subject: Clip Raster Image Pair by Overlapping Area using Python In-Reply-To: References: <96220021-03b7-4016-bbf1-f660b9590dab@googlegroups.com> Message-ID: On Monday, May 19, 2014 9:17:05 PM UTC-4, Chris Angelico wrote: > On Tue, May 20, 2014 at 11:05 AM, wrote: > > > I have a set of aerial images which I am trying to clip by their overlapping areas, for use in a more involved program I am writing with PIL. > > > > > > What would be the best method with Python to extract the overlapping area from a pair of images? I know there are libraries out there that could do this, but I couldn't find any so far. > > > > > > > The problem is that they won't absolutely perfectly match, so you need > > some sort of similarity check. That's hard - very hard. I suggest you > > find a stand-alone program that will do that part of the job; it'll be > > easier than finding a Python library for it. > > > > ChrisA Chris, Thanks for your response. For my purpose, the images won't have to be 'perfectly' matched, but hopefully as close as possible. Registration algorithms won't work for this reason--the images aren't identical to each other because of the different perspectives. From rosuav at gmail.com Mon May 19 21:43:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 May 2014 11:43:42 +1000 Subject: Clip Raster Image Pair by Overlapping Area using Python In-Reply-To: References: <96220021-03b7-4016-bbf1-f660b9590dab@googlegroups.com> Message-ID: On Tue, May 20, 2014 at 11:30 AM, wrote: > Thanks for your response. For my purpose, the images won't have to be 'perfectly' matched, but hopefully as close as possible. Registration algorithms won't work for this reason--the images aren't identical to each other because of the different perspectives. > Yeah, and that's what makes it hard. This is outside my area of expertise, so all I can say is that these sorts of programs do exist, but restricting yourself to Python libraries may make your life unnecessarily hard. On a separate topic, you're posting through Google Groups with its abhorrent bugs. Can you please either edit your posts before sending (removing the blank lines, wrapping to a sane width, and trimming the quoted text), or switch to a better newsreader (or the mailing list)? You'll find that a lot of people here either filter your message to /dev/null automatically, or take one look and just move on to the next post. Remember, never offend people with form when you can offend them with substance :) ChrisA From python.list at tim.thechases.com Mon May 19 21:52:52 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 19 May 2014 20:52:52 -0500 Subject: Python CGI In-Reply-To: References: Message-ID: <20140519205252.264fc764@bigbox.christie.dr> On 2014-05-19 20:32, Christian wrote: > I'd like to use Python for CGI-Scripts. Is there a manual how to > setup Python with Fast-CGI? I'd like to make sure that Python > scripts aren't executed by www-user, but the user who wrote the > script. While Burak addressed your (Fast-)CGI issues, once you have a test-script successfully giving you output, you can use the standard-library's getpass.getuser() function to tell who your script is running as. -tkc From torriem at gmail.com Mon May 19 21:47:10 2014 From: torriem at gmail.com (Michael Torrie) Date: Mon, 19 May 2014 19:47:10 -0600 Subject: Loading modules from files through C++ In-Reply-To: References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> Message-ID: <537AB41E.5020002@gmail.com> On 05/17/2014 08:01 AM, Stefan Behnel wrote: > please avoid top-posting. Trimming quoted material where appropriate is always welcome too! From joshua at landau.ws Mon May 19 22:08:22 2014 From: joshua at landau.ws (Joshua Landau) Date: Tue, 20 May 2014 03:08:22 +0100 Subject: Python Internet Database In-Reply-To: References: Message-ID: On 9 May 2014 22:06, Chris Angelico wrote: > On Sat, May 10, 2014 at 6:45 AM, wrote: >> 2 - Jit compiler for using from a web server. I mean, one has a web server running under Apache in a hosting service like Hostgator, Daddy Host or another inexpensive service. I decide to run a few applications in Racket, but the application requires number crunching. I install the Jit Racket in the hosting service, and call it from my dynamic generated page. My programs will run almost at the speed of optimised C. >> > > For number crunching, you can use the numpy library, which is highly > efficient. For general JIT compilation of actual Python code, PyPy > will do that. AFAIK there's no standard module for that, though. There's also Numba for JIT compilation of Numpy code inside CPython. From rustompmody at gmail.com Tue May 20 00:22:41 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 19 May 2014 21:22:41 -0700 (PDT) Subject: Clip Raster Image Pair by Overlapping Area using Python In-Reply-To: References: <96220021-03b7-4016-bbf1-f660b9590dab@googlegroups.com> Message-ID: On Tuesday, May 20, 2014 7:13:42 AM UTC+5:30, Chris Angelico wrote: > On a separate topic, you're posting through Google Groups with its > abhorrent bugs. Can you please either edit your posts before sending > (removing the blank lines, wrapping to a sane width, and trimming the > quoted text), or switch to a better newsreader (or the mailing list)? > You'll find that a lot of people here either filter your message to > /dev/null automatically, or take one look and just move on to the next > post. Remember, never offend people with form when you can offend them > with substance :) This https://wiki.python.org/moin/GoogleGroupsPython shows the problems and possible solutions From timr at probo.com Tue May 20 01:21:21 2014 From: timr at probo.com (Tim Roberts) Date: Mon, 19 May 2014 22:21:21 -0700 Subject: Psycopg2 : error message. References: Message-ID: dandrigo wrote: > >I'm writing a python script for a web service. I have to connect to my >postgres/postgis databases via Psycopg2. > >I writed a little first script just to connect to my pg/postgis db and drop >a test db. > >But when i execute the python file, i have several error messages. Really, this wouldn't have been so hard to figure out if you had read the documentation. conn=psycopg2.connect("dbname='busard_test' user='laurent' host='localhost' password='cactus'") Psycopg2 has two ways to specify the parameters. You can either do them as individual Python parameters, in which case each parameter is a string that needs to be quited, OR you can use a single connection string, in which case you do NOT quote the individual parameters. So, you can either do this: conn=psycopg2.connect("dbname=busard_test user=laurent host=localhost password=cactus") or do this: conn=psycopg2.connect(database='busard_test', user='laurent', host='localhost', password='cactus'") -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue May 20 01:34:04 2014 From: timr at probo.com (Tim Roberts) Date: Mon, 19 May 2014 22:34:04 -0700 Subject: Need help with executing DB query in two different places in a test References: Message-ID: <8qpln91gcks0s0mm20ds670bsajtsfss78@4ax.com> Sunitha Byju wrote: > >I am trying to automate an ecom website. I need to run DB query after >placing each order. I don't know how to run different queries after >each order. Can someone help me out with having queries after each >order submission or test? Well, what's your primary key? After each test, you need to fetch the record that should have been created, and verify that the fields contain the information you provided. For example, if you're doing a shopping cart, then you must have some kind of key associated with this session. So, you could just fetch all of the record for the session after each transaction, and make sure the contents match what you expect. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rustompmody at gmail.com Tue May 20 01:57:01 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 19 May 2014 22:57:01 -0700 (PDT) Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> Message-ID: <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> On Monday, May 19, 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > > On Mon, May 19, 2014 at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing code and then post when you have problems, or investigate some shell commands (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole job. Or pay someone to do the job for you. ChrisA > Hi ChrisAngelico, > Consider that source and destination directories are given in a .xls(excel) file. > This is the code > import xlrd, sys, subprocess > file_location = "C:\Users\salingeg\Desktop\input.xls" > workbook = xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > sheet.cell_value(0, 0) > for row in range(sheet.nrows): > values = [] > values.append(sheet.cell_value(row, 1)) > destination = [] > destination.append(sheet.cell_value(row, 2)) > for s in values: > for d in destination: > If I am using cp or xcopy command, it will copy all files from s to d. > shutil.copy(s, d) can't be used here because it overwrites files in d. Kindly help. have u tried using https://docs.python.org/2/library/os.path.html#os.path.exists ? From ronaksoni301 at gmail.com Tue May 20 03:11:43 2014 From: ronaksoni301 at gmail.com (Ronak Dhakan) Date: Tue, 20 May 2014 00:11:43 -0700 (PDT) Subject: 'Swampy' installation through 'pip' Message-ID: I have just started learning python from How to Think Like a Computer Scientist. It requires me to install 'swampy' (http://www.greenteapress.com/thinkpython/swampy/install.html) which requires me to install 'pip' (https://pip.pypa.io/en/latest/installing.html). I think I was able to somehow install pip, but am unable to install swampy. When i run 'pip install swampy' in windows command prompt, I get an error: Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\Ronak>E: E:\>pip install swampy Fatal error in launcher: Unable to create process using '""E:\Program Files\Pyth on 2.7.6\pythonw.exe"" "E:\Program Files\Python 2.7.6\Scripts\pip.exe" install s wampy' When I run 'pip install swampy' in IDLE (Python 2.7.6 Shell), I get the following error: Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> pip install swampy SyntaxError: invalid syntax >>> with the word install highlighted in red. I have installed pip by opening it in IDLE & running it from there. A new folder 'Scripts' was created in the Python installation directory 'E:\Program Files\Python 2.7.6' with the following files: easy_install-2.7.exe easy_install.exe pip2.7.exe pip2.exe pip.exe I have added 'E:\Program Files\Python 2.7.6' & 'E:\Program Files\Python 2.7.6\Scripts' to the 'path' variable in Environment Variables in Windows. I have added 'E:\Program Files\Python 2.7.6\Scripts' to the 'PYTHONPATH' variable in Environment Variables in Windows. I have read a lot online trying to get it work, but now I am lost in the technical jargons. I might have missed some steps or done something incorrectly. Please let me know where I went wrong or guide me on how to install swampy. Thanks. Ronak. From varun7rs at gmail.com Tue May 20 04:06:59 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Tue, 20 May 2014 01:06:59 -0700 (PDT) Subject: Problem in writing demands to the xml file In-Reply-To: <94945828-0caf-4534-bdaa-5371bdda6dbe@googlegroups.com> References: <94945828-0caf-4534-bdaa-5371bdda6dbe@googlegroups.com> Message-ID: <98ea99c4-fcd7-421b-88ba-b90f947afede@googlegroups.com> There is no traceback error. But I want to actually fill the demands with certain attributes which I'm not able to do. When I run the program, the xml is written but the demands doesn't have any attributes whatsoever. I could give you a clear idea of what I expect in the demands. For every node, I have an attribute called totaldemands which takes a value between 1 and 5. Now, I need the same no. of demands being written onto the xml file below every node which is now empty totaldemands = random.randint(1, 5) demnum = 0 for demand in range(totaldemands): demnum = demnum + 1 PoPbdw = random.uniform(2, 2.5) PoPstor = random.uniform(2, 2.5) PoPpro = random.uniform(0.5, 1) MMEbdw = random.uniform(2, 2.5) MMEstor = random.uniform(2, 3) MMEpro = random.uniform(0.5, 1) IMSbdw = random.uniform(2.5, 3) IMSstor = random.uniform(2.5, 3.5) IMSpro = random.uniform(0.5, 1) SGWbdw = random.uniform(3, 3.5) SGWstor = random.uniform(2.5, 3.5) SGWpro = random.uniform(0.5, 1) PGWbdw = random.uniform(2.5, 3.5) PGWstor = random.uniform(2, 2.5) PGWpro = random.uniform(0.5, 1) From wxjmfauth at gmail.com Tue May 20 05:19:08 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 20 May 2014 02:19:08 -0700 (PDT) Subject: Python and Math In-Reply-To: References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> Message-ID: <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> Le lundi 19 mai 2014 21:18:54 UTC+2, Tim Golden a ?crit?: > On 19/05/2014 20:07, wxjmfauth at gmail.com wrote: > > >>> Yesterday, I spent one hour attemepting to install IPython > > >> > > >>> for Py3.3 (win 7), I failed. I do not even succeed to > > >> > > >>> understand how. Pip, setuptools, whl or manualy with from the > > >> > > >>> zip... completely lost. There is always something not working. > > >> > > >> > > >> > > >>> This morning I installed Py 3.4.1. I do not even > > >> > > >>> succeed to put it to work. > > > > > > I realise that this probably isn't very helpful, but I've just > > successfully installed ipython on Python 3.3 and Python 3.4 (Win7 > > 32-bit) by simply doing: > > > > py -3.3 -mpip install ipython > > > > py -3.4 -mpip install ipython > > > > Since I don't have the various c:\pythonxx\scripts folders on my path, I > > did then have to launch it explictly: > > > > c:\python33\scripts\ipython > > > > but it was no harder than that. > > Sorry, but I'm even not able to understand how to install pip! Py3.3, why? because I already all the Qt derivative. I found the pip manual, I do not get it! To install pip: To install or upgrade pip, securely download get-pip.py. Where? What should I do with it? It seems you have to install From mail at timgolden.me.uk Tue May 20 06:13:45 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 20 May 2014 11:13:45 +0100 Subject: Python and Math In-Reply-To: <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> Message-ID: <537B2AD9.20003@timgolden.me.uk> On 20/05/2014 10:19, wxjmfauth at gmail.com wrote: > Le lundi 19 mai 2014 21:18:54 UTC+2, Tim Golden a ?crit : >> On 19/05/2014 20:07, wxjmfauth at gmail.com wrote: >> >>>>> Yesterday, I spent one hour attemepting to install IPython >>>>> for Py3.3 (win 7), I failed. I do not even succeed to >>>>> understand how. Pip, setuptools, whl or manualy with from >>>>> the >>>>> zip... completely lost. There is always something not >>>>> working. >> >>>>> This morning I installed Py 3.4.1. I do not even >>>>> succeed to put it to work. >> >> I realise that this probably isn't very helpful, but I've just >> successfully installed ipython on Python 3.3 and Python 3.4 (Win7 >> 32-bit) by simply doing: >> >> py -3.3 -mpip install ipython >> >> py -3.4 -mpip install ipython >> >> >> > Sorry, but I'm even not able to understand how to install pip! Py3.3, > why? because I already all the Qt derivative. > > I found the pip manual, I do not get it! To install pip: To install > or upgrade pip, securely download get-pip.py. Where? What should I do > with it? Ah, I understand. I thought you already had pip and just had difficulties beyond that. Frankly, yes, bootstrapping pip on Windows can be a bit frustrating. That's why 3.4 comes with a version pre-installed. But you say you want to stay with 3.3. If it's possible, download get-pip.py from here: https://bootstrap.pypa.io/get-pip.py (linked from here: http://pip.readthedocs.org/en/latest/installing.html) using wget, curl, File Save As, python requests, urllib.urlretrieve or whatever other method you choose. And then run the get-pip.py program with the version of Python for which you wish to install pip. eg, c:\python33\python.exe get-pip.py That will download the current versions of everything needed and will put various flavours of pip.exe into c:\python33\scripts. As I mentioned before, I've tended not to have the scripts directory on my path, and you can instead do: py -3.3 -mpip install .... I think some people have put together .msi/.exe installers for this but I can't point to any one in particular. TJG From rustompmody at gmail.com Tue May 20 07:20:09 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 20 May 2014 04:20:09 -0700 (PDT) Subject: Python and Math In-Reply-To: References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> Message-ID: <3f92f709-3c00-46d7-88ef-23ef5d0e6d8a@googlegroups.com> On Tuesday, May 20, 2014 3:43:45 PM UTC+5:30, Tim Golden wrote: > If it's possible, download get-pip.py from here: > > https://bootstrap.pypa.io/get-pip.py Gives me secure connection failed error (in firefox) From mail at timgolden.me.uk Tue May 20 07:55:40 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 20 May 2014 12:55:40 +0100 Subject: Python and Math In-Reply-To: <3f92f709-3c00-46d7-88ef-23ef5d0e6d8a@googlegroups.com> References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> <3f92f709-3c00-46d7-88ef-23ef5d0e6d8a@googlegroups.com> Message-ID: <537B42BC.3030508@timgolden.me.uk> On 20/05/2014 12:20, Rustom Mody wrote: > On Tuesday, May 20, 2014 3:43:45 PM UTC+5:30, Tim Golden wrote: >> If it's possible, download get-pip.py from here: >> >> https://bootstrap.pypa.io/get-pip.py > > Gives me secure connection failed error (in firefox) > I've reported on the PyPA issues list for pip: https://github.com/pypa/pip/issues/1823 but, as you can see from that report, I was only able to get a failure in one circumstance. I can successfully download via FF29, IE11 & chrome whatever, all on Win7. TJG From satishmlwizpro at gmail.com Tue May 20 08:21:19 2014 From: satishmlwizpro at gmail.com (Satish ML) Date: Tue, 20 May 2014 05:21:19 -0700 (PDT) Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> Message-ID: <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> On Tuesday, May 20, 2014 11:27:01 AM UTC+5:30, Rustom Mody wrote: > On Monday, May 19, 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > > On Mon, May 19, 2014 at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing code and then post when you have problems, or investigate some shell commands (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole job. Or pay someone to do the job for you. ChrisA > Hi ChrisAngelico, > Consider that source and destination directories are given in a .xls(excel) file. > This is the code > import xlrd, sys, subprocess > file_location = "C:\Users\salingeg\Desktop\input.xls" > workbook = xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > sheet.cell_value(0, 0) > for row in range(sheet.nrows): > values = [] > values.append(sheet.cell_value(row, 1)) > destination = [] > destination.append(sheet.cell_value(row, 2)) > for s in values: > for d in destination: > If I am using cp or xcopy command, it will copy all files from s to d. > shutil.copy(s, d) can't be used here because it overwrites files in d. Kindly help. have u tried using https://docs.python.org/2/library/os.path.html#os.path.exists ? I have tried it. But how does it help? We won't be able to make out whether source file is present in destination directory. From satishmlwizpro at gmail.com Tue May 20 08:23:20 2014 From: satishmlwizpro at gmail.com (Satish ML) Date: Tue, 20 May 2014 05:23:20 -0700 (PDT) Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> Message-ID: <8c6b0cd8-becf-44d6-9988-0fc017922022@googlegroups.com> On Tuesday, May 20, 2014 5:51:19 PM UTC+5:30, Satish ML wrote: > On Tuesday, May 20, 2014 11:27:01 AM UTC+5:30, Rustom Mody wrote: > On Monday, May 19, 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > > On Mon, May 19, 2014 at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing code and then post when you have problems, or investigate some shell commands (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole job. Or pay someone to do the job for you. ChrisA > Hi ChrisAngelico, > Consider that source and destination directories are given in a .xls(excel) file. > This is the code > import xlrd, sys, subprocess > file_location = "C:\Users\salingeg\Desktop\input.xls" > workbook = xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > sheet.cell_value(0, 0) > for row in range(sheet.nrows): > values = [] > values.append(sheet.cell_value(row, 1)) > destination = [] > destination.append(sheet.cell_value(row, 2)) > for s in values: > for d in destination: > If I am using cp or xcopy command, it will copy all files from s to d. > shutil.copy(s, d) can't be used here because it overwrites files in d. Kindly help. have u tried using https://docs.python.org/2/library/os.path.html#os.path.exists ? I have tried it. But how does it help? We won't be able to make out whether source file is present in destination directory. If we can do that, like if (source file exists in destination directory) print "exists" else shutil.copy(s, d) From satishmlwizpro at gmail.com Tue May 20 08:24:47 2014 From: satishmlwizpro at gmail.com (Satish ML) Date: Tue, 20 May 2014 05:24:47 -0700 (PDT) Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> Message-ID: <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> On Tuesday, May 20, 2014 5:51:19 PM UTC+5:30, Satish ML wrote: > On Tuesday, May 20, 2014 11:27:01 AM UTC+5:30, Rustom Mody wrote: > On Monday, May 19, 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > > On Mon, May 19, 2014 at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing code and then post when you have problems, or investigate some shell commands (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole job. Or pay someone to do the job for you. ChrisA > Hi ChrisAngelico, > Consider that source and destination directories are given in a .xls(excel) file. > This is the code > import xlrd, sys, subprocess > file_location = "C:\Users\salingeg\Desktop\input.xls" > workbook = xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > sheet.cell_value(0, 0) > for row in range(sheet.nrows): > values = [] > values.append(sheet.cell_value(row, 1)) > destination = [] > destination.append(sheet.cell_value(row, 2)) > for s in values: > for d in destination: > If I am using cp or xcopy command, it will copy all files from s to d. > shutil.copy(s, d) can't be used here because it overwrites files in d. Kindly help. have u tried using https://docs.python.org/2/library/os.path.html#os.path.exists ? I have tried it. But how does it help? We won't be able to make out whether source file is present in destination directory. If we can do that, like if (source file exists in destination directory) print "exists" continue else shutil.copy(s, d) From satishmlwizpro at gmail.com Tue May 20 08:28:09 2014 From: satishmlwizpro at gmail.com (Satish ML) Date: Tue, 20 May 2014 05:28:09 -0700 (PDT) Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> Message-ID: <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> On Tuesday, May 20, 2014 5:54:47 PM UTC+5:30, Satish ML wrote: > On Tuesday, May 20, 2014 5:51:19 PM UTC+5:30, Satish ML wrote: > On Tuesday, May 20, 2014 11:27:01 AM UTC+5:30, Rustom Mody wrote: > On Monday, May 19, 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > > On Mon, May 19, 2014 at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing code and then post when you have problems, or investigate some shell commands (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole job. Or pay someone to do the job for you. ChrisA > Hi ChrisAngelico, > Consider that source and destination directories are given in a .xls(excel) file. > This is the code > import xlrd, sys, subprocess > file_location = "C:\Users\salingeg\Desktop\input.xls" > workbook = xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > sheet.cell_value(0, 0) > for row in range(sheet.nrows): > values = [] > values.append(sheet.cell_value(row, 1)) > destination = [] > destination.append(sheet.cell_value(row, 2)) > for s in values: > for d in destination: > If I am using cp or xcopy command, it will copy all files from s to d. > shutil.copy(s, d) can't be used here because it overwrites files in d. Kindly help. have u tried using https://docs.python.org/2/library/os.path.html#os.path.exists ? I have tried it. But how does it help? We won't be able to make out whether source file is present in destination directory. If we can do that, like if (source file exists in destination directory) print "exists" continue else shutil.copy(s, d) Here we don't have the option of manually giving the file path. It has to be read from .xls file (i.e. from the two lists in code) From alister.nospam.ware at ntlworld.com Tue May 20 08:48:16 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 20 May 2014 12:48:16 GMT Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> Message-ID: On Tue, 20 May 2014 05:28:09 -0700, Satish ML wrote: > On Tuesday, May 20, 2014 5:54:47 PM UTC+5:30, Satish ML wrote: >> On Tuesday, May 20, 2014 5:51:19 PM UTC+5:30, Satish ML wrote: > On >> Tuesday, May 20, 2014 11:27:01 AM UTC+5:30, Rustom Mody wrote: > On >> Monday, May 19, 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, >> May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > > On Mon, >> May 19, 2014 at 4:53 PM, wrote: > Could you kindly help? Sure. Either >> start writing code and then post when you have problems, or investigate >> some shell commands (xcopy in Windows, cp in Linux, maybe scp) that can >> probably do the whole job. Or pay someone to do the job for you. ChrisA >> > Hi ChrisAngelico, > Consider that source and destination directories >> are given in a .xls(excel) file. > This is the code > import xlrd, sys, >> subprocess > file_location = "C:\Users\salingeg\Desktop\input.xls" > >> workbook = xlrd.open_workbook(file_location) > sheet = >> workbook.sheet_by_index(0) > sheet.cell_value(0, 0) > for row in >> range(sheet.nrows): > values = [] > values.append(sheet.cell_value(row, >> 1)) > destination = [] > destination.append(sheet.cell_value(row, 2)) > >> for s in values: > for d in destination: > If I am using cp or xcopy >> command, it will copy all files from s to d. > shutil.copy(s, d) can't >> be used here because it overwrites files in d. Kindly help. have u >> tried using >> https://docs.python.org/2/library/os.path.html#os.path.exists ? I have >> tried it. But how does it help? We won't be able to make out whether >> source file is present in destination directory. If we can do that, >> like if (source file exists in destination directory) print "exists" >> continue else shutil.copy(s, d) > > Here we don't have the option of manually giving the file path. It has > to be read from .xls file (i.e. from the two lists in code) 1) Post your current code & any errors you are getting, this list is not a free software development house 2) Please clean up your posts before sending so that they are readable either use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. Thanks to Mark for the above paragraph I hope this is "Acceptable Usage" & not a copyright breach ;-) -- My weight is perfect for my height -- which varies. From frank at chagford.com Tue May 20 08:51:27 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 20 May 2014 14:51:27 +0200 Subject: Python and Math References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> <3f92f709-3c00-46d7-88ef-23ef5d0e6d8a@googlegroups.com> <537B42BC.3030508@timgolden.me.uk> Message-ID: "Tim Golden" wrote in message news:537B42BC.3030508 at timgolden.me.uk... > On 20/05/2014 12:20, Rustom Mody wrote: >> On Tuesday, May 20, 2014 3:43:45 PM UTC+5:30, Tim Golden wrote: >>> If it's possible, download get-pip.py from here: >>> >>> https://bootstrap.pypa.io/get-pip.py >> >> Gives me secure connection failed error (in firefox) >> > > I've reported on the PyPA issues list for pip: > > https://github.com/pypa/pip/issues/1823 > > but, as you can see from that report, I was only able to get a failure > in one circumstance. I can successfully download via FF29, IE11 & chrome > whatever, all on Win7. > I have never managed to install pip before (not that I have tried very hard) but following your instructions I seemed to have installed it successfully, using Windows Server 2003, IE8, and python 3.3. I used it to install IPython, with the following results. First I ran 'pip install ipython', which worked. Then I read the IPython docs, which gave the following command to install Notebook - 'pip install ipython[notebook]' That seemed to work, but when I ran 'ipython notebook' it failed on 'import pyzmq'. I ran 'pip install pyzmq', tried again, and it failed on 'import jinja2'. I used pip to install that, then it failed on 'import tornado'. I used pip to install that, and now it seems to be working. Now I understand why 'pip' is so popular - despite the above hiccups, it felt very smooth. Thanks for the instructions, Tim - much appreciated. Frank Millman From breamoreboy at yahoo.co.uk Tue May 20 09:20:28 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 20 May 2014 14:20:28 +0100 Subject: 'Swampy' installation through 'pip' In-Reply-To: References: Message-ID: On 20/05/2014 08:11, Ronak Dhakan wrote: > I have just started learning python from How to Think Like a Computer Scientist. It requires me to install 'swampy' (http://www.greenteapress.com/thinkpython/swampy/install.html) which requires me to install 'pip' (https://pip.pypa.io/en/latest/installing.html). I think I was able to somehow install pip, but am unable to install swampy. > > When i run 'pip install swampy' in windows command prompt, I get an error: > > Microsoft Windows XP [Version 5.1.2600] > (C) Copyright 1985-2001 Microsoft Corp. > > C:\Documents and Settings\Ronak>E: > > E:\>pip install swampy > Fatal error in launcher: Unable to create process using '""E:\Program Files\Pyth > on 2.7.6\pythonw.exe"" "E:\Program Files\Python 2.7.6\Scripts\pip.exe" install s > wampy' > Your setup looks wrong, surely that should be python.exe, not pythonw.exe. I'd recommend reinstalling and use the default settings, putting Python at the top level of the disk and not in "Program Files", that's another set of potential set of problems eliminated straight away. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Tue May 20 09:35:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 May 2014 23:35:21 +1000 Subject: 'Swampy' installation through 'pip' In-Reply-To: References: Message-ID: On Tue, May 20, 2014 at 11:20 PM, Mark Lawrence wrote: > I'd recommend reinstalling and use the default settings, putting Python at > the top level of the disk and not in "Program Files", that's another set of > potential set of problems eliminated straight away. Second this recommendation. I saw some NEWS entries recently regarding pip and spaces in file names. If you're on the absolute latest pip, it would quite possibly work, but I don't know if that works with 2.7, and if so, with which 2.7.x. Avoid spaces unless you're sure. In fact, looking at the error messages, I suspect this isn't a *potential* set of problems, but quite probably the actual problem. ChrisA From wxjmfauth at gmail.com Tue May 20 09:42:19 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 20 May 2014 06:42:19 -0700 (PDT) Subject: Python and Math In-Reply-To: References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> Message-ID: <884c2d26-b5c1-4caf-b686-f031555a80f7@googlegroups.com> Le mardi 20 mai 2014 12:13:45 UTC+2, Tim Golden a ?crit?: > On 20/05/2014 10:19, wxjmfauth at gmail.com wrote: > > > Le lundi 19 mai 2014 21:18:54 UTC+2, Tim Golden a ???crit : > > >> On 19/05/2014 20:07, wxjmfauth at gmail.com wrote: > > >> > > >>>>> Yesterday, I spent one hour attemepting to install IPython > > >>>>> for Py3.3 (win 7), I failed. I do not even succeed to > > >>>>> understand how. Pip, setuptools, whl or manualy with from > > >>>>> the > > >>>>> zip... completely lost. There is always something not > > >>>>> working. > > > > >> > > >>>>> This morning I installed Py 3.4.1. I do not even > > >>>>> succeed to put it to work. > > >> > > >> I realise that this probably isn't very helpful, but I've just > > >> successfully installed ipython on Python 3.3 and Python 3.4 (Win7 > > >> 32-bit) by simply doing: > > >> > > >> py -3.3 -mpip install ipython > > >> > > >> py -3.4 -mpip install ipython > > >> > > >> > > >> > > > Sorry, but I'm even not able to understand how to install pip! Py3.3, > > > why? because I already all the Qt derivative. > > > > > > I found the pip manual, I do not get it! To install pip: To install > > > or upgrade pip, securely download get-pip.py. Where? What should I do > > > with it? > > > > Ah, I understand. I thought you already had pip and just had > > difficulties beyond that. Frankly, yes, bootstrapping pip on Windows can > > be a bit frustrating. That's why 3.4 comes with a version pre-installed. > > But you say you want to stay with 3.3. > > > > If it's possible, download get-pip.py from here: > > > > https://bootstrap.pypa.io/get-pip.py > > > > (linked from here: http://pip.readthedocs.org/en/latest/installing.html) > > > > using wget, curl, File Save As, python requests, urllib.urlretrieve or > > whatever other method you choose. > > > > And then run the get-pip.py program with the version of Python for which > > you wish to install pip. eg, > > > > c:\python33\python.exe get-pip.py > > > > That will download the current versions of everything needed and will > > put various flavours of pip.exe into c:\python33\scripts. As I mentioned > > before, I've tended not to have the scripts directory on my path, and > > you can instead do: > > > > py -3.3 -mpip install .... > > > > > > I think some people have put together .msi/.exe installers for this but > > I can't point to any one in particular. > > > > TJG ------ I give up. Anyway, thanks. From rustompmody at gmail.com Tue May 20 10:14:46 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 20 May 2014 07:14:46 -0700 (PDT) Subject: Python and Math In-Reply-To: References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> <3f92f709-3c00-46d7-88ef-23ef5d0e6d8a@googlegroups.com> Message-ID: <3782869a-e50c-4d88-944a-46aafbfc3647@googlegroups.com> On Tuesday, May 20, 2014 5:25:40 PM UTC+5:30, Tim Golden wrote: > On 20/05/2014 12:20, Rustom Mody wrote: > > > On Tuesday, May 20, 2014 3:43:45 PM UTC+5:30, Tim Golden wrote: > >> If it's possible, download get-pip.py from here: > >> > >> https://bootstrap.pypa.io/get-pip.py > > > > Gives me secure connection failed error (in firefox) > > > > > I've reported on the PyPA issues list for pip: > > https://github.com/pypa/pip/issues/1823 Thanks > > > > but, as you can see from that report, I was only able to get a failure > > in one circumstance. I can successfully download via FF29, IE11 & chrome > > whatever, all on Win7. Seems to be working for me also (now). [Without claiming any understanding]... I dont know what wget has to do with it (in the bug report) I just opened it in firefox: Earlier it didn't work now its working From rustompmody at gmail.com Tue May 20 10:23:26 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 20 May 2014 07:23:26 -0700 (PDT) Subject: Python and Math In-Reply-To: <884c2d26-b5c1-4caf-b686-f031555a80f7@googlegroups.com> References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> <884c2d26-b5c1-4caf-b686-f031555a80f7@googlegroups.com> Message-ID: On Tuesday, May 20, 2014 7:12:19 PM UTC+5:30, jmf wrote: > I give up. > Anyway, thanks. Take a deep breath. Be patient. And post the backtrace (or whatever is the evidence of 'not working') From wxjmfauth at gmail.com Tue May 20 10:31:11 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 20 May 2014 07:31:11 -0700 (PDT) Subject: Putting Py 3.4.1 to work. Message-ID: Experimented users have certainly noticed a lot of things have changed. Short. I installed Py3.4.1, it overwrites c:\Python34 which contained eg. PySide in ...\site-packages. So far, so good. I can launch Python, IDLE and my interactive interpreter I wrote with tkinter via a cmd in dos, .bat, ... Now the questions. It seems all packages in \site-packages are no more recognized. What am I doing wrong? Why is "site-packages" no more recognized, "forcing" sys.path does not seem to help. >From my interactive interpreter: >>> --- import PySide Traceback (most recent call last): File "", line 1, in ImportError: No module named 'PySide' >>> --- sys.path ['D:\\jm\\jmpy\\smid\\smid50beta1', 'C:\\Windows\\system32\\python34.zip', 'C:\\Python34\\DLLs\\DLLs', 'C:\\Python34\\DLLs\\lib', 'C:\\Python34\\DLLs', 'C:\\Python34\\DLLs\\lib\\site-packages'] >>> --- sys.path.append(r'C:\Python34\Lib\site-packages\PySide') >>> --- sys.path ['D:\\jm\\jmpy\\smid\\smid50beta1', 'C:\\Windows\\system32\\python34.zip', 'C:\\Python34\\DLLs\\DLLs', 'C:\\Python34\\DLLs\\lib', 'C:\\Python34\\DLLs', 'C:\\Python34\\DLLs\\lib\\site-packages', 'C:\\Python34\\Lib\\site-packages\\PySide'] >>> --- import PySide Traceback (most recent call last): File "", line 1, in ImportError: No module named 'PySide' >>> --- sys.version '3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)]' >>> --- jmf From peft at icon.co.za Tue May 20 10:25:37 2014 From: peft at icon.co.za (Pat Fourie) Date: Tue, 20 May 2014 16:25:37 +0200 Subject: Basic help Message-ID: <000001cf7437$613cedc0$23b6c940$@icon.co.za> Good Day all. I am new to Python. I need to maintain software written on Python 1.5.2. I will upgrade after learning more. My question is : When compiling, the results of the compile is displayed in the "active window". How can I view this window. Many thanks for your assistance. Kind regards Pat -- This message has been scanned for viruses and dangerous content by Pinpoint, and is believed to be clean. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 20 11:33:49 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 20 May 2014 09:33:49 -0600 Subject: 'Swampy' installation through 'pip' In-Reply-To: References: Message-ID: On May 20, 2014 7:22 AM, "Mark Lawrence" wrote: > > On 20/05/2014 08:11, Ronak Dhakan wrote: >> >> I have just started learning python from How to Think Like a Computer Scientist. It requires me to install 'swampy' ( http://www.greenteapress.com/thinkpython/swampy/install.html) which requires me to install 'pip' ( https://pip.pypa.io/en/latest/installing.html). I think I was able to somehow install pip, but am unable to install swampy. >> >> When i run 'pip install swampy' in windows command prompt, I get an error: >> >> Microsoft Windows XP [Version 5.1.2600] >> (C) Copyright 1985-2001 Microsoft Corp. >> >> C:\Documents and Settings\Ronak>E: >> >> E:\>pip install swampy >> Fatal error in launcher: Unable to create process using '""E:\Program Files\Pyth >> on 2.7.6\pythonw.exe"" "E:\Program Files\Python 2.7.6\Scripts\pip.exe" install s >> wampy' >> > > Your setup looks wrong, surely that should be python.exe, not pythonw.exe. I would bet that's a result of installing from IDLE. Recommend reinstalling pip from the Windows command line. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mnjagadeesh at gmail.com Tue May 20 12:05:10 2014 From: mnjagadeesh at gmail.com (Jagadeesh Malakannavar) Date: Tue, 20 May 2014 21:35:10 +0530 (IST) Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> Message-ID: Hi Satish, Can you please send python part in plain text format? Python code here is difficult to read. Thanks On Tue, 20 May 2014, Satish ML wrote: | On Tuesday, May 20, 2014 5:54:47 PM UTC+5:30, Satish ML wrote: | > On Tuesday, May 20, 2014 5:51:19 PM UTC+5:30, Satish ML wrote: > On Tuesday, May 20, 2014 11:27:01 AM UTC+5:30, Rustom Mody wrote: > On Monday, May 19, 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > > On Mon, May 19, 2014 at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing code and then post when you have problems, or investigate some shell commands (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole job. Or pay someone to do the job for you. ChrisA > Hi ChrisAngelico, > Consider that source and destination directories are given in a .xls(excel) file. > This is the code > import xlrd, sys, subprocess > file_location = "C:\Users\salingeg\Desktop\input.xls" > workbook = xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > sheet.cell_value(0, 0) > for row in range(sheet.nrows): > values = [] > values.append(sheet.cell_value(row, 1)) > destination = [] > dest | ination.append(sheet.cell_value(row, 2)) > for s in values: > for d in destination: > If I am using cp or xcopy command, it will copy all files from s to d. > shutil.copy(s, d) can't be used here because it overwrites files in d. Kindly help. have u tried using https://docs.python.org/2/library/os.path.html#os.path.exists ? I have tried it. But how does it help? We won't be able to make out whether source file is present in destination directory. If we can do that, like if (source file exists in destination directory) print "exists" continue else shutil.copy(s, d) | | Here we don't have the option of manually giving the file path. It has to be read from .xls file (i.e. from the two lists in code) | From skip at pobox.com Tue May 20 12:38:06 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 20 May 2014 11:38:06 -0500 Subject: Reading OpenOffice spreadsheet in Python? Message-ID: I don't have Windows and since upgrading my Mac to Mavericks I no longer have Excel of any flavor. I have a few Excel spreadsheets in which I store parameters from which I generate other config files. I read those spreadsheets using xlrd. I am so fed up with LibreOffice's inability to properly support really basic Excel capabilities, I'm about ready to throw my computer out the window. So, I'm looking for alternatives. Before someone suggests config parser/Windows INI files... A spreadsheet format is kinda handy in this case because I do use a few formulas to define some of the parameters. Adding a new row (new config file) or column (new parameter) is a breeze. The simplest solution would seem to be to submit to LibreOffice's terror and just start saving my spreadsheets in OpenDocument format. That then puts me in the market for an xlrd replacement. Is there something akin to xlrd for OpenDocument spreadsheets? I see a couple possibilities in PyPI (exodf, odfpy), but none which have a really high weight (suggesting they are "category killers"). I'm open to other options as well. I see a number of Google spreadsheet modules, and there is pyspread. The former has the permission issue (besides, where I work everything goes into Git), and I'm not sure how full-featured or stable the latter is (but, will investigate). Thx, Skip From ned at nedbatchelder.com Tue May 20 12:40:51 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 20 May 2014 12:40:51 -0400 Subject: Basic help In-Reply-To: <000001cf7437$613cedc0$23b6c940$@icon.co.za> References: <000001cf7437$613cedc0$23b6c940$@icon.co.za> Message-ID: On 5/20/14 10:25 AM, Pat Fourie wrote: > Good Day all. > > I am new to Python. I need to maintain software written on Python 1.5.2. > I will upgrade after learning more. Pat, you are dealing with a version most people have never even seen! You are brave! :) > > My question is : > > When compiling, the results of the compile is displayed in the ?active > window?. How can I view this window. You'll have to clarify what you are referring to. Python typically has no explicit compile phase. Python also is often used in a terminal window, and has no built-in idea of "active window". Can you tell us more about your environment? > > Many thanks for your assistance. > > Kind regards > > Pat -- Ned Batchelder, http://nedbatchelder.com From rosuav at gmail.com Tue May 20 12:49:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 May 2014 02:49:09 +1000 Subject: Reading OpenOffice spreadsheet in Python? In-Reply-To: References: Message-ID: On Wed, May 21, 2014 at 2:38 AM, Skip Montanaro wrote: > Before someone suggests > config parser/Windows INI files... A spreadsheet format is kinda handy > in this case because I do use a few formulas to define some of the > parameters. Adding a new row (new config file) or column (new > parameter) is a breeze. Okay, I won't suggest Windows INI files, but I'll still suggest taking a step back and figuring out exactly what you're trying to accomplish. Can you separate out the real data from the formula-derived info, put the former into a git-managed file, and the latter into something you regenerate by script (maybe off a makefile)? Organize your source file in such a way that adding a new config file or new parameter is easy. The beauty of a spreadsheet is that a cell could be *either* a formula *or* actual data, completely indistinguishably (note, some may argue that this is also a major weakness of spreadsheets); I would guess you most likely don't need that flexibility, and can easily separate "source" and "calculated". You could make your file format CSV or tab delimited, and then use LibreOffice to edit it, if that makes the most sense. Something to consider, since I can't specifically advise on OO/LO readers/writers. :) ChrisA From emile at fenx.com Tue May 20 12:51:15 2014 From: emile at fenx.com (Emile van Sebille) Date: Tue, 20 May 2014 09:51:15 -0700 Subject: Basic help In-Reply-To: <000001cf7437$613cedc0$23b6c940$@icon.co.za> References: <000001cf7437$613cedc0$23b6c940$@icon.co.za> Message-ID: On 5/20/2014 7:25 AM, Pat Fourie wrote: > Good Day all. > > I am new to Python. Welcome -- > I need to maintain software written on Python 1.5.2. I'd point you to the tutorial for a start. See the docs at https://docs.python.org/release/1.5.2/ > I will upgrade after learning more. > > My question is : > > When compiling, Python isn't a compiled language other than reduction to byte code which doesn't require a compile step but rather is done automatically at run time, so this is somewhat confusing. > the results of the compile is displayed in the ?active > window?. How can I view this window. Here you are likely referring to your editor, but that's not a python issue. HTH, Emile > > Many thanks for your assistance. > > Kind regards > > Pat > > > -- > This message has been scanned for viruses and > dangerous content by *Pinpoint Securemail*, > and is believed to be clean. > > From roland at rptd.ch Tue May 20 13:17:37 2014 From: roland at rptd.ch (=?UTF-8?B?Um9sYW5kIFBsw7xzcw==?=) Date: Tue, 20 May 2014 19:17:37 +0200 Subject: Loading modules from files through C++ In-Reply-To: References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> <53778005.8030105@rptd.ch> <53778E22.3040701@rptd.ch> <53790CCF.1070905@rptd.ch> Message-ID: <537B8E31.7000607@rptd.ch> On 05/19/2014 03:40 AM, Chris Angelico wrote: > On Mon, May 19, 2014 at 5:41 AM, Roland Pl?ss wrote: >> This exec source_code in module.__dict__ , should this not also be doable >> with PyEval_EvalCode? > General principle: The more code you write in Python and the less in > C/C++, the happier and more productive you will be. > > Drop into Python as soon as you can, and do all the work from there. > You won't have to worry about RAM (de)allocation, Unicode (especially > if you use Python 3 rather than 2), integer overflow, etc, etc, etc. > Only write lower-level code for the bits that actually demand it; and > as Stefan has pointed out, Cython is a great help there. > > (Which reminds me. I still need some "excuse project" to justify my > learning Cython. It's good-looking tech but everything I can imagine > writing seems to already exist.) > > ChrisA Figured out the solution to the problem. Inspected some python imported files to check out the module is actually constructed. Turns out something has been missing. In general I needed this to get it working: PyObject * const loadedModule = Py_InitModule3( fullname, NULL, "Loaded module" ); PyObject * const moduleDict = PyModule_GetDict( loadedModule ); // borrowed reference PyDict_SetItemString( moduleDict, "__builtins__", PyEval_GetBuiltins() ); PyRun_StringFlags( fileContent, Py_file_input, moduleDict, moduleDict, NULL ); The important part are the last two lines. An important module is lacking the __builtins__ dictionary member so I had to add it. Furthermore I had to call the string runner with moduleDict both as global and local dictionary. With that change the virtual script is properly loaded and working as it should. Hopefully this works also in Py3 should I switch some time later. But I guess it should seeing how simple the import now became. -- Yours sincerely Pl?ss Roland Leader and Head Programmer - Game: Epsylon ( http://www.indiedb.com/games/epsylon ) - Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine , http://dragengine.rptd.ch/wiki ) - Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php ) - As well as various Blender export scripts und game tools -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 263 bytes Desc: OpenPGP digital signature URL: From gordon at panix.com Tue May 20 13:14:57 2014 From: gordon at panix.com (John Gordon) Date: Tue, 20 May 2014 17:14:57 +0000 (UTC) Subject: Putting Py 3.4.1 to work. References: Message-ID: In wxjmfauth at gmail.com writes: > sys.path > ['D:\\jm\\jmpy\\smid\\smid50beta1', 'C:\\Windows\\system32\\python34.zip', > 'C:\\Python34\\DLLs\\DLLs', 'C:\\Python34\\DLLs\\lib', 'C:\\Python34\\DLLs', > 'C:\\Python34\\DLLs\\lib\\site-packages', 'C:\\Python34\\Lib\\site-packages\\PySide'] > >>> --- > import PySide > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named 'PySide' Is there a file named __init__.py in the PySide directory? Did 'import PySide' used to work on Python 3.4.0? -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From ian.g.kelly at gmail.com Tue May 20 13:38:12 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 20 May 2014 11:38:12 -0600 Subject: Putting Py 3.4.1 to work. In-Reply-To: References: Message-ID: On Tue, May 20, 2014 at 11:14 AM, John Gordon wrote: > In wxjmfauth at gmail.com writes: > >> sys.path >> ['D:\\jm\\jmpy\\smid\\smid50beta1', 'C:\\Windows\\system32\\python34.zip', >> 'C:\\Python34\\DLLs\\DLLs', 'C:\\Python34\\DLLs\\lib', 'C:\\Python34\\DLLs', >> 'C:\\Python34\\DLLs\\lib\\site-packages', 'C:\\Python34\\Lib\\site-packages\\PySide'] >> >>> --- >> import PySide >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named 'PySide' > > Is there a file named __init__.py in the PySide directory? > Did 'import PySide' used to work on Python 3.4.0? > Or maybe some .pth file got clobbered. I always reinstall packages after upgrading Python on Windows. I don't know whether the scenario of reinstalling Python on top of an existing site-packages directory is supposed to work or not. From rosuav at gmail.com Tue May 20 13:55:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 May 2014 03:55:58 +1000 Subject: Loading modules from files through C++ In-Reply-To: <537B8E31.7000607@rptd.ch> References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> <53778005.8030105@rptd.ch> <53778E22.3040701@rptd.ch> <53790CCF.1070905@rptd.ch> <537B8E31.7000607@rptd.ch> Message-ID: On Wed, May 21, 2014 at 3:17 AM, Roland Pl?ss wrote: > The important part are the last two lines. An important module is > lacking the __builtins__ dictionary member so I had to add it. > > Hopefully this works also in Py3 should I switch some time later. But I > guess it should seeing how simple the import now became. An interesting omission, I'm a little surprised at that. But if your switch to Py3 is a serious (or even half-serious) possibility, I recommend tossing a quick comment against that line of code. Check to see if you actually need it, and if you still do, see if there's a change there. The module has been renamed (from __builtin__ to builtins, although the global reference to it is still __builtins__), so you may need to adjust something there, too. But mainly, see if you can drop that line of code in Py3. > Furthermore I had to call the string runner with moduleDict both as > global and local dictionary. With that change the virtual script is > properly loaded and working as it should. This part does make sense, though. Normally, module-level code runs with the same locals and globals: >>> locals() is globals() True And that doesn't change in Py3, so I would expect that your C++ code also won't change. ChrisA From lcelati at latitude-geosystems.com Tue May 20 14:06:35 2014 From: lcelati at latitude-geosystems.com (image) Date: Tue, 20 May 2014 11:06:35 -0700 (PDT) Subject: Code a web service with python/postgis Message-ID: <1400609195596-5057714.post@n6.nabble.com> Dear all, I would like code a web service with python. I have already imported several vector data (land cover) and one Digital Elevation Model (raster layer) into my postgresql/postgis database (server side). I succeed in connecting to my pg db via psycopg2. Client side, operators use a client application (Developed with PHP / javascript / openlayers). Objectives : Client side, once the layer would be selected,and once the operators have clicked on the map , they would like that usefull informations appear on the interface of the client application(kind of land cover, z of the DEM). => Regarding my python script, i have to type a SQL query in order to select usefull informations of the db layers. And, of course, the information must depend on geographic coordinates (Latitude Y/Longitute X). In a 2nd time, my script must produce a result(JSon type) for the client side. It would be possible to help me regarding the coding in order to select usefull informations of the db layers. (depends on geographic coordinates x/y ? Could you throw light for me regarding the way to do this SQL query ? In advance, thank you to throw light for me. -- View this message in context: http://python.6.x6.nabble.com/Code-a-web-service-with-python-postgis-tp5057714.html Sent from the Python - python-list mailing list archive at Nabble.com. From vincent.vandevyvre at swing.be Tue May 20 14:02:37 2014 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Tue, 20 May 2014 20:02:37 +0200 Subject: Putting Py 3.4.1 to work. In-Reply-To: References: Message-ID: <537B98BD.80808@swing.be> Le 20/05/2014 19:38, Ian Kelly a ?crit : > On Tue, May 20, 2014 at 11:14 AM, John Gordon wrote: >> In wxjmfauth at gmail.com writes: >> >>> sys.path >>> ['D:\\jm\\jmpy\\smid\\smid50beta1', 'C:\\Windows\\system32\\python34.zip', >>> 'C:\\Python34\\DLLs\\DLLs', 'C:\\Python34\\DLLs\\lib', 'C:\\Python34\\DLLs', >>> 'C:\\Python34\\DLLs\\lib\\site-packages', 'C:\\Python34\\Lib\\site-packages\\PySide'] >>>>>> --- >>> import PySide >>> Traceback (most recent call last): >>> File "", line 1, in >>> ImportError: No module named 'PySide' >> Is there a file named __init__.py in the PySide directory? >> Did 'import PySide' used to work on Python 3.4.0? >> > Or maybe some .pth file got clobbered. > > I always reinstall packages after upgrading Python on Windows. I > don't know whether the scenario of reinstalling Python on top of an > existing site-packages directory is supposed to work or not. What about: from pyside import QtCore, QtGui ? -- Vincent V.V. Oqapy . Qarte . PaQager From rosuav at gmail.com Tue May 20 14:12:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 May 2014 04:12:40 +1000 Subject: Putting Py 3.4.1 to work. In-Reply-To: <537B98BD.80808@swing.be> References: <537B98BD.80808@swing.be> Message-ID: On Wed, May 21, 2014 at 4:02 AM, Vincent Vande Vyvre wrote: > from pyside import QtCore, QtGui Is it pyside or PySide? There seems to be some inconsistency here. ChrisA From breamoreboy at yahoo.co.uk Tue May 20 14:13:45 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 20 May 2014 19:13:45 +0100 Subject: Putting Py 3.4.1 to work. In-Reply-To: References: Message-ID: On 20/05/2014 18:38, Ian Kelly wrote: > On Tue, May 20, 2014 at 11:14 AM, John Gordon wrote: >> In wxjmfauth at gmail.com writes: >> >>> sys.path >>> ['D:\\jm\\jmpy\\smid\\smid50beta1', 'C:\\Windows\\system32\\python34.zip', >>> 'C:\\Python34\\DLLs\\DLLs', 'C:\\Python34\\DLLs\\lib', 'C:\\Python34\\DLLs', >>> 'C:\\Python34\\DLLs\\lib\\site-packages', 'C:\\Python34\\Lib\\site-packages\\PySide'] >>>>>> --- >>> import PySide >>> Traceback (most recent call last): >>> File "", line 1, in >>> ImportError: No module named 'PySide' >> >> Is there a file named __init__.py in the PySide directory? >> Did 'import PySide' used to work on Python 3.4.0? >> > > Or maybe some .pth file got clobbered. > > I always reinstall packages after upgrading Python on Windows. I > don't know whether the scenario of reinstalling Python on top of an > existing site-packages directory is supposed to work or not. > I've never bothered to reinstall packages after upgrading Python on Windows and I've never had a problem. I can't see how Python can do anything with site-packages as it knows nothing about it, other than that it exists, so it strikes me that it has to work, or am I missing something? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From lcelati at latitude-geosystems.com Tue May 20 14:10:05 2014 From: lcelati at latitude-geosystems.com (lcelati at latitude-geosystems.com) Date: Tue, 20 May 2014 20:10:05 +0200 Subject: Code a web service with python/postgis Message-ID: <20140520201005.ddj5zabr8goog4kg@webmail.latitude-geosystems.com> Dear all, I would like code a web service with python. I have already imported several vector data (land cover) and one Digital Elevation Model (raster layer) into my postgresql/postgis database (server side). I succeed in connecting to my pg db via psycopg2. Client side, operators use a client application (Developed with PHP / javascript / openlayers). Objectives : Client side, once the layer would be selected,and once the operators have clicked on the map , they would like that usefull informations appear on the interface of the client application(kind of land cover, z of the DEM). => Regarding my python script, i have to type a SQL query in order to select usefull informations of the db layers. And, of course, the information must depend on geographic coordinates (Latitude Y/Longitute X). In a 2nd time, my script must produce a result(JSon type) for the client side. It would be possible to help me regarding the coding in order to select usefull informations of the db layers. (depends on geographic coordinates x/y ? Could you throw light for me regarding the way to do this SQL query ? In advance, thank you to throw light for me. From fabiofz at gmail.com Tue May 20 14:19:46 2014 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 20 May 2014 15:19:46 -0300 Subject: PyDev 3.5.0 Released Message-ID: What is PyDev? --------------------------- PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com What is LiClipse? --------------------------- LiClipse is a PyDev standalone with goodies such as support for Multiple cursors, theming and a number of other languages such as Django Templates, Kivy Language, Mako Templates, Html, Javascript, etc. It's also a commercial counterpart which helps supporting the development of PyDev. Details on LiClipse: http://brainwy.github.io/liclipse/ Release Highlights: ------------------------------- - **Important**: PyDev requires Eclipse 3.8 or 4.3 onwards and Java 7! For older versions, keep using PyDev 2.x (or LiClipse for a PyDev standalone with all requirements bundled). * Adding plead for the current crowdfunding at http://tiny.cc/pydev-2014. * PyDev now has a new logo. * **py.test**: * Improved py.test test runner preferences page. * py.test integration improved to be less intrusive and work with xdist. * py.test protocol invocation now allows for module/session scoped fixtures to work properly. * Add bookmark and add task actions are shown in the ruler context menu (**Ctrl+F10**). * Code completion was not properly recognizing variables assigned to self inside an elif statement. * Django 1.7: Model.objects is manually patched inside PyDev to give proper code-completion results. * Debugger: hovering over private ('__' prefixed) variables now shows proper value. * Thread.isAlive() is no longer called to workaround debugger issue on Python 3.4. * Hyperlinking should not happen on spacing characters (I.e.: Ctrl+click on spaces). * Fixed NPE when interpreter is created with JDT and loaded afterwards without it. * Fixed issue where tokens cached information could end up being null after I/O. * Manually creating new run configuration no longer gives an exception (i.e.: configuration without associated project). * Out-of-sync error on PYTHONPATH change (patch by Danny Yoo) * There's an extension point for clients to resolve modules (patch by Danny Yoo). * **Ctrl+Shift+G** (find references) is now properly categorized. * Rename refactoring now validates files (read only) prior to refactoring (patch by Danny Yoo). * Not checking preferred settings when the PyDev plugin is started, but rather when a PyDev editor is opened. * Setting remote debugger socket to be properly reused. * The PyDev stdout/stderr redirector now properly uses PYTHONIOENCODING. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer LiClipse http://brainwy.github.io/liclipse PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent.vandevyvre at swing.be Tue May 20 15:11:21 2014 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Tue, 20 May 2014 21:11:21 +0200 Subject: Putting Py 3.4.1 to work. In-Reply-To: References: <537B98BD.80808@swing.be> Message-ID: <537BA8D9.9030302@swing.be> Le 20/05/2014 20:12, Chris Angelico a ?crit : > On Wed, May 21, 2014 at 4:02 AM, Vincent Vande Vyvre > wrote: >> from pyside import QtCore, QtGui > Is it pyside or PySide? There seems to be some inconsistency here. > > ChrisA Yes PySide, off course. Sorry. -- Vincent V.V. Oqapy . Qarte . PaQager From wxjmfauth at gmail.com Tue May 20 15:26:37 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 20 May 2014 12:26:37 -0700 (PDT) Subject: Putting Py 3.4.1 to work. In-Reply-To: References: <537B98BD.80808@swing.be> Message-ID: <1095b264-de18-429f-b796-67c2a38a62b3@googlegroups.com> ----- Complete (re)Fresh install Stop Python34, PySide ok Stop cx_freeze 4.3.3 for py34 seems to suffer, again, from the same desease as with cx_freeze 4.3.2, Py 3.4.0 leading to a Py crash Stop Python, PySide, cx_freeze, Windows issue? No idea Stop Have some idea about the guilty msi installer Stop. jmf From mmanns at gmx.net Tue May 20 15:45:15 2014 From: mmanns at gmx.net (Martin Manns) Date: Tue, 20 May 2014 21:45:15 +0200 Subject: Reading OpenOffice spreadsheet in Python? References: Message-ID: <20140520214515.1089e2c7@Fuddel> On Tue, 20 May 2014 11:38:06 -0500 Skip Montanaro wrote: > I am so fed up with LibreOffice's inability to properly support really > basic Excel capabilities, I'm about ready to throw my computer out the Could you please give some examples, what basic Excel capabilities you are missing? > I'm open to other options as well. I see a number of Google > spreadsheet modules, and there is pyspread. The former has the > permission issue (besides, where I work everything goes into Git), and > I'm not sure how full-featured or stable the latter is (but, will > investigate). Maybe gnumeric may be an option, too. Pyspread should run fine on the Mac. However, Macs are not officially supported because there are no testers for OSX, yet. Please note that pyspread does not translate Excel "xls" files into Python but only imports cell contents and formatting via xlrd. If you use Excel cell functions or VBA then you would have to migrate your code to Python. Martin From zachary.ware+pylist at gmail.com Tue May 20 16:55:51 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Tue, 20 May 2014 15:55:51 -0500 Subject: Putting Py 3.4.1 to work. In-Reply-To: References: Message-ID: On Tue, May 20, 2014 at 9:31 AM, wrote: > Experimented users have certainly noticed a lot of > things have changed. > > Short. I installed Py3.4.1, it overwrites c:\Python34 which > contained eg. PySide in ...\site-packages. > > So far, so good. I can launch Python, IDLE and my interactive > interpreter I wrote with tkinter via a cmd in dos, .bat, ... > > Now the questions. It seems all packages in \site-packages > are no more recognized. > What am I doing wrong? Why is "site-packages" no more > recognized, "forcing" sys.path does not seem to help. > > From my interactive interpreter: > >>>> --- > import PySide > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named 'PySide' >>>> --- > sys.path > ['D:\\jm\\jmpy\\smid\\smid50beta1', 'C:\\Windows\\system32\\python34.zip', > 'C:\\Python34\\DLLs\\DLLs', 'C:\\Python34\\DLLs\\lib', 'C:\\Python34\\DLLs', > 'C:\\Python34\\DLLs\\lib\\site-packages'] This looks like something went weird in your installation, like you installed to 'C:\Python34\DLLs' instead of 'C:\Python34'. What path does sys.executable give? The usual location for site-packages is C:\Python34\Lib\site-packages, which is not listed. -- Zach From skip at pobox.com Tue May 20 18:08:17 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 20 May 2014 17:08:17 -0500 Subject: Reading OpenOffice spreadsheet in Python? In-Reply-To: <20140520214515.1089e2c7@Fuddel> References: <20140520214515.1089e2c7@Fuddel> Message-ID: On Tue, May 20, 2014 at 2:45 PM, Martin Manns wrote: >> I am so fed up with LibreOffice's inability to properly support really >> basic Excel capabilities, I'm about ready to throw my computer out the > > Could you please give some examples, what basic Excel capabilities you > are missing? That's the problem. It's not that it's obviously missing some features. It's that the files it writes sometimes are misinterpreted by xlrd. (Maybe the problem is xlrd, but it never has a problem with actual Excel-generated XLS files.) For example, I use a formula to generate a sequence of strings in one column: "F0", "G0", "H0", ..., "Z0", "F1", "G1", ... continuing for as long as I have data in an adjoining column. If I add or delete rows, this sequence grows and shrinks. It looks fine in the spreadsheet. I rarely, if ever, change the number of rows, so the values in this column rarely, if ever, change. Still, sometimes when xlrd reads the values out of that column it finds all cells in that column contain the number 0. If I mess around with the spreadsheet in ways which are apparently unrelated to this column, I can sometimes get it to read right, sort of like hitting a jukebox to stop a record from skipping. I haven't tried changing the output format to XLSX format (isn't that a compressed XML document?), but maybe I should give that a whirl. I don't know if xlrd will read such files (at first blush, it appears not). Also, Mac isn't my primary platform. This problem occurs using the Linux version of LibreOffice as well. Sometimes I edit this spreadsheet from home though. Before I upgraded to OS X Mavericks, I still had an ancient version of Excel for Mac which worked fine (despite all the disparaging remarks I've seen over the years about that product). Once I upgraded though, that was no longer an option. Thanks for the gnumeric and pyspread suggestions. I thought gnumeric was a long dead project, but see that it's available for my Mac, so I'll try that right off. I'll also play around with pyspread and see how that does. I don't mind rewriting my couple of formulas, though I will no longer be able to rely on the Excel experts at work. :-) Skip From tjreedy at udel.edu Tue May 20 18:19:37 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 May 2014 18:19:37 -0400 Subject: Putting Py 3.4.1 to work. In-Reply-To: References: Message-ID: On 5/20/2014 4:55 PM, Zachary Ware wrote: > On Tue, May 20, 2014 at 9:31 AM, wrote: >> Experimented users have certainly noticed a lot of >> things have changed. >> >> Short. I installed Py3.4.1, it overwrites c:\Python34 which >> contained eg. PySide in ...\site-packages. I installed 3.4.1 on top of 3.4.0, Win 7, both 64-bit versions. >> contained eg. PySide in ...\site-packages. The installer is careful to only overwrite or delete files it installed. The only problem one will have is if you modify a file Python installed or add a new file where Python subsequently adds one (but that is unlikely in bug-fix releases anyway). >> So far, so good. I can launch Python, IDLE and my interactive >> interpreter I wrote with tkinter via a cmd in dos, .bat, ... >> >> Now the questions. It seems all packages in \site-packages >> are no more recognized. >> What am I doing wrong? Why is "site-packages" no more >> recognized, "forcing" sys.path does not seem to help. >> >> From my interactive interpreter: >> >>>>> --- >> import PySide >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named 'PySide' >>>>> --- >> sys.path >> ['D:\\jm\\jmpy\\smid\\smid50beta1', 'C:\\Windows\\system32\\python34.zip', >> 'C:\\Python34\\DLLs\\DLLs', 'C:\\Python34\\DLLs\\lib', 'C:\\Python34\\DLLs', >> 'C:\\Python34\\DLLs\\lib\\site-packages'] >>> sys.path ['', 'C:\\Programs\\Python34\\Lib\\idlelib', 'C:\\Windows\\system32\\python34.zip', 'C:\\Programs\\Python34\\DLLs', 'C:\\Programs\\Python34\\lib', 'C:\\Programs\\Python34', 'C:\\Users\\Terry\\AppData\\Roaming\\Python\\Python34\\site-packages', 'C:\\Programs\\Python34\\lib\\site-packages', 'F:\\Python' Delete \Programs to match what you should have. > This looks like something went weird in your installation, like you > installed to 'C:\Python34\DLLs' instead of 'C:\Python34'. I suspect you nailed it. > What path does sys.executable give? >>> sys.executable 'C:\\Programs\\Python34\\pythonw.exe' (from Idle) > The usual location for site-packages is > C:\Python34\Lib\site-packages, which is not listed. whereas the new 'C:\\Programs\\Python34\\lib\\site-packages' will be empty. -- Terry Jan Reedy From skip at pobox.com Tue May 20 18:16:29 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 20 May 2014 17:16:29 -0500 Subject: Reading OpenOffice spreadsheet in Python? In-Reply-To: References: Message-ID: On Tue, May 20, 2014 at 11:49 AM, Chris Angelico wrote: > Okay, I won't suggest Windows INI files, but I'll still suggest taking > a step back and figuring out exactly what you're trying to accomplish. > Can you separate out the real data from the formula-derived info, put > the former into a git-managed file, and the latter into something you > regenerate by script (maybe off a makefile)? Actually, I'm sympathetic to INI files. I like the simplicity. The ultimate config files are output in XML though (ugh). Somewhere along the way, I want to avoid typing repetitive information into files. Today, I use a template file, read the spreadsheet with xlrd and generate the XML cruft with Cheetah. I could retain Excel (or Open Document or pyspread or some other spreadsheet) and then export to CSV files. That would solve the issue as well. Though it would be an extra step I'd have to do manually (because I can rely on xlrd), it would still leave me with the input-to-config-file data in tabular form. I'll figure something out. Something else that occurs to me as I write this is that Excel files tend to acquire all sorts of cruft, right? Or is that just Word files? Perhaps I can make things better by copying/pasting the existing spreadsheet data into a fresh spreadsheet that hasn't been updated repeatedly? Skip From rustompmody at gmail.com Tue May 20 21:19:50 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 20 May 2014 18:19:50 -0700 (PDT) Subject: Reading OpenOffice spreadsheet in Python? In-Reply-To: References: Message-ID: <638bcc73-e627-4c25-91af-8a46e87a45b1@googlegroups.com> On Tuesday, May 20, 2014 10:08:06 PM UTC+5:30, Skip Montanaro wrote: > I don't have Windows and since upgrading my Mac to Mavericks I no > longer have Excel of any flavor. I have a few Excel spreadsheets in > which I store parameters from which I generate other config files. I > read those spreadsheets using xlrd. > I am so fed up with LibreOffice's inability to properly support really > basic Excel capabilities, I'm about ready to throw my computer out the > window. So, I'm looking for alternatives. Before someone suggests > config parser/Windows INI files... A spreadsheet format is kinda handy > in this case because I do use a few formulas to define some of the > parameters. Adding a new row (new config file) or column (new > parameter) is a breeze. Are you familiar with emacs' org mode tables? http://orgmode.org/org.html#Tables From rustompmody at gmail.com Tue May 20 21:29:40 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 20 May 2014 18:29:40 -0700 (PDT) Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> Message-ID: <2122e5a9-198d-4998-bebf-3f19fe110f57@googlegroups.com> On Tuesday, May 20, 2014 9:35:10 PM UTC+5:30, Jagadeesh N. Malakannavar wrote: > Hi Satish, > > Can you please send python part in plain text format? Python code here is > > difficult to read. It would be helpful to read https://wiki.python.org/moin/GoogleGroupsPython#Posting_from_Google_Groups Note particularly the 2 standard expectations: - Dont top post - Dont use excessively long (> 70 chars) lines From skip at pobox.com Tue May 20 21:33:26 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 20 May 2014 20:33:26 -0500 Subject: Reading OpenOffice spreadsheet in Python? In-Reply-To: <638bcc73-e627-4c25-91af-8a46e87a45b1@googlegroups.com> References: <638bcc73-e627-4c25-91af-8a46e87a45b1@googlegroups.com> Message-ID: > Are you familiar with emacs' org mode tables? > http://orgmode.org/org.html#Tables No. Thanks for the pointer. S -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Wed May 21 01:52:51 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 20 May 2014 22:52:51 -0700 (PDT) Subject: Putting Py 3.4.1 to work. In-Reply-To: References: Message-ID: <8f4b849a-29bf-44b2-89a2-32ddf9cf6c5d@googlegroups.com> Le mercredi 21 mai 2014 00:19:37 UTC+2, Terry Reedy a ?crit?: > On 5/20/2014 4:55 PM, Zachary Ware wrote: > > > On Tue, May 20, 2014 at 9:31 AM, wrote: > > >> Experimented users have certainly noticed a lot of > > >> things have changed. > > >> > > > > This looks like something went weird in your installation, like you > > > installed to 'C:\Python34\DLLs' instead of 'C:\Python34'. > > > > I suspect you nailed it. > > Sorry, *I* did not install, the *msi* installer did it. I had a complete mismatch, python*.exe, in DLLs and py*.exe in c:\python34 ! Usualy, I removed then I reinstall, I did no do it this time. I'm very aware about all this stuff, all my apps are running on any wins from an usb strick, including my interactive interpreters. I have however some more serious concerns about cx_freeze, will spend some time soon. FYI: On win7, "Program Files" does no more exist. The name is a "fake" "Programs" (without any space (finally)) which carries the name of the "linguistic" win version, in my case c:\Programmes (French). jmf From dieter at handshake.de Wed May 21 02:25:00 2014 From: dieter at handshake.de (dieter) Date: Wed, 21 May 2014 08:25:00 +0200 Subject: Reading OpenOffice spreadsheet in Python? References: Message-ID: <87sio3ps1v.fsf@handshake.de> Skip Montanaro writes: > ... > That then puts me in the market for an xlrd > replacement. Is there something akin to xlrd for OpenDocument > spreadsheets? Unlike the binary "excel" format (at least for early versions), "OpenDocument" is a well documented file format (a zip file containing various XML files; processible by standard XML tools). Thus, you may get at the content via "zipfile" and Python's "xml" tools. It might be possible to create an "xlrd" replacement based on "zipfile" and the "xml" package -- but, of course, one would need to study the (complex) description for the involved XML files. In the "Plone" world, there are text extractors/html converters for "OpenDocument" which go this route. I do not know how well they work. From stefan_ml at behnel.de Wed May 21 02:33:53 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 21 May 2014 08:33:53 +0200 Subject: Loading modules from files through C++ In-Reply-To: <537B8E31.7000607@rptd.ch> References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> <53778005.8030105@rptd.ch> <53778E22.3040701@rptd.ch> <53790CCF.1070905@rptd.ch> <537B8E31.7000607@rptd.ch> Message-ID: Roland Pl?ss, 20.05.2014 19:17: > PyObject * const loadedModule = Py_InitModule3( fullname, NULL, "Loaded > module" ); > PyObject * const moduleDict = PyModule_GetDict( loadedModule ); // > borrowed reference > PyDict_SetItemString( moduleDict, "__builtins__", PyEval_GetBuiltins() ); > PyRun_StringFlags( fileContent, Py_file_input, moduleDict, moduleDict, > NULL ); > > Hopefully this works also in Py3 should I switch some time later. But I > guess it should seeing how simple the import now became. The general principle should still work, just the module creation has changed. Stefan From dieter at handshake.de Wed May 21 02:36:56 2014 From: dieter at handshake.de (dieter) Date: Wed, 21 May 2014 08:36:56 +0200 Subject: Code a web service with python/postgis References: <20140520201005.ddj5zabr8goog4kg@webmail.latitude-geosystems.com> Message-ID: <87oayrprhz.fsf@handshake.de> lcelati at latitude-geosystems.com writes: > ... > I would like code a web service with python. > ... details omitted ... Such a task has many facets. Some of them are quite general and you can find packages on "PyPI" which support them well; others are highly problem specific and you likely will need to solve them on your own. "web service" is an ambigous term: in a wide meaning, it can be any service provided via HTTP/HTTPS; however, often, it is used in a narrow way as a SOAP/WSDL service. There are several packages which help you to implement SOAP services in Python, among them "spyne" and "soapbox". This gives you the SOAP aspect (together with WSDL generation). In addition, you have the "web" aspect. There are other packages for this: among them "django", "pyramid", "twisted", ... And there are further more application dependent aspects like determining the geo location. Look at "PyPI" to find out whether there are packages that help you with those. Likely, those will not be pure Python packages but bridges to other ("C/C++") libraries. From wxjmfauth at gmail.com Wed May 21 02:36:23 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 20 May 2014 23:36:23 -0700 (PDT) Subject: Putting Py 3.4.1 to work. In-Reply-To: <8f4b849a-29bf-44b2-89a2-32ddf9cf6c5d@googlegroups.com> References: <8f4b849a-29bf-44b2-89a2-32ddf9cf6c5d@googlegroups.com> Message-ID: I really expected I worked to quickly and I did a mistake in freezing applications. But, no. cx_freeze just re-became problematic, __file__, bootstap, importlib and so on. My take on the subject. Since the introduction of this uncecessary __pycache__ mess, I'm experimenting a lot of problems (I'm not alone). It was too simple, logical, let's make complicate. Pure Python development style. jmf From ronaksoni301 at gmail.com Wed May 21 04:12:38 2014 From: ronaksoni301 at gmail.com (Ronak Dhakan) Date: Wed, 21 May 2014 01:12:38 -0700 (PDT) Subject: 'Swampy' installation through 'pip' In-Reply-To: References: Message-ID: <4ff628db-1b32-449d-9f93-37d567c4627a@googlegroups.com> After reading the suggestions... I uninstalled Python 2.7.6 from 'E:\Program Files\Python 2.7.6' & installed in 'C:\Python27'. Then I put 'get-pip.py' file in 'C:\Python27' , opened command prompt, navigated to 'C:\Python27' & ran 'python get-pip.py' and pip was installed. Then I navigated to 'C:\Python27\Scripts' in command prompt, ran 'pip install swampy' . And swampy was downloaded & installed. Yeeaaayy !!! Problem solved ! From satishmlwizpro at gmail.com Wed May 21 04:41:42 2014 From: satishmlwizpro at gmail.com (Satish ML) Date: Wed, 21 May 2014 01:41:42 -0700 (PDT) Subject: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: <2122e5a9-198d-4998-bebf-3f19fe110f57@googlegroups.com> References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> <2122e5a9-198d-4998-bebf-3f19fe110f57@googlegroups.com> Message-ID: <99a414b6-0d02-40ac-9891-e179ff296db8@googlegroups.com> On Wednesday, May 21, 2014 6:59:40 AM UTC+5:30, Rustom Mody wrote: > On Tuesday, May 20, 2014 9:35:10 PM UTC+5:30, Jagadeesh N. Malakannavar wrote: > Hi Satish, > > Can you please send python part in plain text format? Python code here is > > difficult to read. It would be helpful to read https://wiki.python.org/moin/GoogleGroupsPython#Posting_from_Google_Groups Note particularly the 2 standard expectations: - Dont top post - Dont use excessively long (> 70 chars) lines Hi, Here is the code. xls file looks as follows: a.c C:\Desktop\salingeg\src\code\a.c C:\Desktop\salingeg\dest\code hello.txt C:\Desktop\salingeg\src\txt\hello.txt C:\Desktop\salingeg\dest\txt integration.doc C:\Desktop\salingeg\src\doc\integration.doc C:\Desktop\salingeg\dest\doc UG.doc C:\Desktop\salingeg\src\doc\UG.doc C:\Desktop\salingeg\dest\doc Applications.xml C:\Desktop\salingeg\src\xml\Applications.xml C:\Desktop\salingeg\dest\xml Platforms.xml C:\Desktop\salingeg\src\xml\Platforms.xml C:\Desktop\salingeg\dest\xml avc.alias C:\Desktop\salingeg\src\cnx\alias\avc.alias C:\Desktop\salingeg\dest\cnx\alias cats.alias C:\Desktop\salingeg\src\cnx\alias\cats.alias C:\Desktop\salingeg\dest\cnx\alias avc.init C:\Desktop\salingeg\src\cnx\init\avc.init C:\Desktop\salingeg\dest\cnx\init cats.init C:\Desktop\salingeg\src\cnx\init\cats.init C:\Desktop\salingeg\dest\cnx\init PYTHON SCRIPT: import xlrd, sys, os, shutil file_location = "C:\Users\salingeg\Desktop\input.xls" workbook = xlrd.open_workbook(file_location) sheet = workbook.sheet_by_index(0) sheet.cell_value(0, 0) for row in range(sheet.nrows): source = [] source.append(sheet.cell_value(row, 1)) destination = [] destination.append(sheet.cell_value(row, 2)) files = [] files.append(sheet.cell_value(row, 0)) for f in files: for s in source: for d in destination: print f print s print d if (os.path.exists("d\\f")): print ('File exists') else: shutil.copy(s, d) I am getting the following error: a.c C:\Desktop\salingeg\src\code\a.c C:\Desktop\salingeg\dest\code Traceback (most recent call last): File "C:\Users\salingeg\Desktop\excel_1.py", line 24, in shutil.copy(s, d) File "C:\Program Files (x86)\python26\lib\shutil.py", line 84, in copy copyfile(src, dst) File "C:\Program Files (x86)\python26\lib\shutil.py", line 50, in copyfile with open(src, 'rb') as fsrc: IOError: [Errno 2] No such file or directory: u'C:\\Desktop\\salingeg\\src\\code\\a.c' From rustompmody at gmail.com Wed May 21 04:53:12 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 21 May 2014 01:53:12 -0700 (PDT) Subject: Reading OpenOffice spreadsheet in Python? In-Reply-To: References: Message-ID: <21575b32-1d21-4a9c-8a72-c8735d1630d9@googlegroups.com> On Tuesday, May 20, 2014 10:08:06 PM UTC+5:30, Skip Montanaro wrote: > I don't have Windows and since upgrading my Mac to Mavericks I no > longer have Excel of any flavor. I have a few Excel spreadsheets in > which I store parameters from which I generate other config files. I > read those spreadsheets using xlrd. > I am so fed up with LibreOffice's inability to properly support really > basic Excel capabilities, I'm about ready to throw my computer out the > window. Another possibility: Use google drive/docs spreadsheet capability. Makes much less mess than libreoffice and will export to standard formats From burak.arslan at arskom.com.tr Wed May 21 05:08:18 2014 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Wed, 21 May 2014 12:08:18 +0300 Subject: Code a web service with python/postgis In-Reply-To: <20140520201005.ddj5zabr8goog4kg@webmail.latitude-geosystems.com> References: <20140520201005.ddj5zabr8goog4kg@webmail.latitude-geosystems.com> Message-ID: <537C6D02.6080709@arskom.com.tr> On 05/20/14 21:10, lcelati at latitude-geosystems.com wrote: > Dear all, > > I would like code a web service with python. I have already imported > several vector data > (land cover) and one Digital Elevation Model (raster layer) into my > postgresql/postgis > database (server side). > > I succeed in connecting to my pg db via psycopg2. > > Client side, operators use a client application (Developed with PHP / > javascript / > openlayers). > > Objectives : Client side, once the layer would be selected,and once > the operators have > clicked on the map , they would like that usefull informations appear > on the interface > of the client application(kind of land cover, z of the DEM). > > > => Regarding my python script, i have to type a SQL query in order to > select usefull > informations of the db layers. And, of course, the information must > depend on geographic > coordinates (Latitude Y/Longitute X). > In a 2nd time, my script must produce a result(JSon type) for the > client side. Hi, Spyne supports Point, Line, Polygon and their Multi* variants. e.g.: http://spyne.io/docs/2.10/reference/model/primitive.html#spyne.model.primitive.Line This means it can validate WKT input and produce WKT output. It also includes SQLAlchemy adapters for these types. This means you don't need to use GeoAlchemy if you have Spyne. Finally, Spyne can return your data in Soap, Xml, Json, Yaml, MsgPack, html table, html microformat, etc. etc. or you can implement your protocols if you don't like the ones already provided. Spyne web site: http://spyne.io If you have further questions you can use Spyne tag in stackoverflow or http://lists.spyne.io/listinfo/people Disclaimer: I'm the author of Spyne. I already have GIS projects based on Spyne in production. Best regards, Burak From __peter__ at web.de Wed May 21 05:12:49 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 May 2014 11:12:49 +0200 Subject: Copying non-existing files, was Re: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> <2122e5a9-198d-4998-bebf-3f19fe110f57@googlegroups.com> <99a414b6-0d02-40ac-9891-e179ff296db8@googlegroups.com> Message-ID: Satish ML wrote: [Regarding subject: let's see if we can trigger a buffer overflow somewhere ;)] > On Wednesday, May 21, 2014 6:59:40 AM UTC+5:30, Rustom Mody wrote: >> On Tuesday, May 20, 2014 9:35:10 PM UTC+5:30, Jagadeesh N. Malakannavar >> wrote: > Hi Satish, > > Can you please send python part in plain text >> format? Python code here is > > difficult to read. It would be helpful to >> read >> https://wiki.python.org/moin/GoogleGroupsPython#Posting_from_Google_Groups >> Note particularly the 2 standard expectations: - Dont top post - Dont use >> excessively long (> 70 chars) lines > > Hi, > > Here is the code. > > > xls file looks as follows: > a.c C:\Desktop\salingeg\src\code\a.c C:\Desktop\salingeg\dest\code > hello.txt C:\Desktop\salingeg\src\txt\hello.txt > C:\Desktop\salingeg\dest\txt > integration.doc C:\Desktop\salingeg\src\doc\integration.doc > C:\Desktop\salingeg\dest\doc > UG.doc C:\Desktop\salingeg\src\doc\UG.doc C:\Desktop\salingeg\dest\doc > Applications.xml C:\Desktop\salingeg\src\xml\Applications.xml > C:\Desktop\salingeg\dest\xml > Platforms.xml C:\Desktop\salingeg\src\xml\Platforms.xml > C:\Desktop\salingeg\dest\xml > avc.alias C:\Desktop\salingeg\src\cnx\alias\avc.alias > C:\Desktop\salingeg\dest\cnx\alias > cats.alias C:\Desktop\salingeg\src\cnx\alias\cats.alias > C:\Desktop\salingeg\dest\cnx\alias > avc.init C:\Desktop\salingeg\src\cnx\init\avc.init > C:\Desktop\salingeg\dest\cnx\init > cats.init C:\Desktop\salingeg\src\cnx\init\cats.init > C:\Desktop\salingeg\dest\cnx\init > > > PYTHON SCRIPT: > > import xlrd, sys, os, shutil > > file_location = "C:\Users\salingeg\Desktop\input.xls" > workbook = xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > sheet.cell_value(0, 0) > for row in range(sheet.nrows): > source = [] > source.append(sheet.cell_value(row, 1)) > destination = [] > destination.append(sheet.cell_value(row, 2)) > files = [] > files.append(sheet.cell_value(row, 0)) > for f in files: > for s in source: > for d in destination: > print f > print s > print d > if (os.path.exists("d\\f")): The following line will either always be executed if you have a subdirectory "d" in your current working directory and that directory contains a file called "f" (unlikely) or never if "d\\f" doesn't exist (likely). Have a look at os.path.join() for the right way to join a directory with a filename into a path. Use the interactive interpreter to make sure you get the desired result and understand how it works before you fix your script. > print ('File exists') > else: > shutil.copy(s, d) > > I am getting the following error: > > a.c > C:\Desktop\salingeg\src\code\a.c > C:\Desktop\salingeg\dest\code > Traceback (most recent call last): > File "C:\Users\salingeg\Desktop\excel_1.py", line 24, in > shutil.copy(s, d) > File "C:\Program Files (x86)\python26\lib\shutil.py", line 84, in copy > copyfile(src, dst) > File "C:\Program Files (x86)\python26\lib\shutil.py", line 50, in > copyfile > with open(src, 'rb') as fsrc: > IOError: [Errno 2] No such file or directory: > u'C:\\Desktop\\salingeg\\src\\code\\a.c' According to the error message the file you are trying to copy doesn't exist. Have a look into the C:\Desktop\salngeg\src\code folder, and check whether a file called a.c is there. If not you have three options - add the file - remove the line from the excel file - modify the code to check if the *source* file exists From robert.kern at gmail.com Wed May 21 05:32:08 2014 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 21 May 2014 10:32:08 +0100 Subject: Python and Math In-Reply-To: <537bfa73$0$42909$c3e8da3$1920ae85@news.astraweb.com> References: <537bfa73$0$42909$c3e8da3$1920ae85@news.astraweb.com> Message-ID: On 2014-05-21 01:59, Tony the Tiger wrote: > On Sun, 18 May 2014 14:09:43 -0400, Bill Cunningham wrote: > >> linear algebra, expanding and factoring equations of all degrees. >> Geometry. > > Sounds to me like you really want something like Maple, Mathematica, or > similar. Try http://www.scilab.org/ > > Can do heaps of stuff, too. For free. And with Python! http://sagemath.org/ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From satishmlwizpro at gmail.com Wed May 21 05:34:36 2014 From: satishmlwizpro at gmail.com (Satish ML) Date: Wed, 21 May 2014 02:34:36 -0700 (PDT) Subject: Copying non-existing files, was Re: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name. In-Reply-To: References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> <2122e5a9-198d-4998-bebf-3f19fe110f57@googlegroups.com> <99a414b6-0d02-40ac-9891-e179ff296db8@googlegroups.com> Message-ID: <8389c3e9-1fa5-43a5-bee5-c64fe4ee0919@googlegroups.com> On Wednesday, May 21, 2014 2:42:49 PM UTC+5:30, Peter Otten wrote: > Satish ML wrote: [Regarding subject: let's see if we can trigger a buffer overflow somewhere ;)] > On Wednesday, May 21, 2014 6:59:40 AM UTC+5:30, Rustom Mody wrote: >> On Tuesday, May 20, 2014 9:35:10 PM UTC+5:30, Jagadeesh N. Malakannavar >> wrote: > Hi Satish, > > Can you please send python part in plain text >> format? Python code here is > > difficult to read. It would be helpful to >> read >> https://wiki.python.org/moin/GoogleGroupsPython#Posting_from_Google_Groups >> Note particularly the 2 standard expectations: - Dont top post - Dont use >> excessively long (> 70 chars) lines > > Hi, > > Here is the code. > > > xls file looks as follows: > a.c C:\Desktop\salingeg\src\code\a.c C:\Desktop\salingeg\dest\code > hello.txt C:\Desktop\salingeg\src\txt\hello.txt > C:\Desktop\salingeg\dest\txt > integration.doc C:\Desktop\salingeg\src\doc\integration.doc > C:\Desktop\salingeg\dest\doc > UG.doc C:\Desktop\salingeg\src\doc\UG.doc C:\Desktop\salingeg\dest\doc > Applications.xml C:\Desktop\salingeg\src\xml\Applications.xml > C:\Desktop\salingeg\dest\xml > Platforms.xml C:\Desktop\salingeg\src\xml\Platforms.xml > C:\Desktop\salingeg\dest\xml > avc.alias C:\Desktop\salingeg\src\cnx\alias\avc.alias > C:\Desktop\salingeg\dest\cnx\alias > cats.alias C:\Desktop\salingeg\src\cnx\alias\cats.alias > C:\Desktop\salingeg\dest\cnx\alias > avc.init C:\Desktop\salingeg\src\cnx\init\avc.init > C:\Desktop\salingeg\dest\cnx\init > cats.init C:\Desktop\salingeg\src\cnx\init\cats.init > C:\Desktop\salingeg\dest\cnx\init > > > PYTHON SCRIPT: > > import xlrd, sys, os, shutil > > file_location = "C:\Users\salingeg\Desktop\input.xls" > workbook = xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > sheet.cell_value(0, 0) > for row in range(sheet.nrows): > source = [] > source.append(sheet.cell_value(row, 1)) > destination = [] > destination.append(sheet.cell_value(row, 2)) > files = [] > files.append(sheet.cell_value(row, 0)) > for f in files: > for s in source: > for d in destination: > print f > print s > print d > if (os.path.exists("d\\f")): The following line will either always be executed if you have a subdirectory "d" in your current working directory and that directory contains a file called "f" (unlikely) or never if "d\\f" doesn't exist (likely). Have a look at os.path.join() for the right way to join a directory with a filename into a path. Use the interactive interpreter to make sure you get the desired result and understand how it works before you fix your script. > print ('File exists') > else: > shutil.copy(s, d) > > I am getting the following error: > > a.c > C:\Desktop\salingeg\src\code\a.c > C:\Desktop\salingeg\dest\code > Traceback (most recent call last): > File "C:\Users\salingeg\Desktop\excel_1.py", line 24, in > shutil.copy(s, d) > File "C:\Program Files (x86)\python26\lib\shutil.py", line 84, in copy > copyfile(src, dst) > File "C:\Program Files (x86)\python26\lib\shutil.py", line 50, in > copyfile > with open(src, 'rb') as fsrc: > IOError: [Errno 2] No such file or directory: > u'C:\\Desktop\\salingeg\\src\\code\\a.c' According to the error message the file you are trying to copy doesn't exist. Have a look into the C:\Desktop\salngeg\src\code folder, and check whether a file called a.c is there. If not you have three options - add the file - remove the line from the excel file - modify the code to check if the *source* file exists Hi, On Wednesday, May 21, 2014 2:42:49 PM UTC+5:30, Peter Otten wrote: > Satish ML wrote: [Regarding subject: let's see if we can trigger a buffer overflow somewhere ;)] > On Wednesday, May 21, 2014 6:59:40 AM UTC+5:30, Rustom Mody wrote: >> On Tuesday, May 20, 2014 9:35:10 PM UTC+5:30, Jagadeesh N. Malakannavar >> wrote: > Hi Satish, > > Can you please send python part in plain text >> format? Python code here is > > difficult to read. It would be helpful to >> read >> https://wiki.python.org/moin/GoogleGroupsPython#Posting_from_Google_Groups >> Note particularly the 2 standard expectations: - Dont top post - Dont use >> excessively long (> 70 chars) lines > > Hi, > > Here is the code. > > > xls file looks as follows: > a.c C:\Desktop\salingeg\src\code\a.c C:\Desktop\salingeg\dest\code > hello.txt C:\Desktop\salingeg\src\txt\hello.txt > C:\Desktop\salingeg\dest\txt > integration.doc C:\Desktop\salingeg\src\doc\integration.doc > C:\Desktop\salingeg\dest\doc > UG.doc C:\Desktop\salingeg\src\doc\UG.doc C:\Desktop\salingeg\dest\doc > Applications.xml C:\Desktop\salingeg\src\xml\Applications.xml > C:\Desktop\salingeg\dest\xml > Platforms.xml C:\Desktop\salingeg\src\xml\Platforms.xml > C:\Desktop\salingeg\dest\xml > avc.alias C:\Desktop\salingeg\src\cnx\alias\avc.alias > C:\Desktop\salingeg\dest\cnx\alias > cats.alias C:\Desktop\salingeg\src\cnx\alias\cats.alias > C:\Desktop\salingeg\dest\cnx\alias > avc.init C:\Desktop\salingeg\src\cnx\init\avc.init > C:\Desktop\salingeg\dest\cnx\init > cats.init C:\Desktop\salingeg\src\cnx\init\cats.init > C:\Desktop\salingeg\dest\cnx\init > > > PYTHON SCRIPT: > > import xlrd, sys, os, shutil > > file_location = "C:\Users\salingeg\Desktop\input.xls" > workbook = xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > sheet.cell_value(0, 0) > for row in range(sheet.nrows): > source = [] > source.append(sheet.cell_value(row, 1)) > destination = [] > destination.append(sheet.cell_value(row, 2)) > files = [] > files.append(sheet.cell_value(row, 0)) > for f in files: > for s in source: > for d in destination: > print f > print s > print d > if (os.path.exists("d\\f")): The following line will either always be executed if you have a subdirectory "d" in your current working directory and that directory contains a file called "f" (unlikely) or never if "d\\f" doesn't exist (likely). Have a look at os.path.join() for the right way to join a directory with a filename into a path. Use the interactive interpreter to make sure you get the desired result and understand how it works before you fix your script. > print ('File exists') > else: > shutil.copy(s, d) > > I am getting the following error: > > a.c > C:\Desktop\salingeg\src\code\a.c > C:\Desktop\salingeg\dest\code > Traceback (most recent call last): > File "C:\Users\salingeg\Desktop\excel_1.py", line 24, in > shutil.copy(s, d) > File "C:\Program Files (x86)\python26\lib\shutil.py", line 84, in copy > copyfile(src, dst) > File "C:\Program Files (x86)\python26\lib\shutil.py", line 50, in > copyfile > with open(src, 'rb') as fsrc: > IOError: [Errno 2] No such file or directory: > u'C:\\Desktop\\salingeg\\src\\code\\a.c' According to the error message the file you are trying to copy doesn't exist. Have a look into the C:\Desktop\salngeg\src\code folder, and check whether a file called a.c is there. If not you have three options - add the file - remove the line from the excel file - modify the code to check if the *source* file exists Hi, Source file exists in the directory. From robert.kern at gmail.com Wed May 21 05:34:48 2014 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 21 May 2014 10:34:48 +0100 Subject: Python and Math In-Reply-To: References: Message-ID: On 2014-05-21 01:40, Dennis Lee Bieber wrote: > On Sun, 18 May 2014 14:09:43 -0400, "Bill Cunningham" > declaimed the following: > >> linear algebra, expanding and factoring equations of all degrees. >> Geometry. >> > Without significant add-in libraries, probably not... > > "Expanding and factoring equations" -- to me -- implies /symbolic > algebra systems/. > > Python can compute results of equations, but it won't, natively, > reformulate equations. > > Linear algebra tends to turn into matrix manipulation, as I recall... > Again, not a native feature. But all easily available with well-established open source packages. Just because it's not in the standard library doesn't mean that Python isn't a suitable language for doing this stuff. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From __peter__ at web.de Wed May 21 06:15:24 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 May 2014 12:15:24 +0200 Subject: Copying non-existing files References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> <2122e5a9-198d-4998-bebf-3f19fe110f57@googlegroups.com> <99a414b6-0d02-40ac-9891-e179ff296db8@googlegroups.com> <8389c3e9-1fa5-43a5-bee5-c64fe4ee0919@googlegroups.com> Message-ID: Satish ML wrote: [You're back to turd-formatted text; please find a permanent fix for this] > C:\Desktop\salingeg\dest\code > Traceback (most recent call last): > File > "C:\Users\salingeg\Desktop\excel_1.py", line 24, in > shut > il.copy(s, d) > File "C:\Program Files (x86)\python26\lib\shutil.py", > line 84, in copy > copyfile(src, dst) > File "C:\Program Files > (x86)\python26\lib\shutil.py", line 50, in > copyfile > with open (src, > 'rb') as fsrc: > IOError: [Errno 2] No such file or directory: > > u'C:\\Desktop\\salingeg\\src\\code\\a.c' According to the error message > the file you are trying to copy doesn't exist. Have a look into the > C:\Desktop\salngeg\src\code folder, and check whether a file called a.c > is there. If not you have three options - add the file - remove the line > from the excel file - modify the code to check if the *source* file > exists > > Hi, > > Source file exists in the directory. If you are *really* sure about this (please double-check) it may be a rights issue. Then make sure the user running the script has reading rights for the file. From jamiemitchell1604 at gmail.com Wed May 21 07:59:19 2014 From: jamiemitchell1604 at gmail.com (Jamie Mitchell) Date: Wed, 21 May 2014 04:59:19 -0700 (PDT) Subject: Adding R squared value to scatter plot Message-ID: <47d85028-12c7-4e5b-b540-33a12539fbd2@googlegroups.com> I have made a plot using the following code: python2.7 import netCDF4 import matplotlib.pyplot as plt import numpy as np swh_Q0_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') hs_Q0_con_sw=swh_Q0_con_sw.variables['hs'][:] swh_Q3_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') hs_Q3_con_sw=swh_Q3_con_sw.variables['hs'][:] swh_Q4_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') hs_Q4_con_sw=swh_Q4_con_sw.variables['hs'][:] swh_Q14_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') hs_Q14_con_sw=swh_Q14_con_sw.variables['hs'][:] swh_Q16_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') hs_Q16_con_sw=swh_Q16_con_sw.variables['hs'][:] swh_Q0_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') hs_Q0_fut_sw=swh_Q0_fut_sw.variables['hs'][:] swh_Q3_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') hs_Q3_fut_sw=swh_Q3_fut_sw.variables['hs'][:] swh_Q4_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') hs_Q4_fut_sw=swh_Q4_fut_sw.variables['hs'][:] swh_Q14_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') hs_Q14_fut_sw=swh_Q14_fut_sw.variables['hs'][:] swh_Q16_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') hs_Q16_fut_sw=swh_Q16_fut_sw.variables['hs'][:] fit_Q0_sw=np.polyfit(hs_Q0_con_sw,hs_Q0_fut_sw,1) fit_fn_Q0_sw=np.poly1d(fit_Q0_sw) plt.plot(hs_Q0_con_sw,hs_Q0_fut_sw,'g.') plt.plot(hs_Q0_con_sw,fit_fn_Q0_sw(hs_Q0_con_sw),'g',label='Q0 no pert') fit_Q3_sw=np.polyfit(hs_Q3_con_sw,hs_Q3_fut_sw,1) fit_fn_Q3_sw=np.poly1d(fit_Q3_sw) plt.plot(hs_Q3_con_sw,hs_Q3_fut_sw,'b.') plt.plot(hs_Q3_con_sw,fit_fn_Q3_sw(hs_Q3_con_sw),'b',label='Q3 low sens') fit_Q4_sw=np.polyfit(hs_Q4_con_sw,hs_Q4_fut_sw,1) fit_fn_Q4_sw=np.poly1d(fit_Q4_sw) plt.plot(hs_Q4_con_sw,hs_Q4_fut_sw,'y.') plt.plot(hs_Q4_con_sw,fit_fn_Q4_sw(hs_Q4_con_sw),'y',label='Q4 low sens') fit_Q14_sw=np.polyfit(hs_Q14_con_sw,hs_Q14_fut_sw,1) fit_fn_Q14_sw=np.poly1d(fit_Q14_sw) plt.plot(hs_Q14_con_sw,hs_Q14_fut_sw,'r.') plt.plot(hs_Q14_con_sw,fit_fn_Q14_sw(hs_Q14_con_sw),'r',label='Q14 high sens') fit_Q16_sw=np.polyfit(hs_Q16_con_sw,hs_Q16_fut_sw,1) fit_fn_Q16_sw=np.poly1d(fit_Q16_sw) plt.plot(hs_Q16_con_sw,hs_Q16_fut_sw,'c.') plt.plot(hs_Q16_con_sw,fit_fn_Q16_sw(hs_Q16_con_sw),'c',label='Q16 high sens') plt.legend(loc='best') plt.xlabel('Significant Wave Height annual averages NW Scotland 1981-2010') plt.ylabel('Significant Wave Height annual averages NW Scotland 2040-2069') plt.title('Scatter plot of Significant Wave Height') plt.show() -- What I would like to do is display the R squared value next to the line of best fits that I have made. Does anyone know how to do this with matplotlib? Thanks, Jamie From jason.swails at gmail.com Wed May 21 08:30:16 2014 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 21 May 2014 08:30:16 -0400 Subject: Adding R squared value to scatter plot In-Reply-To: <47d85028-12c7-4e5b-b540-33a12539fbd2@googlegroups.com> References: <47d85028-12c7-4e5b-b540-33a12539fbd2@googlegroups.com> Message-ID: ?? On Wed, May 21, 2014 at 7:59 AM, Jamie Mitchell wrote: > I have made a plot using the following code: > > python2.7 > import netCDF4 > import matplotlib.pyplot as plt > import numpy as np > > > swh_Q0_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') > hs_Q0_con_sw=swh_Q0_con_sw.variables['hs'][:] > > swh_Q3_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') > hs_Q3_con_sw=swh_Q3_con_sw.variables['hs'][:] > > swh_Q4_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') > hs_Q4_con_sw=swh_Q4_con_sw.variables['hs'][:] > > swh_Q14_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') > hs_Q14_con_sw=swh_Q14_con_sw.variables['hs'][:] > > swh_Q16_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') > hs_Q16_con_sw=swh_Q16_con_sw.variables['hs'][:] > > swh_Q0_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') > hs_Q0_fut_sw=swh_Q0_fut_sw.variables['hs'][:] > > swh_Q3_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') > hs_Q3_fut_sw=swh_Q3_fut_sw.variables['hs'][:] > > swh_Q4_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') > hs_Q4_fut_sw=swh_Q4_fut_sw.variables['hs'][:] > > swh_Q14_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') > hs_Q14_fut_sw=swh_Q14_fut_sw.variables['hs'][:] > > swh_Q16_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') > hs_Q16_fut_sw=swh_Q16_fut_sw.variables['hs'][:] > > fit_Q0_sw=np.polyfit(hs_Q0_con_sw,hs_Q0_fut_sw,1) > fit_fn_Q0_sw=np.poly1d(fit_Q0_sw) > > plt.plot(hs_Q0_con_sw,hs_Q0_fut_sw,'g.') > plt.plot(hs_Q0_con_sw,fit_fn_Q0_sw(hs_Q0_con_sw),'g',label='Q0 no pert') > > fit_Q3_sw=np.polyfit(hs_Q3_con_sw,hs_Q3_fut_sw,1) > fit_fn_Q3_sw=np.poly1d(fit_Q3_sw) > > plt.plot(hs_Q3_con_sw,hs_Q3_fut_sw,'b.') > plt.plot(hs_Q3_con_sw,fit_fn_Q3_sw(hs_Q3_con_sw),'b',label='Q3 low sens') > > fit_Q4_sw=np.polyfit(hs_Q4_con_sw,hs_Q4_fut_sw,1) > fit_fn_Q4_sw=np.poly1d(fit_Q4_sw) > > plt.plot(hs_Q4_con_sw,hs_Q4_fut_sw,'y.') > plt.plot(hs_Q4_con_sw,fit_fn_Q4_sw(hs_Q4_con_sw),'y',label='Q4 low sens') > > fit_Q14_sw=np.polyfit(hs_Q14_con_sw,hs_Q14_fut_sw,1) > fit_fn_Q14_sw=np.poly1d(fit_Q14_sw) > > plt.plot(hs_Q14_con_sw,hs_Q14_fut_sw,'r.') > plt.plot(hs_Q14_con_sw,fit_fn_Q14_sw(hs_Q14_con_sw),'r',label='Q14 high > sens') > > fit_Q16_sw=np.polyfit(hs_Q16_con_sw,hs_Q16_fut_sw,1) > fit_fn_Q16_sw=np.poly1d(fit_Q16_sw) > > plt.plot(hs_Q16_con_sw,hs_Q16_fut_sw,'c.') > plt.plot(hs_Q16_con_sw,fit_fn_Q16_sw(hs_Q16_con_sw),'c',label='Q16 high > sens') > > plt.legend(loc='best') > plt.xlabel('Significant Wave Height annual averages NW Scotland 1981-2010') > plt.ylabel('Significant Wave Height annual averages NW Scotland 2040-2069') > plt.title('Scatter plot of Significant Wave Height') > plt.show() > > -- > > What I would like to do is display the R squared value next to the line of > best fits that I have made. > > Does anyone know how to do this with matplotlib? > ?You can add plain text or annotations with arrows using any of the API functions described here: http://matplotlib.org/1.3.1/users/text_intro.html(information specifically regarding the text call is here: http://matplotlib.org/1.3.1/api/pyplot_api.html#matplotlib.pyplot.text) You can also use LaTeX typesetting here, so you can make the text something like r'$R^2$' to display R^2 with "nice" typesetting. (I typically use raw strings for matplotlib text strings with LaTeX formulas in them since LaTeX makes extensive use of the \ character.) The onus is on you, the programmer, to determine _where_ on the plot you want the text to appear. Since you know what you are plotting, you can write a quick helper function that will compute the optimal (to you) location for the label to occur based on where things are drawn on the canvas. There is a _lot_ of flexibility here so you should be able to get your text looking exactly how (and where) you want it. Hope this helps, Jason -- Jason M. Swails BioMaPS, Rutgers University Postdoctoral Researcher -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed May 21 09:46:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 May 2014 23:46:46 +1000 Subject: All-numeric script names and import Message-ID: If I have a file called 1.py, is there a way to import it? Obviously I can't import it as itself, but in theory, it should be possible to import something from it. I can manage it with __import__ (this is Python 2.7 I'm working on, at least for the moment), but not with the statement form. # from 1 import app as application # Doesn't work with a numeric name application = __import__("1").app Is there a way to tell Python that, syntactically, this thing that looks like a number is really a name? Or am I just being dumb? (Don't hold back on that last question. "Yes" is a perfectly acceptable answer. But please explain which of the several possibilities is the way I'm being dumb. Thanks!) ChrisA From rustompmody at gmail.com Wed May 21 10:14:12 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 21 May 2014 07:14:12 -0700 (PDT) Subject: Copying non-existing files In-Reply-To: References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> <2122e5a9-198d-4998-bebf-3f19fe110f57@googlegroups.com> <99a414b6-0d02-40ac-9891-e179ff296db8@googlegroups.com> <8389c3e9-1fa5-43a5-bee5-c64fe4ee0919@googlegroups.com> Message-ID: <10443c4a-5e1c-40bc-8c18-c696f6abde8f@googlegroups.com> On Wednesday, May 21, 2014 2:11:42 PM UTC+5:30, Satish ML wrote: > import xlrd, sys, os, shutil > for f in files: > for s in source: > for d in destination: > print f > print s > print d > if (os.path.exists("d\\f")): Am I missing something very basic??? Should you be writing "d\\f" or d ++ "\\" ++ f ? On Wednesday, May 21, 2014 3:45:24 PM UTC+5:30, Peter Otten wrote: > > [You're back to turd-formatted text; please find a permanent fix for this] > Satish: Please see https://mail.python.org/pipermail/python-list/2014-May/672340.html to get an idea how your posts look to others here Then see https://mail.python.org/pipermail/python-list/2014-May/ to see how most posts look From skip at pobox.com Wed May 21 10:24:45 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 21 May 2014 09:24:45 -0500 Subject: Reading OpenOffice spreadsheet in Python? In-Reply-To: <21575b32-1d21-4a9c-8a72-c8735d1630d9@googlegroups.com> References: <21575b32-1d21-4a9c-8a72-c8735d1630d9@googlegroups.com> Message-ID: On Wed, May 21, 2014 at 3:53 AM, Rustom Mody wrote: > Another possibility: Use google drive/docs spreadsheet capability. > Makes much less mess than libreoffice and will export to standard formats Correct, though it separates my spreadsheet from the Git repository, and means anyone else at work who might work on this stuff would need to be granted access. Not insurmountable problems, but not great either. I tried Gnumeric today. The first edits caused no problems. Knock on wood... Skip From harrismh777 at gmail.com Wed May 21 10:24:30 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 21 May 2014 09:24:30 -0500 Subject: All-numeric script names and import References: Message-ID: <537CB71E.5060506@gmail.com> On 5/21/14 8:46 AM, Chris Angelico wrote: > # from 1 import app as application # Doesn't work with a numeric name > application = __import__("1").app > > Is there a way to tell Python that, syntactically, this thing that > looks like a number is really a name? Or am I just being dumb? > > (Don't hold back on that last question. "Yes" is a perfectly > acceptable answer. But please explain which of the several > possibilities is the way I'm being dumb. Thanks!) If you have a script that is self-programming (producing sequenced, numbered scripts 1.py 2.py 3.py) then why not just prefix an alpha character a1.py a2.py a3.py ? Otherwise, are you just pulling our chain? :) On the other hand, if you open IDLE and then open the 1.py module (yes, that's a dumb name) and then click run--> run module it will import and run... assuming 1.py contains some valid python code. Why must you have a numbered script? You're just pulling someone's chain, right? marcus From davea at davea.name Wed May 21 10:32:23 2014 From: davea at davea.name (Dave Angel) Date: Wed, 21 May 2014 10:32:23 -0400 (EDT) Subject: All-numeric script names and import References: Message-ID: Chris Angelico Wrote in message: > If I have a file called 1.py, is there a way to import it? Obviously I > can't import it as itself, but in theory, it should be possible to > import something from it. I can manage it with __import__ (this is > Python 2.7 I'm working on, at least for the moment), but not with the > statement form. > > # from 1 import app as application # Doesn't work with a numeric name > application = __import__("1").app > > Is there a way to tell Python that, syntactically, this thing that > looks like a number is really a name? Or am I just being dumb? > > (Don't hold back on that last question. "Yes" is a perfectly > acceptable answer. But please explain which of the several > possibilities is the way I'm being dumb. Thanks!) > I don't think there's any question of dumbhood, but the answer should be found in the formal grammar document. https://docs.python.org/2/reference/grammar.html The import statement is defined as: import_name: 'import' dotted_as_names and dotted_as_names is defined as: dotted_as_names: dotted_as_name (',' dotted_as_name)* continuing thusly: import_as_name: NAME ['as' NAME] dotted_as_name: dotted_name ['as' NAME] So it comes down to the definition of NAME, which doesn?t seem to be on that page. That's the one which has to start with underscore or letter, followed by zero or more letter, digits, ... -- DaveA From rosuav at gmail.com Wed May 21 10:40:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 May 2014 00:40:58 +1000 Subject: All-numeric script names and import In-Reply-To: <537CB71E.5060506@gmail.com> References: <537CB71E.5060506@gmail.com> Message-ID: On Thu, May 22, 2014 at 12:24 AM, Mark H Harris wrote: > On the other hand, if you open IDLE and then open the 1.py module (yes, > that's a dumb name) and then click run--> run module it will import and > run... assuming 1.py contains some valid python code. Oh, it runs fine as an application, just not importably. > Why must you have a numbered script? > > You're just pulling someone's chain, right? Heh. No, I'm actually finally getting around to rewriting something in Python. It's been called 1 for as long as it's ever existed, having made the jump from a flat file in my personal directory to a web site, and since then from MySQL to PostgreSQL, and finally now I'm getting rid of the last artefact of the old web host by ditching PHP. Yes, I wrote it in PHP because it was hosted on a server that didn't support Python, and when I moved everything onto my own server, I didn't rewrite it. But that's no excuse for changing the name now :) http://rosuav.com/1/ Now, I could of course rename the .py files while still having it at /1/ on the site, but that's cheating. :) ChrisA From rosuav at gmail.com Wed May 21 10:43:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 May 2014 00:43:39 +1000 Subject: All-numeric script names and import In-Reply-To: References: Message-ID: On Thu, May 22, 2014 at 12:32 AM, Dave Angel wrote: > I don't think there's any question of dumbhood, but the answer > should be found in the formal grammar document. Yeah, I figured it'd be an issue of the grammar. It expects 1 to mean an integer, not a name - which in most contexts is correct (you can't go "1 = 2" because 1 isn't a name). In some contexts you can force a different interpretation, so for instance you can look at attributes of an integer literal as (1).real even though 1.real is an error; but I couldn't find a way to fiddle this one. And the only way I could find to pass a string was to use __import__(). So is that the only way? Same thing would happen, I guess, if you have dots in the file name. A file called "foo.bar.py" probably can't be imported. ChrisA From rosuav at gmail.com Wed May 21 10:45:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 May 2014 00:45:10 +1000 Subject: Copying non-existing files In-Reply-To: <10443c4a-5e1c-40bc-8c18-c696f6abde8f@googlegroups.com> References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> <2122e5a9-198d-4998-bebf-3f19fe110f57@googlegroups.com> <99a414b6-0d02-40ac-9891-e179ff296db8@googlegroups.com> <8389c3e9-1fa5-43a5-bee5-c64fe4ee0919@googlegroups.com> <10443c4a-5e1c-40bc-8c18-c696f6abde8f@googlegroups.com> Message-ID: On Thu, May 22, 2014 at 12:14 AM, Rustom Mody wrote: > d ++ "\\" ++ f ITYM: d + "\\" + f or possibly: d + "/" + f ChrisA From ethan at stoneleaf.us Wed May 21 10:03:12 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 21 May 2014 07:03:12 -0700 Subject: All-numeric script names and import In-Reply-To: References: Message-ID: <537CB220.9090602@stoneleaf.us> On 05/21/2014 06:46 AM, Chris Angelico wrote: > > # from 1 import app as application # Doesn't work with a numeric name > application = __import__("1").app The statement form of import only works with valid Python identifiers. So all numeric names won't work, names with dashes won't work, etc. -- ~Ethan~ From harrismh777 at gmail.com Wed May 21 10:24:30 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 21 May 2014 09:24:30 -0500 Subject: All-numeric script names and import In-Reply-To: References: Message-ID: <537CB71E.5060506@gmail.com> On 5/21/14 8:46 AM, Chris Angelico wrote: > # from 1 import app as application # Doesn't work with a numeric name > application = __import__("1").app > > Is there a way to tell Python that, syntactically, this thing that > looks like a number is really a name? Or am I just being dumb? > > (Don't hold back on that last question. "Yes" is a perfectly > acceptable answer. But please explain which of the several > possibilities is the way I'm being dumb. Thanks!) If you have a script that is self-programming (producing sequenced, numbered scripts 1.py 2.py 3.py) then why not just prefix an alpha character a1.py a2.py a3.py ? Otherwise, are you just pulling our chain? :) On the other hand, if you open IDLE and then open the 1.py module (yes, that's a dumb name) and then click run--> run module it will import and run... assuming 1.py contains some valid python code. Why must you have a numbered script? You're just pulling someone's chain, right? marcus From bgailer at gmail.com Wed May 21 12:09:32 2014 From: bgailer at gmail.com (bob gailer) Date: Wed, 21 May 2014 12:09:32 -0400 Subject: Basic help In-Reply-To: <002d01cf74c6$af11ce00$0d356a00$@icon.co.za> References: <000001cf7437$613cedc0$23b6c940$@icon.co.za> <002d01cf74c6$af11ce00$0d356a00$@icon.co.za> Message-ID: <537CCFBC.1000304@gmail.com> On 5/21/2014 3:31 AM, Pat Fourie wrote: > > Good Day Bob, > > Many thanks for your response. ur welcome. Some guidelines: Post in plain text (rather than formatted with colors etc.) reply to the list so we all get a chance to read your responses. > > As mentioned I am new to Python, I apologise for the terminology. Yeah, it's a learning curve. Also there may be some magic done to PyWin by choice.exe / choice.py. > > The software needs to run on a TELIT modem (GM862 ? GPS). I looked that up. Now I have basic understanding. > > I am running the software under Windows 7 Professional. > > In the Python Windows IDE I use the ?F6? function to ?compile? the source code Here I am lost - my Python for Windows IDE does not have an F6 defined. I see Choice.exe and Choice.py in the Telit PythonWin Software which (I guess) configures PyWin. Where is the relevant documentation? Until we know more about these issues I can't help. The link to GM862 Documentation takes me to a page with various devices (GM862 is not there). Do you have this documentation? Will you share it with us? From ksong at lbl.gov Wed May 21 12:11:02 2014 From: ksong at lbl.gov (Kai Song) Date: Wed, 21 May 2014 11:11:02 -0500 Subject: tkinter errors out without clear message Message-ID: Dear Python community, I have been trying to make Tkinter work on my Scientific Linux 6 (SL6) system. The python version is the SL6 default Python/2.6.6, and the tkinter is also from SL6 repository, "tkinter-2.6.6-51.el6.x86_64". I was able to import _tkinter and Tkinter, and the _test() will bring up an empty window, but it will then fail without any actual error message. I think it's when it tries to create buttons. I tried to use python gdb to debug through the code, but It's hard to pin point the problem. Here is the output: [kai at localhost ~ ]$ python Python 2.6.6 (r266:84292, Nov 21 2013, 12:39:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import _tkinter >>> import Tkinter >>> Tkinter._test() Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 3757, in _test label = Label(root, text=text) File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 2466, in __init__ Widget.__init__(self, master, 'label', cnf, kw) File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 1932, in __init__ (widgetName, self._w) + extra + self._options(cnf)) _tkinter.TclError >>> I also tried to build python/2.7.5 from scratch, and this problem still there. So, I suspect it could be due to system configuration, but without actual error message, I don't know how to fix this. Did any of you come across similar issues for Tkinter? Any advice would be greatly appreciated! Thanks in advance! Kai -- Kai Song 1.510.495.2180 1 Cyclotron Rd. Berkeley, CA94720, MS-50B 3209 High Performance Computing Services (HPCS) Lawrence Berkeley National Laboratory - http://scs.lbl.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Wed May 21 12:42:58 2014 From: gandalf at shopzeus.com (=?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Wed, 21 May 2014 18:42:58 +0200 Subject: cx_freeze and temporary files - security related question Message-ID: <537CD792.5050608@shopzeus.com> I need to create an application for Windows 7 that runs from a flash drive. This program would be used to create remote backups of the pendrive. The pendrive contains sensitive data, so when I plug in the pendrive and run the program to make a backup, it should not leave any trace of operation on the windows system. The information is so sensitive that I was forbidden to use cloud storage. I was also forbidden to make backups to a local drive, or leave any trace on the host windows system. The question is this: if I create this program with Python 3.4 and cx_Freeze, then what should I expect. When the user starts the cx_freeze-d program from the flash drive, will it create temporary files on the system drive? Will it leave log files or store any permanent or temporary data on the system drive (maybe in the user's tmp folder) that can later be used to tell what drive was mounted, with what parameters the program was started etc. Thanks From tjreedy at udel.edu Wed May 21 13:19:42 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 May 2014 13:19:42 -0400 Subject: tkinter errors out without clear message In-Reply-To: References: Message-ID: On 5/21/2014 12:11 PM, Kai Song wrote: > Dear Python community, > > I have been trying to make Tkinter work on my Scientific Linux 6 (SL6) > system. The python version is the SL6 default Python/2.6.6, and the > tkinter is also from SL6 repository, "tkinter-2.6.6-51.el6.x86_64". > > I was able to import _tkinter and Tkinter, and the _test() will bring up > an empty window, but it will then fail without any actual error message. > I think it's when it tries to create buttons. I tried to use python gdb > to debug through the code, but It's hard to pin point the problem. > _tkinter.TclError Nasty. I have seen TclErrors, but with a message. Here is a simple test I just ran (from within Idle) on Win7, 2.7.6. >>> import Tkinter as tk >>> root = tk.Tk() >>> tk.Label(root, text = 'label text').pack() >>> tk.mainloop() and I see a window with label with text. tk._test() works too, with slightly more involved window. You said you tried 2.7.5. I believe 2.7.6 has some tkinter bug fixes. There is also the issue that TkVersion == 8.5 is underspecied -- there are multiple bugfix releases. The 2.7 Windows installer has been installing 8.5.2, which has some bugs, but 2.7.7 will install 8.5.13, which is much better. -- Terry Jan Reedy From tjreedy at udel.edu Wed May 21 13:29:19 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 May 2014 13:29:19 -0400 Subject: cx_freeze and temporary files - security related question In-Reply-To: <537CD792.5050608@shopzeus.com> References: <537CD792.5050608@shopzeus.com> Message-ID: On 5/21/2014 12:42 PM, Nagy L?szl? Zsolt wrote: > I need to create an application for Windows 7 that runs from a flash > drive. This program would be used to create remote backups of the > pendrive. The pendrive contains sensitive data, so when I plug in the > pendrive and run the program to make a backup, it should not leave any > trace of operation on the windows system. The information is so > sensitive that I was forbidden to use cloud storage. I was also > forbidden to make backups to a local drive, or leave any trace on the > host windows system. > > The question is this: if I create this program with Python 3.4 and > cx_Freeze, then what should I expect. I know that Python can be compiled so that it runs without being installed, as from a usb plugin. I forget the name on pypi. I know nothing whether cx_Freeze works for that. > When the user starts the > cx_freeze-d program from the flash drive, will it create temporary files > on the system drive? Will it leave log files or store any permanent or > temporary data on the system drive (maybe in the user's tmp folder) that > can later be used to tell what drive was mounted, with what parameters > the program was started etc. I am really sure that *python* does not do anything like that, but do not bet your job on my say so. I believe it can run from a read-only directory or device. I don't know what *windows* might do that I do not know about. -- Terry Jan Reedy From ksong at lbl.gov Wed May 21 14:55:22 2014 From: ksong at lbl.gov (Kai Song) Date: Wed, 21 May 2014 13:55:22 -0500 Subject: tkinter errors out without clear message In-Reply-To: References: Message-ID: Hi Terry, Thanks for your reply! > Nasty. I have seen TclErrors, but with a message. > > Here is a simple test I just ran (from within Idle) on Win7, 2.7.6. > > >>> import Tkinter as tk > >>> root = tk.Tk() > >>> tk.Label(root, text = 'label text').pack() > >>> tk.mainloop() > > and I see a window with label with text. > > tk._test() works too, with slightly more involved window. > I tried this, but it panics in the same way when running tk.Label(). Again, I can see an empty window after "root=tk.Tk()". > > You said you tried 2.7.5. I believe 2.7.6 has some tkinter bug fixes. > There is also the issue that TkVersion == 8.5 is underspecied -- there are > multiple bugfix releases. The 2.7 Windows installer has been installing > 8.5.2, which has some bugs, but 2.7.7 will install 8.5.13, which is much > better. Sure, I can try with some other combinations of python/tk versions. However, I tried on other SL6 machines, they have the same version (SL6.5), and same tests work on those systems. So, the python/2.6.6 and tk-6.5.7 should work... I can't recall how I set up these systems differently, but I am worried that there are other non-tk/python related issues... I am just curious if there are other ways to debug this other than python gdb? Thanks again for your help! Kai -- Kai Song 1.510.495.2180 1 Cyclotron Rd. Berkeley, CA94720, MS-50B 3209 High Performance Computing Services (HPCS) Lawrence Berkeley National Laboratory - http://scs.lbl.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: From ksong at lbl.gov Wed May 21 15:43:55 2014 From: ksong at lbl.gov (Kai Song) Date: Wed, 21 May 2014 14:43:55 -0500 Subject: tkinter errors out without clear message In-Reply-To: References: Message-ID: Hi Terry, I managed to find the problem! As you suggested, I installed newer version of tk/8.5.15. Then, the same test will still fail, but the error message has content now. It complains about missing font. I did some google, then fix it by installing "dejavu-sans-fonts". I laughed when I found the problem, and indeed, this small bug has bothered me for a whole day. Thanks again for your help. I would probably spend hours and days before even think about trying newer version tk. :) Best, Kai On Wed, May 21, 2014 at 1:55 PM, Kai Song wrote: > Hi Terry, > > Thanks for your reply! > > >> Nasty. I have seen TclErrors, but with a message. >> >> Here is a simple test I just ran (from within Idle) on Win7, 2.7.6. >> >> >>> import Tkinter as tk >> >>> root = tk.Tk() >> >>> tk.Label(root, text = 'label text').pack() >> >>> tk.mainloop() >> >> and I see a window with label with text. >> >> tk._test() works too, with slightly more involved window. >> > > I tried this, but it panics in the same way when running tk.Label(). > Again, I can see an empty window after "root=tk.Tk()". > > >> >> You said you tried 2.7.5. I believe 2.7.6 has some tkinter bug fixes. >> There is also the issue that TkVersion == 8.5 is underspecied -- there >> are multiple bugfix releases. The 2.7 Windows installer has been installing >> 8.5.2, which has some bugs, but 2.7.7 will install 8.5.13, which is much >> better. > > > Sure, I can try with some other combinations of python/tk versions. > However, I tried on other SL6 machines, they have the same version (SL6.5), > and same tests work on those systems. So, the python/2.6.6 and tk-6.5.7 > should work... > > I can't recall how I set up these systems differently, but I am worried > that there are other non-tk/python related issues... I am just curious if > there are other ways to debug this other than python gdb? > > Thanks again for your help! > > Kai > > > > -- > Kai Song > 1.510.495.2180 > 1 Cyclotron Rd. Berkeley, CA94720, MS-50B 3209 > High Performance Computing Services (HPCS) > Lawrence Berkeley National Laboratory - http://scs.lbl.gov > -- Kai Song 1.510.495.2180 1 Cyclotron Rd. Berkeley, CA94720, MS-50B 3209 High Performance Computing Services (HPCS) Lawrence Berkeley National Laboratory - http://scs.lbl.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: From roland at rptd.ch Wed May 21 18:09:55 2014 From: roland at rptd.ch (=?UTF-8?B?Um9sYW5kIFBsw7xzcw==?=) Date: Thu, 22 May 2014 00:09:55 +0200 Subject: Loading modules from files through C++ In-Reply-To: References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> <53778005.8030105@rptd.ch> <53778E22.3040701@rptd.ch> <53790CCF.1070905@rptd.ch> <537B8E31.7000607@rptd.ch> Message-ID: <537D2433.7080606@rptd.ch> On 05/20/2014 07:55 PM, Chris Angelico wrote: > On Wed, May 21, 2014 at 3:17 AM, Roland Pl?ss wrote: >> The important part are the last two lines. An important module is >> lacking the __builtins__ dictionary member so I had to add it. >> >> Hopefully this works also in Py3 should I switch some time later. But I >> guess it should seeing how simple the import now became. > An interesting omission, I'm a little surprised at that. But if your > switch to Py3 is a serious (or even half-serious) possibility, I > recommend tossing a quick comment against that line of code. Check to > see if you actually need it, and if you still do, see if there's a > change there. The module has been renamed (from __builtin__ to > builtins, although the global reference to it is still __builtins__), > so you may need to adjust something there, too. But mainly, see if you > can drop that line of code in Py3. That has been a huge mess. Py3 totally messes things up there. Even the most simply code doesn't work. Take this example: # CODE # PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL }; moduledef.m_name = "MyModule"; moduledef.m_doc = "MyModule"; pModule = PyModule_Create( &moduledef ); PyState_AddModule( pModule, &moduledef ); PyRun_SimpleString( "print( globals() )\n" ); PyRun_SimpleString( "import MyModule\nprint( globals() )\n" ); # CODE # yields this: {'__name__': '__main__', '__builtins__': , '__doc__': None, '__loader__': , '__package__': None} Traceback (most recent call last): File "", line 1, in ImportError: No module named 'MyModule' This worked in Py2 and in Py3 created modules are invisible breaking anything. Why is there no sane documentation providing a working example for something that elementary. Any ideas what Py3 requires that it does not write into the docs as one should do? -- Yours sincerely Pl?ss Roland Leader and Head Programmer - Game: Epsylon ( http://www.indiedb.com/games/epsylon ) - Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine , http://dragengine.rptd.ch/wiki ) - Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php ) - As well as various Blender export scripts und game tools -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 263 bytes Desc: OpenPGP digital signature URL: From chris.barker at noaa.gov Wed May 21 19:14:29 2014 From: chris.barker at noaa.gov (chris.barker at noaa.gov) Date: Wed, 21 May 2014 16:14:29 -0700 (PDT) Subject: Python and Math In-Reply-To: References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> <3f92f709-3c00-46d7-88ef-23ef5d0e6d8a@googlegroups.com> <537B42BC.3030508@timgolden.me.uk> Message-ID: <281f5806-8793-4fd2-877c-214927ddaf10@googlegroups.com> On Tuesday, May 20, 2014 5:51:27 AM UTC-7, Frank Millman wrote: > I used it to install IPython, with the following results. > > First I ran 'pip install ipython', which worked. > > Then I read the IPython docs, which gave the following command to install > > Notebook - > > 'pip install ipython[notebook]' the reason for this is that the notebook has additional dependencies beyond what "plain" ipython requires. adding the [notebook] is supposed to bring those in, but apparetnly did not. So this is either a bug, or maybe the problem is that you had already installed ipython, so when you did : 'pip install ipython[notebook]' pip looked and saw that you already had it, so did nothing -- what did it report? In this caes: 'pip install -U ipython[notebook]' might have worked: -U means upgrade even if I already have it. But I"m glad the rest of the pip installs worked, that's pretty new actually! Note that the "scipy stack" and particularly extra add-on stuff like 3-d visualization, etc, is very hard to build and install -- so a number of folks rely on "distributions" that give you all that in one pile: Enthought Canopy Continuum Anaconda are two such options. Very odd that pip being hard to figure out might send someone to MS C#: Is there really a point and clic, out of the box high level interactive computational environment that MS delivers for C# ;-) Not that we don't need the installation of packages made even easier, but really! -Chris From rustompmody at gmail.com Thu May 22 01:53:29 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 21 May 2014 22:53:29 -0700 (PDT) Subject: Copying non-existing files In-Reply-To: References: <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> <2122e5a9-198d-4998-bebf-3f19fe110f57@googlegroups.com> <99a414b6-0d02-40ac-9891-e179ff296db8@googlegroups.com> <8389c3e9-1fa5-43a5-bee5-c64fe4ee0919@googlegroups.com> <10443c4a-5e1c-40bc-8c18-c696f6abde8f@googlegroups.com> Message-ID: <6888fa58-4250-4227-a8d1-9dcceaa3bcda@googlegroups.com> On Wednesday, May 21, 2014 8:15:10 PM UTC+5:30, Chris Angelico wrote: > On Thu, May 22, 2014 at 12:14 AM, Rustom Mody wrote: > > > d ++ "\\" ++ f > > ITYM: > > d + "\\" + f > > or possibly: > > d + "/" + f Heh! I had a vague feeling it looked strange -- stack corrupted while context switching from haskell To OP: No you should use none of the above. Use join https://docs.python.org/2/library/os.path.html#os.path.join From wxjmfauth at gmail.com Thu May 22 02:52:47 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 21 May 2014 23:52:47 -0700 (PDT) Subject: Python and Math In-Reply-To: <281f5806-8793-4fd2-877c-214927ddaf10@googlegroups.com> References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> <3f92f709-3c00-46d7-88ef-23ef5d0e6d8a@googlegroups.com> <537B42BC.3030508@timgolden.me.uk> <281f5806-8793-4fd2-877c-214927ddaf10@googlegroups.com> Message-ID: <22d3270d-6138-4987-b05f-0fdb331da9e2@googlegroups.com> Le jeudi 22 mai 2014 01:14:29 UTC+2, chris.... at noaa.gov a ?crit?: > On Tuesday, May 20, 2014 5:51:27 AM UTC-7, Frank Millman wrote: > > > > > I used it to install IPython, with the following results. > > > > > > First I ran 'pip install ipython', which worked. > > > > > > Then I read the IPython docs, which gave the following command to install > > > > > > Notebook - > > > > > > 'pip install ipython[notebook]' > > > > the reason for this is that the notebook has additional dependencies beyond what "plain" ipython requires. adding the [notebook] is supposed to bring those in, but apparetnly did not. > > > > So this is either a bug, or maybe the problem is that you had already installed ipython, so when you did : > > 'pip install ipython[notebook]' > > > > pip looked and saw that you already had it, so did nothing -- what did it report? In this caes: > > > > 'pip install -U ipython[notebook]' > > > > might have worked: -U means upgrade even if I already have it. > > > > But I"m glad the rest of the pip installs worked, that's pretty new actually! > > > > Note that the "scipy stack" and particularly extra add-on stuff like 3-d visualization, etc, is very hard to build and install -- so a number of folks rely on "distributions" that give you all that in one pile: > > > > Enthought Canopy > > Continuum Anaconda > > > > are two such options. > > > > Very odd that pip being hard to figure out might send someone to MS C#: > > > > Is there really a point and clic, out of the box high level interactive computational environment that MS delivers for C# ;-) > > > > Not that we don't need the installation of packages made even easier, but really! > ========= ========= Hi Chris, do you remember me? Look at the adress wxjm... I wanted to test wxPhoenix. Unable to install it, whl...? If you do not need tester(s) (and a little bit more) put it it clearly in the wxPython front page. I just type "wx python wxphoenix download" in google. Results, first entry: Can someone tell me how to download wxPython Phoenix ... jmf PS The latest version of wxPython I tested fails due to the coding of characters, you should not be suprised, and you probably remember how many times I tried to explain it. From frank at chagford.com Thu May 22 05:04:17 2014 From: frank at chagford.com (Frank Millman) Date: Thu, 22 May 2014 11:04:17 +0200 Subject: Python and Math References: <9c2aecd7-7c4a-4d6c-b8f3-418c0005d00a@googlegroups.com> <9d14f092-4e41-4d52-8502-32ab7cbfa3ae@googlegroups.com> <9609c0b2-653d-421f-a2be-946c6e4e31b6@googlegroups.com> <53be0d6b-25fb-4c46-8768-0287d8953abd@googlegroups.com> <3f92f709-3c00-46d7-88ef-23ef5d0e6d8a@googlegroups.com> <537B42BC.3030508@timgolden.me.uk> <281f5806-8793-4fd2-877c-214927ddaf10@googlegroups.com> Message-ID: wrote in message news:281f5806-8793-4fd2-877c-214927ddaf10 at googlegroups.com... > > pip looked and saw that you already had it, so did nothing -- what did it > report? In this caes: > > 'pip install -U ipython[notebook]' > > might have worked: -U means upgrade even if I already have it. > Indeed it did - thanks for the tip. I used pip to uninstall jinja2. Afterwards, running 'ipython notebook' predictably failed. Then I ran the above command to upgrade ipython notebook. It figured out that jinja2 was missing and re-installed it. Now it works again. Very smooth. Frank From storchaka at gmail.com Thu May 22 05:17:47 2014 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 22 May 2014 12:17:47 +0300 Subject: tkinter errors out without clear message In-Reply-To: References: Message-ID: 21.05.14 20:19, Terry Reedy ???????(??): > There is also the issue that TkVersion == 8.5 is underspecied -- there > are multiple bugfix releases. root.call('info', 'patchlevel') returns more detailed info. From who2are2you at gmail.com Thu May 22 05:30:31 2014 From: who2are2you at gmail.com (who2are2you at gmail.com) Date: Thu, 22 May 2014 17:30:31 +0800 Subject: =?GB2312?B?16q3ojogaGmjrEhvdyBtdWNoIHRpbWUgY2FuIHRyYW5zaXRpb24gdG8gcHl0aG9uMw==?= Message-ID: <2014052217302905188014@gmail.com> hi, i learn python is 0.5 year, i'm so much love python, i come from non English speaking countries, Python2 coding problem has been troubling me, I started to learn the python3 now, But many libraries do not support python3, I know python3 publishing for many years. Why do so many libraries or does not support python3, Perhaps it is because of your home page, still in the striking position put python2 download link, You can speed up the elimination of python2 ? please thank you who2are2you at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben at benfinney.id.au Thu May 22 05:38:57 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 22 May 2014 19:38:57 +1000 Subject: =?utf-8?B?6L2s5Y+ROiBoae+8jEhvdw==?= much time can transition to python3 References: <2014052217302905188014@gmail.com> Message-ID: <85iooy5f0u.fsf@benfinney.id.au> "who2are2you at gmail.com" writes: > i learn python is 0.5 year, > i'm so much love python, Welcome, you have found a very good programming language. I'm glad you like it. > i come from non English speaking countries, > Python2 coding problem has been troubling me, > I started to learn the python3 now, This is good. Python 3 makes it much easier to do the right thing with writing systems worldwide. > But many libraries do not support python3, > I know python3 publishing for many years. > Why do so many libraries or does not support python3, Because Python 2 has a lot of inertia. There is a great amount of existing Python 2 code, and many other systems built on that code. Change takes time. Be glad that you are learning Python 3 now! There has been great improvement in the Python 3 landscape in recent years. > Perhaps it is because of your home page, still in the striking > position put python2 download link, You have that backward; the website reflects the current needs of the community. While the PYthon 3 transition is still going through rapid change, the safest choice is still Python 2 for *existing * uses. But for newcomers like yourself, Python 3 is now the right choice and has been for some years. Congratulations! > You can speed up the elimination of python2 ? Yes, much has already been done, and much is still being done now. But there is still more work to do, as you observed. You can help by contacting the specific projects you rely on which still do not have Python 3 support, and ask those people kindly how you can help. We all get there faster by helping each other! -- \ ?Not to be absolutely certain is, I think, one of the essential | `\ things in rationality.? ?Bertrand Russell | _o__) | Ben Finney From who2are2you at gmail.com Thu May 22 05:35:33 2014 From: who2are2you at gmail.com (lovePython999999) Date: Thu, 22 May 2014 02:35:33 -0700 (PDT) Subject: Perhaps it is because of your home page, still in the striking position put python2 download link, Message-ID: hi, i learn python is 0.5 year, i'm so much love python, i come from non English speaking countries, Python2 coding problem has been troubling me, I started to learn the python3 now, But many libraries do not support python3, I know python3 publishing for many years. Why do so many libraries or does not support python3, Perhaps it is because of your home page, still in the striking position put python2 download link, You can speed up the elimination of python2 ? please thank you From ed.cottam at gmail.com Thu May 22 06:03:34 2014 From: ed.cottam at gmail.com (ed.cottam at gmail.com) Date: Thu, 22 May 2014 03:03:34 -0700 (PDT) Subject: Can Python do this? First steps, links to resources or complete software referals appreciated. Message-ID: <4efbb539-be4f-487c-8f7e-9675990e20a5@googlegroups.com> Hi, I'm an academic and I want to find/adapt/create a script that will grab abstracts (150-250 words of text) from Google Scholar search results and sort them by relevance (e.g. keywords, keyword combinations, anything other way you can think of). Any of you guys know of a script that does this already? Preferably open source? If not, any resources you could bring to my attention? I' a complete Newb! Thanks for your help. Ed From rosuav at gmail.com Thu May 22 06:54:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 May 2014 20:54:22 +1000 Subject: Python is horribly slow compared to bash!! Message-ID: Figure some of you folks might enjoy this. Look how horrible Python performance is! http://thedailywtf.com/Articles/Best-of-Email-Brains,-Security,-Robots,-and-a-Risky-Click.aspx Actually, probably a lot of you folks already read TDWTF, but maybe some don't (yet). ChrisA From a24061 at ducksburg.com Thu May 22 07:47:31 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 22 May 2014 12:47:31 +0100 Subject: hashing strings to integers for sqlite3 keys Message-ID: I'm using Python 3.3 and the sqlite3 module in the standard library. I'm processing a lot of strings from input files (among other things, values of headers in e-mail & news messages) and suppressing duplicates using a table of seen strings in the database. It seems to me --- from past experience with other things, where testing integers for equality is faster than testing strings, as well as from reading the SQLite3 documentation about INTEGER PRIMARY KEY --- that the SELECT tests should be faster if I am looking up an INTEGER PRIMARY KEY value rather than TEXT PRIMARY KEY. Is that right? If so, what sort of hashing function should I use? The "maxint" for SQLite3 is a lot smaller than the size of even MD5 hashes. The only thing I've thought of so far is to use MD5 or SHA-something modulo the maxint value. (Security isn't an issue --- i.e., I'm not worried about someone trying to create a hash collision.) Thanks, Adam -- "It is the role of librarians to keep government running in difficult times," replied Dramoren. "Librarians are the last line of defence against chaos." (McMullen 2001) From who2are2you at gmail.com Thu May 22 08:28:27 2014 From: who2are2you at gmail.com (lovePython999999) Date: Thu, 22 May 2014 05:28:27 -0700 (PDT) Subject: =?UTF-8?B?UmU6IOi9rOWPkTogaGnvvIxIb3cgbXVjaCB0aW1lIGNhbiB0cmFuc2l0aW9uIHRvIHB5dA==?= =?UTF-8?B?aG9uMw==?= In-Reply-To: References: <2014052217302905188014@gmail.com> Message-ID: <885cd9c1-4e5d-497d-ba9a-64a0f93bcfd6@googlegroups.com> ? 2014?5?22????UTC+8??5?38?57??Ben Finney??? > " > > > > > i learn python is 0.5 year, > > > i'm so much love python, > > > > Welcome, you have found a very good programming language. I'm glad you > > like it. > > > > > i come from non English speaking countries, > > > Python2 coding problem has been troubling me, > > > I started to learn the python3 now, > > > > This is good. Python 3 makes it much easier to do the right thing with > > writing systems worldwide. > > > > > But many libraries do not support python3, > > > I know python3 publishing for many years. > > > Why do so many libraries or does not support python3, > > > > Because Python 2 has a lot of inertia. There is a great amount of > > existing Python 2 code, and many other systems built on that code. > > Change takes time. > > > > Be glad that you are learning Python 3 now! There has been great > > improvement in the Python 3 landscape in recent years. > > > > > Perhaps it is because of your home page, still in the striking > > > position put python2 download link, > > > > You have that backward; the website reflects the current needs of the > > community. While the PYthon 3 transition is still going through rapid > > change, the safest choice is still Python 2 for *existing * uses. > > > > But for newcomers like yourself, Python 3 is now the right choice and > > has been for some years. Congratulations! > > > > > You can speed up the elimination of python2 ? > > > > Yes, much has already been done, and much is still being done now. But > > there is still more work to do, as you observed. > > > > You can help by contacting the specific projects you rely on which still > > do not have Python 3 support, and ask those people kindly how you can > > help. We all get there faster by helping each other! > > > > -- > > \ ?Not to be absolutely certain is, I think, one of the essential | > > `\ things in rationality.? ?Bertrand Russell | > > _o__) | > > Ben Finney thank you so much From __peter__ at web.de Thu May 22 08:58:50 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 22 May 2014 14:58:50 +0200 Subject: hashing strings to integers for sqlite3 keys References: Message-ID: Adam Funk wrote: > I'm using Python 3.3 and the sqlite3 module in the standard library. > I'm processing a lot of strings from input files (among other things, > values of headers in e-mail & news messages) and suppressing > duplicates using a table of seen strings in the database. > > It seems to me --- from past experience with other things, where > testing integers for equality is faster than testing strings, as well > as from reading the SQLite3 documentation about INTEGER PRIMARY KEY > --- that the SELECT tests should be faster if I am looking up an > INTEGER PRIMARY KEY value rather than TEXT PRIMARY KEY. Is that > right? My gut feeling tells me that this would matter more for join operations than lookup of a value. If you plan to do joins you could use an autoinc integer as the primary key and an additional string key for lookup. > If so, what sort of hashing function should I use? The "maxint" for > SQLite3 is a lot smaller than the size of even MD5 hashes. The only > thing I've thought of so far is to use MD5 or SHA-something modulo the > maxint value. (Security isn't an issue --- i.e., I'm not worried > about someone trying to create a hash collision.) Start with the cheapest operation you can think of, md5(s) % MAXINT or even hash(s) % MAXINT # don't forget to set PYTHONHASHSEED then compare performance with just s and only if you can demonstrate a significant speedup keep the complication in your code. If you find such a speedup I'd like to see the numbers because this cries PREMATURE OPTIMIZATION... From rosuav at gmail.com Thu May 22 09:03:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 May 2014 23:03:34 +1000 Subject: hashing strings to integers for sqlite3 keys In-Reply-To: References: Message-ID: On Thu, May 22, 2014 at 9:47 PM, Adam Funk wrote: > I'm using Python 3.3 and the sqlite3 module in the standard library. > I'm processing a lot of strings from input files (among other things, > values of headers in e-mail & news messages) and suppressing > duplicates using a table of seen strings in the database. > > It seems to me --- from past experience with other things, where > testing integers for equality is faster than testing strings, as well > as from reading the SQLite3 documentation about INTEGER PRIMARY KEY > --- that the SELECT tests should be faster if I am looking up an > INTEGER PRIMARY KEY value rather than TEXT PRIMARY KEY. Is that > right? It might be faster to use an integer primary key, but the possibility of even a single collision means you can't guarantee uniqueness without a separate check. I don't know sqlite3 well enough to say, but based on what I know of PostgreSQL, it's usually best to make your schema mimic your logical structure, rather than warping it for the sake of performance. With a good indexing function, the performance of a textual PK won't be all that much worse than an integral one, and everything you do will read correctly in the code - no fiddling around with hashes and collision checks. Stick with the TEXT PRIMARY KEY and let the database do the database's job. If you're processing a really large number of strings, you might want to consider moving from sqlite3 to PostgreSQL anyway (I've used psycopg2 quite happily), as you'll get better concurrency; and that might solve your performance problem as well, as Pg plays very nicely with caches. ChrisA From python.list at tim.thechases.com Thu May 22 09:09:59 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 22 May 2014 08:09:59 -0500 Subject: hashing strings to integers for sqlite3 keys In-Reply-To: References: Message-ID: <20140522080959.0487fae5@bigbox.christie.dr> On 2014-05-22 12:47, Adam Funk wrote: > I'm using Python 3.3 and the sqlite3 module in the standard library. > I'm processing a lot of strings from input files (among other > things, values of headers in e-mail & news messages) and suppressing > duplicates using a table of seen strings in the database. > > It seems to me --- from past experience with other things, where > testing integers for equality is faster than testing strings, as > well as from reading the SQLite3 documentation about INTEGER > PRIMARY KEY --- that the SELECT tests should be faster if I am > looking up an INTEGER PRIMARY KEY value rather than TEXT PRIMARY > KEY. Is that right? If sqlite can handle the absurd length of a Python long, you *can* do it as ints: >>> from hashlib import sha1 >>> s = "Hello world" >>> h = sha1(s) >>> h.hexdigest() '7b502c3a1f48c8609ae212cdfb639dee39673f5e' >>> int(h.hexdigest(), 16) 703993777145756967576188115661016000849227759454L That's a pretty honkin' huge int for a DB key, but you can use it. And it's pretty capped on length regardless of the underlying string's length. > If so, what sort of hashing function should I use? The "maxint" for > SQLite3 is a lot smaller than the size of even MD5 hashes. The only > thing I've thought of so far is to use MD5 or SHA-something modulo > the maxint value. (Security isn't an issue --- i.e., I'm not > worried about someone trying to create a hash collision.) You could truncate that to something like >>> int(h.hexdigest()[-8:], 16) which should give you something that would result in a 32-bit number that should fit in sqlite's int. -tkc From wxjmfauth at gmail.com Thu May 22 09:43:46 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 22 May 2014 06:43:46 -0700 (PDT) Subject: Python is horribly slow compared to bash!! In-Reply-To: References: Message-ID: <8848706d-405b-482e-8fba-4470e903ba02@googlegroups.com> Le jeudi 22 mai 2014 12:54:22 UTC+2, Chris Angelico a ?crit?: > Figure some of you folks might enjoy this. Look how horrible Python > > performance is! > > > > http://thedailywtf.com/Articles/Best-of-Email-Brains,-Security,-Robots,-and-a-Risky-Click.aspx > > > > Actually, probably a lot of you folks already read TDWTF, but maybe > > some don't (yet). > > > > ChrisA ========= ========= >>> timeit.repeat("(x*1000 + y)[:-1]", setup="x = 'abc'; y = 'z'") [1.4027834829454946, 1.38714224331963, 1.3822586635296261] >>> timeit.repeat("(x*1000 + y)[:-1]", setup="x = 'abc'; y = '\u0fce'") [5.462776291480395, 5.4479432055423445, 5.447874284053398] Na, na, na, I win. But that's peanuts. I can make an application running 100 times slower just by replacing 'z' with Dutch characters. [*]. I win again. I can take the same application and replace 'z' by ..., and ... No, I do not win :-( . Python fails. [*] Unicode is fascinating, working with it is a little bit travelling. jmf From a24061 at ducksburg.com Thu May 22 09:41:17 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 22 May 2014 14:41:17 +0100 Subject: hashing strings to integers for sqlite3 keys References: Message-ID: On 2014-05-22, Peter Otten wrote: > Adam Funk wrote: > >> I'm using Python 3.3 and the sqlite3 module in the standard library. >> I'm processing a lot of strings from input files (among other things, >> values of headers in e-mail & news messages) and suppressing >> duplicates using a table of seen strings in the database. >> >> It seems to me --- from past experience with other things, where >> testing integers for equality is faster than testing strings, as well >> as from reading the SQLite3 documentation about INTEGER PRIMARY KEY >> --- that the SELECT tests should be faster if I am looking up an >> INTEGER PRIMARY KEY value rather than TEXT PRIMARY KEY. Is that >> right? > > My gut feeling tells me that this would matter more for join operations than > lookup of a value. If you plan to do joins you could use an autoinc integer > as the primary key and an additional string key for lookup. I'm not doing any join operations. I'm using sqlite3 for storing big piles of data & persistence between runs --- not really "proper relational database use". In this particular case, I'm getting header values out of messages & doing this: for this_string in these_strings: if not already_seen(this_string): process(this_string) # ignore if already seen ... > and only if you can demonstrate a significant speedup keep the complication > in your code. > > If you find such a speedup I'd like to see the numbers because this cries > PREMATURE OPTIMIZATION... On further reflection, I think I asked for that. In fact, the table I'm using only has one column for the hashes --- I wasn't going to store the strings at all in order to save disk space (maybe my mind is stuck in the 1980s). -- But the government always tries to coax well-known writers into the Establishment; it makes them feel educated. [Robert Graves] From wrw at mac.com Thu May 22 08:51:36 2014 From: wrw at mac.com (William Ray Wing) Date: Thu, 22 May 2014 08:51:36 -0400 Subject: Can Python do this? First steps, links to resources or complete software referals appreciated. In-Reply-To: <4efbb539-be4f-487c-8f7e-9675990e20a5@googlegroups.com> References: <4efbb539-be4f-487c-8f7e-9675990e20a5@googlegroups.com> Message-ID: <9EBFC54B-C4AD-4B5C-AA29-741CBF108857@mac.com> On May 22, 2014, at 6:03 AM, ed.cottam at gmail.com wrote: > Hi, I'm an academic and I want to find/adapt/create a script that will grab abstracts (150-250 words of text) from Google Scholar search results and sort them by relevance (e.g. keywords, keyword combinations, anything other way you can think of). > > Any of you guys know of a script that does this already? Preferably open source? If not, any resources you could bring to my attention? I' a complete Newb! > > Thanks for your help. > > Ed > -- > https://mail.python.org/mailman/listinfo/python-list Well, you might take a look at scholar.py, located here: http://www.icir.org/christian/scholar.html Also, there is this at stackoverflow: http://stackoverflow.com/questions/13200709/extract-google-scholar-results-using-python-or-r One of these may provide what you want, or serve as a jumping off point. -Bill From a24061 at ducksburg.com Thu May 22 09:47:34 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 22 May 2014 14:47:34 +0100 Subject: hashing strings to integers for sqlite3 keys References: Message-ID: On 2014-05-22, Chris Angelico wrote: > On Thu, May 22, 2014 at 9:47 PM, Adam Funk wrote: >> I'm using Python 3.3 and the sqlite3 module in the standard library. >> I'm processing a lot of strings from input files (among other things, >> values of headers in e-mail & news messages) and suppressing >> duplicates using a table of seen strings in the database. >> >> It seems to me --- from past experience with other things, where >> testing integers for equality is faster than testing strings, as well >> as from reading the SQLite3 documentation about INTEGER PRIMARY KEY >> --- that the SELECT tests should be faster if I am looking up an >> INTEGER PRIMARY KEY value rather than TEXT PRIMARY KEY. Is that >> right? > > It might be faster to use an integer primary key, but the possibility > of even a single collision means you can't guarantee uniqueness > without a separate check. I don't know sqlite3 well enough to say, but > based on what I know of PostgreSQL, it's usually best to make your > schema mimic your logical structure, rather than warping it for the > sake of performance. With a good indexing function, the performance of > a textual PK won't be all that much worse than an integral one, and > everything you do will read correctly in the code - no fiddling around > with hashes and collision checks. > > Stick with the TEXT PRIMARY KEY and let the database do the database's > job. If you're processing a really large number of strings, you might > want to consider moving from sqlite3 to PostgreSQL anyway (I've used > psycopg2 quite happily), as you'll get better concurrency; and that > might solve your performance problem as well, as Pg plays very nicely > with caches. Well, actually I'm thinking about doing away with checking for duplicates at this stage, since the substrings that I pick out of the deduplicated header values go into another table as the TEXT PRIMARY KEY anyway, with deduplication there. So I think this stage reeks of premature optimization. -- The history of the world is the history of a privileged few. --- Henry Miller From a24061 at ducksburg.com Thu May 22 09:54:08 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 22 May 2014 14:54:08 +0100 Subject: hashing strings to integers for sqlite3 keys References: Message-ID: <05c15bxrpj.ln2@news.ducksburg.com> On 2014-05-22, Tim Chase wrote: > On 2014-05-22 12:47, Adam Funk wrote: >> I'm using Python 3.3 and the sqlite3 module in the standard library. >> I'm processing a lot of strings from input files (among other >> things, values of headers in e-mail & news messages) and suppressing >> duplicates using a table of seen strings in the database. >> >> It seems to me --- from past experience with other things, where >> testing integers for equality is faster than testing strings, as >> well as from reading the SQLite3 documentation about INTEGER >> PRIMARY KEY --- that the SELECT tests should be faster if I am >> looking up an INTEGER PRIMARY KEY value rather than TEXT PRIMARY >> KEY. Is that right? > > If sqlite can handle the absurd length of a Python long, you *can* do > it as ints: It can't. SQLite3 INTEGER is an 8-byte signed one. https://www.sqlite.org/datatype3.html But after reading the other replies to my question, I've concluded that what I was trying to do is pointless. > >>> from hashlib import sha1 > >>> s = "Hello world" > >>> h = sha1(s) > >>> h.hexdigest() > '7b502c3a1f48c8609ae212cdfb639dee39673f5e' > >>> int(h.hexdigest(), 16) > 703993777145756967576188115661016000849227759454L That ties in with a related question I've been wondering about lately (using MD5s & SHAs for other things) --- getting a hash value (which is internally numeric, rather than string, right?) out as a hex string & then converting that to an int looks inefficient to me --- is there any better way to get an int? (I haven't seen any other way in the API.) -- A firm rule must be imposed upon our nation before it destroys itself. The United States needs some theology and geometry, some taste and decency. I suspect that we are teetering on the edge of the abyss. --- Ignatius J Reilly From rosuav at gmail.com Thu May 22 10:08:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 May 2014 00:08:43 +1000 Subject: hashing strings to integers for sqlite3 keys In-Reply-To: References: Message-ID: On Thu, May 22, 2014 at 11:41 PM, Adam Funk wrote: > On further reflection, I think I asked for that. In fact, the table > I'm using only has one column for the hashes --- I wasn't going to > store the strings at all in order to save disk space (maybe my mind is > stuck in the 1980s). That's a problem, then, because you will see hash collisions. Maybe not often, but they definitely will occur if you have enough strings (look up the birthday paradox - with a 32-bit arbitrarily selected integer (such as a good crypto hash that you then truncate to 32 bits), you have a 50% chance of a collision at just 77,000 strings). Do you have enough RAM to hold all the strings directly? Just load 'em all up into a Python set. Set operations are fast, clean, and easy. Your already_seen function becomes a simple 'in' check. These days you can get 16GB or 32GB of RAM in a PC inexpensively enough; with an average string size of 80 characters, and assuming Python 3.3+, that's about 128 bytes each - close enough, and a nice figure. 16GB divided by 128 gives 128M strings - obviously you won't get all of that, but that's your ball-park. Anything less than, say, a hundred million strings, and you can dump the lot into memory. Easy! ChrisA From rosuav at gmail.com Thu May 22 10:14:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 May 2014 00:14:10 +1000 Subject: hashing strings to integers for sqlite3 keys In-Reply-To: <05c15bxrpj.ln2@news.ducksburg.com> References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: On Thu, May 22, 2014 at 11:54 PM, Adam Funk wrote: >> >>> from hashlib import sha1 >> >>> s = "Hello world" >> >>> h = sha1(s) >> >>> h.hexdigest() >> '7b502c3a1f48c8609ae212cdfb639dee39673f5e' >> >>> int(h.hexdigest(), 16) >> 703993777145756967576188115661016000849227759454L > > That ties in with a related question I've been wondering about lately > (using MD5s & SHAs for other things) --- getting a hash value (which > is internally numeric, rather than string, right?) out as a hex string > & then converting that to an int looks inefficient to me --- is there > any better way to get an int? (I haven't seen any other way in the > API.) I don't know that there is, at least not with hashlib. You might be able to use digest() followed by the struct module, but it's no less convoluted. It's the same in several other languages' hashing functions; the result is a string, not an integer. ChrisA From wonko at 4amlunch.net Thu May 22 10:31:11 2014 From: wonko at 4amlunch.net (wonko at 4amlunch.net) Date: Thu, 22 May 2014 07:31:11 -0700 (PDT) Subject: daemon.DaemonContext In-Reply-To: References: Message-ID: I know it's 4 years later, but I'm currently battling this myself. I do exactly this and yet it doesn't appear to be keeping the filehandler open. Nothing ever gets written to logs after I daemonize! From a24061 at ducksburg.com Thu May 22 10:40:35 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 22 May 2014 15:40:35 +0100 Subject: hashing strings to integers for sqlite3 keys References: Message-ID: <3se15bx8pl.ln2@news.ducksburg.com> On 2014-05-22, Chris Angelico wrote: > On Thu, May 22, 2014 at 11:41 PM, Adam Funk wrote: >> On further reflection, I think I asked for that. In fact, the table >> I'm using only has one column for the hashes --- I wasn't going to >> store the strings at all in order to save disk space (maybe my mind is >> stuck in the 1980s). > > That's a problem, then, because you will see hash collisions. Maybe > not often, but they definitely will occur if you have enough strings > (look up the birthday paradox - with a 32-bit arbitrarily selected > integer (such as a good crypto hash that you then truncate to 32 > bits), you have a 50% chance of a collision at just 77,000 strings). Ah yes, there's a handy table for that: https://en.wikipedia.org/wiki/Birthday_attack#Mathematics > Do you have enough RAM to hold all the strings directly? Just load 'em > all up into a Python set. Set operations are fast, clean, and easy. > Your already_seen function becomes a simple 'in' check. These days you > can get 16GB or 32GB of RAM in a PC inexpensively enough; with an > average string size of 80 characters, and assuming Python 3.3+, that's > about 128 bytes each - close enough, and a nice figure. 16GB divided > by 128 gives 128M strings - obviously you won't get all of that, but > that's your ball-park. Anything less than, say, a hundred million > strings, and you can dump the lot into memory. Easy! Good point, & since (as I explained in my other post) the substrings are being deduplicated in their own table anyway it's probably not worth bothering with persistence between runs for this bit. -- Some say the world will end in fire; some say in segfaults. [XKCD 312] From alister.nospam.ware at ntlworld.com Thu May 22 10:48:19 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 22 May 2014 14:48:19 GMT Subject: hashing strings to integers for sqlite3 keys References: Message-ID: On Thu, 22 May 2014 12:47:31 +0100, Adam Funk wrote: > I'm using Python 3.3 and the sqlite3 module in the standard library. I'm > processing a lot of strings from input files (among other things, values > of headers in e-mail & news messages) and suppressing duplicates using a > table of seen strings in the database. > > It seems to me --- from past experience with other things, where testing > integers for equality is faster than testing strings, as well as from > reading the SQLite3 documentation about INTEGER PRIMARY KEY --- that the > SELECT tests should be faster if I am looking up an INTEGER PRIMARY KEY > value rather than TEXT PRIMARY KEY. Is that right? > > If so, what sort of hashing function should I use? The "maxint" for > SQLite3 is a lot smaller than the size of even MD5 hashes. The only > thing I've thought of so far is to use MD5 or SHA-something modulo the > maxint value. (Security isn't an issue --- i.e., I'm not worried about > someone trying to create a hash collision.) > > Thanks, > Adam why not just set the filed in the DB to be unique & then catch the error when you try to Wright a duplicate? let the DB engine handle the task -- Your step will soil many countries. From a24061 at ducksburg.com Thu May 22 10:47:48 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 22 May 2014 15:47:48 +0100 Subject: hashing strings to integers for sqlite3 keys References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: On 2014-05-22, Chris Angelico wrote: > On Thu, May 22, 2014 at 11:54 PM, Adam Funk wrote: >> That ties in with a related question I've been wondering about lately >> (using MD5s & SHAs for other things) --- getting a hash value (which >> is internally numeric, rather than string, right?) out as a hex string >> & then converting that to an int looks inefficient to me --- is there >> any better way to get an int? (I haven't seen any other way in the >> API.) > > I don't know that there is, at least not with hashlib. You might be > able to use digest() followed by the struct module, but it's no less > convoluted. It's the same in several other languages' hashing > functions; the result is a string, not an integer. Well, J*v* returns a byte array, so I used to do this: digester = MessageDigest.getInstance("MD5"); ... digester.reset(); byte[] digest = digester.digest(bytes); return new BigInteger(+1, digest); I dunno why language designers don't make it easy to get a single big number directly out of these things. I just had a look at the struct module's fearsome documentation & think it would present a good shoot(self, foot) opportunity. -- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? From rosuav at gmail.com Thu May 22 11:09:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 May 2014 01:09:30 +1000 Subject: hashing strings to integers for sqlite3 keys In-Reply-To: References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: On Fri, May 23, 2014 at 12:47 AM, Adam Funk wrote: >> I don't know that there is, at least not with hashlib. You might be >> able to use digest() followed by the struct module, but it's no less >> convoluted. It's the same in several other languages' hashing >> functions; the result is a string, not an integer. > > Well, J*v* returns a byte array... I counted byte arrays along with strings. Whether it's notionally a string of bytes or characters makes no difference - it's not an integer. > I dunno why language designers don't make it easy to get a single big > number directly out of these things. It's probably because these sorts of hashes are usually done on large puddles of memory, to create a smaller puddle of memory. How you interpret the resulting puddle is up to you; maybe you want to think of it as a number, maybe as a string, but really it's just a sequence of bytes. ChrisA From wonko at 4amlunch.net Thu May 22 11:26:51 2014 From: wonko at 4amlunch.net (wonko at 4amlunch.net) Date: Thu, 22 May 2014 08:26:51 -0700 (PDT) Subject: daemon.DaemonContext In-Reply-To: References: Message-ID: <7bccfd30-ef36-46b0-968b-6c274f079b9c@googlegroups.com> On Thursday, May 22, 2014 10:31:11 AM UTC-4, wo... at 4amlunch.net wrote: > I know it's 4 years later, but I'm currently battling this myself. I do exactly this and yet it doesn't appear to be keeping the filehandler open. Nothing ever gets written to logs after I daemonize! Ok, made it work, although I think this goes against the documentation as well as what's here. I changed: context = daemon.DaemonContext( # Stuff here ) context.files_preserve[fh.stream] to: context = daemon.DaemonContext( # Stuff here files_preserve[fh.stream] ) And now it works. From wonko at 4amlunch.net Thu May 22 11:28:19 2014 From: wonko at 4amlunch.net (wonko at 4amlunch.net) Date: Thu, 22 May 2014 08:28:19 -0700 (PDT) Subject: daemon.DaemonContext and logging In-Reply-To: <87iq7yk5me.fsf@benfinney.id.au> References: <105750f9-2ed1-4dc3-b23d-d64d3b433224@z10g2000prh.googlegroups.com> <87iq7yk5me.fsf@benfinney.id.au> Message-ID: <6539d794-c931-4be5-be34-8f2932e32ef5@googlegroups.com> On Saturday, April 10, 2010 11:52:41 PM UTC-4, Ben Finney wrote: > pid = daemon.pidlockfile.TimeoutPIDLockFile( > "/tmp/dizazzo-daemontest.pid", 10) Has pidlockfile been removed? (1.6) -brian From __peter__ at web.de Thu May 22 11:34:02 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 22 May 2014 17:34:02 +0200 Subject: hashing strings to integers for sqlite3 keys References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: Adam Funk wrote: > On 2014-05-22, Chris Angelico wrote: > >> On Thu, May 22, 2014 at 11:54 PM, Adam Funk wrote: > >>> That ties in with a related question I've been wondering about lately >>> (using MD5s & SHAs for other things) --- getting a hash value (which >>> is internally numeric, rather than string, right?) out as a hex string >>> & then converting that to an int looks inefficient to me --- is there >>> any better way to get an int? (I haven't seen any other way in the >>> API.) >> >> I don't know that there is, at least not with hashlib. You might be >> able to use digest() followed by the struct module, but it's no less >> convoluted. It's the same in several other languages' hashing >> functions; the result is a string, not an integer. > > Well, J*v* returns a byte array, so I used to do this: > > digester = MessageDigest.getInstance("MD5"); > ... > digester.reset(); > byte[] digest = digester.digest(bytes); > return new BigInteger(+1, digest); In Python 3 there's int.from_bytes() >>> h = hashlib.sha1(b"Hello world") >>> int.from_bytes(h.digest(), "little") 538059071683667711846616050503420899184350089339 > I dunno why language designers don't make it easy to get a single big > number directly out of these things. You hardly ever need to manipulate the numerical value of the digest. And on its way into the database it will be re-serialized anyway. > I just had a look at the struct module's fearsome documentation & > think it would present a good shoot(self, foot) opportunity. From ethan at stoneleaf.us Thu May 22 11:22:44 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 22 May 2014 08:22:44 -0700 Subject: daemon.DaemonContext In-Reply-To: References: Message-ID: <537E1644.5060702@stoneleaf.us> On 05/22/2014 07:31 AM, wonko at 4amlunch.net wrote: > I know it's 4 years later, but I'm currently battling this myself. I do exactly this and yet it doesn't appear to be keeping the filehandler open. Nothing ever gets written to logs after I daemonize! You didn't include any context (important after four years!) so what are you talking about? And did you target the correct list? -- ~Ethan~ From fomcl at yahoo.com Thu May 22 12:58:57 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Thu, 22 May 2014 09:58:57 -0700 (PDT) Subject: shebang & windows: call an extensionless git hook Message-ID: <1400777937.43633.YahooMailNeo@web163802.mail.gq1.yahoo.com> Hi, I wrote the git pre-commit hook below. It is supposed to reject commits that contain large files (e.g. accidental commits by inexperienced users, think of "git add .") Anyway, I tried this under Linux, but the target platform is Windows. As per Git design the hook name *must* be "pre-commit" (no .py extension). How will Windows know that Python should be run? And (should it be relevant): how does Windows know which Python version to invoke? I read about custom shebangs with Pylauncher. Is that my only option? (see: https://bitbucket.org/vinay.sajip/pylauncher, http://legacy.python.org/dev/peps/pep-0397/) In addition, I would really appreciate general feedback on the hook script below.? Thanks! Albert-Jan albertjan at debian ~/Desktop/test_repo $ git config --global init.templatedir ~/Desktop/git_template_dir albertjan at debian ~/Desktop/test_repo $ cd ~/Desktop/git_template_dir albertjan at debian ~/Desktop/git_template_dir $ cat hooks/pre-commit #!/usr/bin/python #-*- mode: python -*- """Git pre-commit hook: reject large files""" import sys import os import re from subprocess import Popen, PIPE def git_filesize_hook(megabytes_cutoff=5, verbose=False): ??? """Git pre-commit hook: Return error if the maximum file size in the HEAD ??? revision exceeds , succes (0) otherwise. You can bypass ??? this hook by specifying '--no-verify' as an option in 'git commit'.""" ??? if verbose: print os.getcwd() ??? cmd = "git ls-tree --full-tree -r -l HEAD" ??? git = Popen(cmd, shell=True, stdout=PIPE, cwd=os.getcwd()) ??? get_size = lambda item: int(re.split(" +", item)[3].split("\t")[0])?????????? ??? sizes = map(get_size, git.stdout.readlines()) ??? cut_off_bytes = megabytes_cutoff * 2 ** 20 ??? if max(sizes) > cut_off_bytes: ??????? return ("ERROR: your commit contains at least one file " ??????????????? "that is larger than %d bytes" % cut_off_bytes) ??? return 0 if __name__ == "__main__": ??? sys.exit(git_filesize_hook(0.000001, True)) albertjan at debian ~/Desktop/git_template_dir $ cd - /home/antonia/Desktop/test_repo albertjan at debian ~/Desktop/test_repo $ git init? ## this also fetches my own pre-commit hook from template_dir Initialized empty Git repository in /home/antonia/Desktop/test_repo/.git/ albertjan at debian ~/Desktop/test_repo $ touch foo.txt albertjan at debian ~/Desktop/test_repo $ git add foo.txt albertjan at debian ~/Desktop/test_repo $ ls -l .git/hooks total 4 -rw-r--r-- 1 albertjan albertjan 1468 May 22 14:49 pre-commit albertjan at debian ~/Desktop/test_repo $ git commit -a -m "commit"?? ##### hook does not yet work [master (root-commit) dc82f3d] commit ?0 files changed ?create mode 100644 foo.txt albertjan at debian ~/Desktop/test_repo $ chmod +x .git/hooks/pre-commit?? ###### can I avoid this in Linux? What should I do in Windows? albertjan at debian ~/Desktop/test_repo $ echo "blaah\n" >> foo.txt albertjan at debian ~/Desktop/test_repo $ git commit -a -m "commit"? ##### now the hook does its job /home/antonia/Desktop/test_repo ERROR: your commit contains at least one file that is larger than 1 bytes Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From xdegaye at gmail.com Thu May 22 06:32:28 2014 From: xdegaye at gmail.com (Xavier de Gaye) Date: Thu, 22 May 2014 12:32:28 +0200 Subject: All-numeric script names and import In-Reply-To: References: Message-ID: <537DD23C.1090301@gmail.com> On 05/21/2014 03:46 PM, Chris Angelico wrote: > If I have a file called 1.py, is there a way to import it? Obviously I > can't import it as itself, but in theory, it should be possible to > import something from it. I can manage it with __import__ (this is > Python 2.7 I'm working on, at least for the moment), but not with the > statement form. > > # from 1 import app as application # Doesn't work with a numeric name > application = __import__("1").app > > Is there a way to tell Python that, syntactically, this thing that > looks like a number is really a name? Or am I just being dumb? > > (Don't hold back on that last question. "Yes" is a perfectly > acceptable answer. But please explain which of the several > possibilities is the way I'm being dumb. Thanks!) > > ChrisA > import 1.py as module_1 on Python 2.7 (module_1 is not inserted in sys.modules): >>> import imp >>> module_1 = imp.new_module('module_1') >>> execfile('1.py', module_1.__dict__) >>> del module_1.__dict__['__builtins__'] Xavier From xdegaye at gmail.com Thu May 22 06:51:30 2014 From: xdegaye at gmail.com (Xavier de Gaye) Date: Thu, 22 May 2014 12:51:30 +0200 Subject: All-numeric script names and import In-Reply-To: <537DD23C.1090301@gmail.com> References: <537DD23C.1090301@gmail.com> Message-ID: <537DD6B2.90107@gmail.com> On 05/22/2014 12:32 PM, Xavier de Gaye wrote: > import 1.py as module_1 on Python 2.7 (module_1 is not inserted in sys.modules): > > >>> import imp > >>> module_1 = imp.new_module('module_1') > >>> execfile('1.py', module_1.__dict__) > >>> del module_1.__dict__['__builtins__'] Oups.. should not remove the builtins and should add __file__. With corrections: >>> import imp >>> module_1 = imp.new_module('module_1') >>> execfile('1.py', module_1.__dict__) >>> module_1.__file__ = '1.py' Xavier From rosuav at gmail.com Thu May 22 13:44:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 May 2014 03:44:13 +1000 Subject: All-numeric script names and import In-Reply-To: <537DD23C.1090301@gmail.com> References: <537DD23C.1090301@gmail.com> Message-ID: On Thu, May 22, 2014 at 8:32 PM, Xavier de Gaye wrote: > import 1.py as module_1 on Python 2.7 (module_1 is not inserted in > sys.modules): > >>>> import imp >>>> module_1 = imp.new_module('module_1') >>>> execfile('1.py', module_1.__dict__) >>>> del module_1.__dict__['__builtins__'] Heh, I think __import__() is simpler than that :) ChrisA From harrismh777 at gmail.com Thu May 22 14:54:40 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 22 May 2014 13:54:40 -0500 Subject: daemon.DaemonContext and logging References: <105750f9-2ed1-4dc3-b23d-d64d3b433224@z10g2000prh.googlegroups.com> <87iq7yk5me.fsf@benfinney.id.au> <6539d794-c931-4be5-be34-8f2932e32ef5@googlegroups.com> Message-ID: On 5/22/14 10:28 AM, wonko at 4amlunch.net wrote: > On Saturday, April 10, 2010 11:52:41 PM UTC-4, Ben Finney wrote: >> pid = daemon.pidlockfile.TimeoutPIDLockFile( >> "/tmp/dizazzo-daemontest.pid", 10) > > Has pidlockfile been removed? (1.6) > > -brian > "Have you released the inertial dampener?" :) From asmbansal2 at gmail.com Thu May 22 14:54:51 2014 From: asmbansal2 at gmail.com (Aseem Bansal) Date: Thu, 22 May 2014 11:54:51 -0700 (PDT) Subject: Advice for choosing correct architecture/tech for a hobby project Message-ID: <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0@googlegroups.com> I am working on a hobby project - a Bookmarker https://github.com/anshbansal/Bookmarker. Basically bookmarks like in webbrowser stored in a app. The twist is storage by categories. I have spent some time on choosing the correct tech for making this project but it seems it would be better to take some advice on this after I went through this discussion on django forums https://groups.google.com/forum/#!topic/django-users/rSqSftkl5mg. I want to be able to add bookmarks to the app through browser. I want a front-end from which I am able to browse the bookmarks. The browsing front-end should have a search option(search for category) for filtering the bookmarks. As per these requirements that I have framed so far I thought that a web framework would be a good choice and so I chose Django. The reason being the capability to add bookmarks through browser can be done easily through JavaScript. But I hit a snag today that webbrowser's won't allow client to open hyperlinks with file protocol. I have both offline and online bookmarks so that was a problem for me. Now I am at my experience's ends. I have spent 15-20 days' spare time trying to decide the technology and now this snag. Can someone advice on this? Am I using correct technology? From harrismh777 at gmail.com Thu May 22 15:17:01 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 22 May 2014 14:17:01 -0500 Subject: Python is horribly slow compared to bash!! References: Message-ID: On 5/22/14 5:54 AM, Chris Angelico wrote: > Figure some of you folks might enjoy this. Look how horrible Python > performance is! > > http://thedailywtf.com/Articles/Best-of-Email-Brains,-Security,-Robots,-and-a-Risky-Click.aspx > > From TDWTF: > Most of the interesting physics analysis code here is based > on a framework using Python scripts for setup and configuration > which then calls native analysis code, that usually is implemented in C++. This goes back to a previous discussion about about Julia (couple weeks back) and IPython. What these guys at CERN need is the dynamic duo of IPython and Julia. (its gonna be fabulous, seriously) Or, Julia by itself. The whole point of the Julia project was to bring the whole dynamic scripting, glue, lightning fast FORTRAN or C++ specialty code, into one screaming fast package that "does it all". Of course that's a pipe dream, but they are getting very close. And, if they pull off the IPython | Julia match-up thing, man, its going to change the way technical computation is handled for decades to come. Back to the TDWTF post, what a hoot. Ok, you heard it there first people, Python is dead everyone learn BASH. :-p heh marcus From gordon at panix.com Thu May 22 15:28:54 2014 From: gordon at panix.com (John Gordon) Date: Thu, 22 May 2014 19:28:54 +0000 (UTC) Subject: Advice for choosing correct architecture/tech for a hobby project References: <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0@googlegroups.com> Message-ID: In <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0 at googlegroups.com> Aseem Bansal writes: > But I hit a snag today that webbrowser's won't allow client to open > hyperlinks with file protocol. I have both offline and online bookmarks > so that was a problem for me. What do you mean by saying "webbrowser's won't allow client to open hyperlinks with file protocol"? Of course they do. My web browser works just fine with links such as this: foo.html -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From harrismh777 at gmail.com Thu May 22 15:49:22 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 22 May 2014 14:49:22 -0500 Subject: Advice for choosing correct architecture/tech for a hobby project References: <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0@googlegroups.com> Message-ID: On 5/22/14 1:54 PM, Aseem Bansal wrote: > I am working on a hobby project - a Bookmarker{snip} hi, no django is not really the correct tool-set. Django is for server-side content management, but who knows, you might come up with a great hack (I don't want to discourage you). But, a straight python trimmed down app would probably be better... what led you to django? It seems from your descriptions, which don't make sense by the way, that you are attempting to create your own 'browser' within your app (web api) and you want to use a standard browser (like firefox or chrome) to 'front-end' the apps bookmarks. So, your app needs to be able to read your browser's bookmarks file. Browsers most certainly can read http:// https:// file:// etc. (and many more). Your api may not be able to read local file:// urls, but I'm skeptical about that (most web api(s) have no trouble with file:// either). Provide some more info, somebody will help. marcus From ian.g.kelly at gmail.com Thu May 22 15:55:09 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 22 May 2014 13:55:09 -0600 Subject: Advice for choosing correct architecture/tech for a hobby project In-Reply-To: References: <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0@googlegroups.com> Message-ID: On Thu, May 22, 2014 at 1:28 PM, John Gordon wrote: > In <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0 at googlegroups.com> Aseem Bansal writes: > >> But I hit a snag today that webbrowser's won't allow client to open >> hyperlinks with file protocol. I have both offline and online bookmarks >> so that was a problem for me. > > What do you mean by saying "webbrowser's won't allow client to open > hyperlinks with file protocol"? Of course they do. > > My web browser works just fine with links such as this: > > foo.html It works if the document that contains the link is also opened from the local filesystem, but browsers will refuse to follow the link if it was served over http. From gordon at panix.com Thu May 22 16:38:13 2014 From: gordon at panix.com (John Gordon) Date: Thu, 22 May 2014 20:38:13 +0000 (UTC) Subject: Advice for choosing correct architecture/tech for a hobby project References: <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0@googlegroups.com> Message-ID: In Ian Kelly writes: > > My web browser works just fine with links such as this: > > > > foo.html > It works if the document that contains the link is also opened from > the local filesystem, but browsers will refuse to follow the link if > it was served over http. Aha! I didn't know that. Now that I think about it, I suppose it makes sense. Perhaps the OP could write a separate application for handling local files, something like: -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From ethan at stoneleaf.us Thu May 22 17:28:51 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 22 May 2014 14:28:51 -0700 Subject: Advice for choosing correct architecture/tech for a hobby project In-Reply-To: <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0@googlegroups.com> References: <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0@googlegroups.com> Message-ID: <537E6C13.4000808@stoneleaf.us> On 05/22/2014 11:54 AM, Aseem Bansal wrote: > > I am working on a hobby project - a Bookmarker https://github.com/anshbansal/Bookmarker. Take a look at delicio.us -- it seems to be a similar type of experience. -- ~Ethan~ From rustompmody at gmail.com Thu May 22 22:08:09 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 22 May 2014 19:08:09 -0700 (PDT) Subject: All-numeric script names and import In-Reply-To: References: Message-ID: <1714fbce-827f-4ba5-853c-f2f934a75466@googlegroups.com> On Wednesday, May 21, 2014 7:16:46 PM UTC+5:30, Chris Angelico wrote: > If I have a file called 1.py, is there a way to import it? Obviously I > can't import it as itself, but in theory, it should be possible to > import something from it. I can manage it with __import__ (this is > Python 2.7 I'm working on, at least for the moment), but not with the > statement form. $ cat ?.py x = 1 def foo(x): print("Hi %s!!" % x) $ python3 Python 3.3.5 (default, Mar 22 2014, 13:24:53) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import ? >>> ?.foo('Chris') Hi Chris!! >>> ?.x 1 From rosuav at gmail.com Thu May 22 23:26:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 May 2014 13:26:20 +1000 Subject: All-numeric script names and import In-Reply-To: <1714fbce-827f-4ba5-853c-f2f934a75466@googlegroups.com> References: <1714fbce-827f-4ba5-853c-f2f934a75466@googlegroups.com> Message-ID: On Fri, May 23, 2014 at 12:08 PM, Rustom Mody wrote: > $ cat ?.py > x = 1 > def foo(x): print("Hi %s!!" % x) Yeah, no thanks. I am not naming my scripts in Arabic. :) ChrisA From ian.g.kelly at gmail.com Fri May 23 03:07:55 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 23 May 2014 01:07:55 -0600 Subject: Advice for choosing correct architecture/tech for a hobby project In-Reply-To: References: <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0@googlegroups.com> Message-ID: On Thu, May 22, 2014 at 1:49 PM, Mark H Harris wrote: > On 5/22/14 1:54 PM, Aseem Bansal wrote: >> >> I am working on a hobby project - a Bookmarker{snip} > > > hi, no django is not really the correct tool-set. Django is for server-side > content management That's a common misconception. Django is a feature-rich web framework aimed at developing database-driven web apps. It's a popular choice for implementing content management systems but is not at all limited to that scope. It should be fine for the sort of app that the OP is writing, although a bit on the heavy side. From wolfgang.maier at biologie.uni-freiburg.de Fri May 23 04:58:59 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Fri, 23 May 2014 10:58:59 +0200 Subject: All-numeric script names and import In-Reply-To: References: <1714fbce-827f-4ba5-853c-f2f934a75466@googlegroups.com> Message-ID: On 23.05.2014 05:26, Chris Angelico wrote: > On Fri, May 23, 2014 at 12:08 PM, Rustom Mody wrote: >> $ cat ?.py >> x = 1 >> def foo(x): print("Hi %s!!" % x) > > Yeah, no thanks. I am not naming my scripts in Arabic. :) > Latin, you DID use Arabic numbers :) Cheers, Wolfgang From rosuav at gmail.com Fri May 23 05:02:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 May 2014 19:02:07 +1000 Subject: All-numeric script names and import In-Reply-To: References: <1714fbce-827f-4ba5-853c-f2f934a75466@googlegroups.com> Message-ID: On Fri, May 23, 2014 at 6:58 PM, Wolfgang Maier wrote: > Latin, you DID use Arabic numbers :) > I may have used an Arabic numeral, but I named my script very definitely in English. Isn't it obvious? It's read "one dot pie", which is clearly English! :) ChrisA From wolfgang.maier at biologie.uni-freiburg.de Fri May 23 05:22:36 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Fri, 23 May 2014 11:22:36 +0200 Subject: All-numeric script names and import In-Reply-To: References: <1714fbce-827f-4ba5-853c-f2f934a75466@googlegroups.com> Message-ID: On 23.05.2014 11:02, Chris Angelico wrote: > On Fri, May 23, 2014 at 6:58 PM, Wolfgang Maier > wrote: >> Latin, you DID use Arabic numbers :) >> > > I may have used an Arabic numeral, but I named my script very > definitely in English. Isn't it obvious? It's read "one dot pie", > which is clearly English! :) > I see, so what you should propose then is a change to import, so that when it can't find a module it will try to import an alternative that's pronounced the same way. Then you could simply do: import one and you're fine :) Cheers, Wolfgang From rosuav at gmail.com Fri May 23 05:28:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 May 2014 19:28:46 +1000 Subject: All-numeric script names and import In-Reply-To: References: <1714fbce-827f-4ba5-853c-f2f934a75466@googlegroups.com> Message-ID: On Fri, May 23, 2014 at 7:22 PM, Wolfgang Maier wrote: > I see, so what you should propose then is a change to import, so that when > it can't find a module it will try to import an alternative that's > pronounced the same way. Then you could simply do: > > import one > > and you're fine :) This strikes me as a very dangerous proposal. Imagine what would happen when you try to "import chip" in New Zealand and it goes out looking for "chup.py". Or the devastating results of "yes.py" and "no.py" being indistinguishable on politicians' builds of Python... ChrisA From a24061 at ducksburg.com Fri May 23 06:27:08 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Fri, 23 May 2014 11:27:08 +0100 Subject: hashing strings to integers (was: hashing strings to integers for sqlite3 keys) References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: On 2014-05-22, Peter Otten wrote: > Adam Funk wrote: >> Well, J*v* returns a byte array, so I used to do this: >> >> digester = MessageDigest.getInstance("MD5"); >> ... >> digester.reset(); >> byte[] digest = digester.digest(bytes); >> return new BigInteger(+1, digest); > > In Python 3 there's int.from_bytes() > >>>> h = hashlib.sha1(b"Hello world") >>>> int.from_bytes(h.digest(), "little") > 538059071683667711846616050503420899184350089339 Excellent, thanks for pointing that out. I've just recently started using Python 3 instead of 2, & appreciate pointers to new things like that. The only thing that really bugs me in Python 3 is that execfile has been removed (I find it useful for testing things interactively). >> I dunno why language designers don't make it easy to get a single big >> number directly out of these things. > > You hardly ever need to manipulate the numerical value of the digest. And on > its way into the database it will be re-serialized anyway. I now agree that my original plan to hash strings for the SQLite3 table was pointless, so I've changed the subject header. :-) I have had good reason to use int hashes in the past, however. I was doing some experiments with Andrei Broder's "sketches of shingles" technique for finding partial duplication between documents, & you need integers for that so you can do modulo arithmetic. I've also used hashes of strings for other things involving deduplication or fast lookups (because integer equality is faster than string equality). I guess if it's just for deduplication, though, a set of byte arrays is as good as a set of int? -- Classical Greek lent itself to the promulgation of a rich culture, indeed, to Western civilization. Computer languages bring us doorbells that chime with thirty-two tunes, alt.sex.bestiality, and Tetris clones. (Stoll 1995) From a24061 at ducksburg.com Fri May 23 06:36:01 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Fri, 23 May 2014 11:36:01 +0100 Subject: hashing strings to integers References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: On 2014-05-23, Adam Funk wrote: > On 2014-05-22, Peter Otten wrote: >> In Python 3 there's int.from_bytes() >> >>>>> h = hashlib.sha1(b"Hello world") >>>>> int.from_bytes(h.digest(), "little") >> 538059071683667711846616050503420899184350089339 > > Excellent, thanks for pointing that out. I've just recently started > using Python 3 instead of 2, & appreciate pointers to new things like > that. BTW, I just tested that & it should be "big" for consistency with the hexdigest: Python 3.3.2+ (default, Feb 28 2014, 00:52:16) [GCC 4.8.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import hashlib >>> h0 = hashlib.sha1(bytes('pants', 'UTF-8')).digest() >>> h1 = hashlib.sha1(bytes('pants', 'UTF-8')).hexdigest() >>> int.from_bytes(h0, 'big') 1315090007003469710610607131160586168131917298749 >>> int.from_bytes(h0, 'little') 352462323236431222976527983157432783788229548774 >>> int(h1, 16) 1315090007003469710610607131160586168131917298749 Thanks. -- The kid's a hot prospect. He's got a good head for merchandising, an agent who can take you downtown and one of the best urine samples I've seen in a long time. [Dead Kennedys t-shirt] From rosuav at gmail.com Fri May 23 06:59:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 May 2014 20:59:30 +1000 Subject: hashing strings to integers (was: hashing strings to integers for sqlite3 keys) In-Reply-To: References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: On Fri, May 23, 2014 at 8:27 PM, Adam Funk wrote: > I've also used hashes of strings for other things involving > deduplication or fast lookups (because integer equality is faster than > string equality). I guess if it's just for deduplication, though, a > set of byte arrays is as good as a set of int? Want a better way to do that? Use a set or dict and let Python do the hashing. It'll be every bit as fast as explicit hashing, plus you get the bonus of simplicity. ChrisA From rosuav at gmail.com Fri May 23 07:01:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 May 2014 21:01:11 +1000 Subject: hashing strings to integers In-Reply-To: References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: On Fri, May 23, 2014 at 8:36 PM, Adam Funk wrote: > BTW, I just tested that & it should be "big" for consistency with the > hexdigest: Yes, it definitely should be parsed big-endianly. ChrisA From amirouche.boubekki at gmail.com Fri May 23 08:48:10 2014 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Fri, 23 May 2014 14:48:10 +0200 Subject: SQLAlchemy - web framework ? In-Reply-To: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> References: <17149f49-bb71-4c97-9d07-d80766b93865@googlegroups.com> Message-ID: H?llo, 2014-05-13 1:34 GMT+02:00 flebber : > If I want to use SQLAlchemy as my ORM what would be the best option for a web framework? I think the best option would be Pyramid but I don't know SQLAchemy or Pyramid that much, but: - Django doesn't support SQLAlchemy as is - I don't recommend Flask, even if it has some ?good intentions? (Jinja2 >> Django Template, Web Browser Debugger) - I don't know web.py, turbogears - I only know that tornado is an async framework and *it seems to me *that Python+Async is still not mainstream - This year, I was working on non-web related stuff, so I'm not fully up to date. > It appears the general advice regarding Django is to do it the Django way and use the django ORM and change it out for SQLAlchemy. You will loose a lot of the benefits of using Django. My point of view is that removing one thing in Django (even the template system) will lead me to remove *a lot of things*... writing a new framework. Not necessarily because they are coupled, but because there is kind of a lot of stuff I dislike in Django... But I still use Django, trying to avoid land mines and working around inefficiencies... > That to me limited knowledge leaves flask, pyramid and turbogears 2. So if I wanted to not build it all myself as with flask then potentially pyramid, turbogears is the best option? Like I said, I don't recommend flask and I know nobody using turbogears for new projects. > Is this true? I have completed the TG2 intro tutorial and have built several small things with flask although I feel offput by doing anything bigger in flask. They are templates projects that help bootstrap bigger projects. But anyway, last time I checked Flask has less resources (documentation, example code, example project, coobooks, documented pratices...) > See what I have done is got my python knowledge to a fair point where I can do useful things, good knowledge of web HTML/CSS, built a few small projects in flask to get an idea for python web, completed django tutorials, turogears tutorials and now looking to design out a bigger project I want to set myself and i am trying to compile the parts so I can see what I will need to use and gather info to cover what othe things I will need to know. The thing that, again, goes in the direction of choosing Django, is that it's a big noosphere == lot of ressources of different kind code, video, articles, books == lot of people from different background and interests == lot of ideas. Getting to learn things is easier in this conditions. If you choose another framework, you will invest extra time while referring to documentation written for Django. Since you seem to be starting Python, it will be easier to avoid this extra step of translation. Even if ?translation? is a very common pratice of programming, so working on that skill is interesting. > Do I have a false fear of flask and doing bigger projects? Many people claim they use Flask on big projects, but AFAIK there is no big open source projects written with Flask. So you can't be sure about what it means to use Flask in big project anyway. Mozilla use extensively Django, checkout mozilla at github . > So at this point I know I want SQLAlchemy, will use postgres(although mysql/maria would work fine). SQLAlchemy is better than Django's equivalent. Like said I don't fully know SQLAlchemy. But the SQL language mapping in Python is nicer in SQLAlchemy. The project is dedicated to supporting RDBMS so there is better support, tooling, I think. Some people will say it's a matter of taste, look'n'feel and compare it to "ice cream flavors". IMO it's not comparable to "ice cream flavor" but different people have different needs, background and context so favor one library instead of another without strong engineering or scientific grounds. Money, business, HR & marketing will have more significance. flebber writes: > > > One of the main parts that is tripping myself up is that I need to > > consistently import xml files into my database. > > XML documents represent a hierarchical tree of data. Relational > databases are not good at representing hierarchical documents. > - It's not always hierarchical data. - RDBMS can handle hierarchical data anyway especially PostgresSQL When I was at Lib?ration (a french national newspaper, kind of the french Guardian). We ported the previous CMS based on a custom PHP framework to Django. Basically there was 3 parts: - Frontend: main website, mainly for reading digital articles or articles from paper version. There is several frontends for the same backend. - Backend: forms and whatnot for journalist to manage the content of the website - Automatic processing: this needs little human interventions but are still fully part of the CMS The CMS import stuff, many kind among which articles bundled in XML. A "django application", a python package integrated with django that creates a mini-framework for implementing "import rules" called django-swallow . This can do simple thing like: an XML file -> Python class -> a RDBMS row. Or more complex stuff like: - blacklist or whitelist input documents - create several Python class (model instances) - update row if it already exists And probably other stuffs, I think it is kind of documented. It's not perfect, but was good enough to be put into production. For instance, the online readercontent was fully imported by a django-swallow based modules. It was the most complex import. It's fully integrated (search & co). It was the main objective of django-swallow: make it easy to import paper version of the newspaper with minimal human needed to mess around ;) One thing it was missing, is integration with Django forms for input and "output" (before saving in the database) validation. It has a sibling package: django-carrier-pigeonwhich is dedicated to create "export rules". I don't know if those are the best apps today, but when they were created, nothing matched. See https://www.djangopackages.com/search/?q=import I discovered recently in a PHP project a RDBMS tree structure for menus, I can recall the name right now. Basically, even if RDBMS is not good at trees. You make it good at the particular query that requires performance by duplicating informations... for instance a hierarchical menu is seldom updated, but quiet often queried, so make it easy to query and but slow to update... I can't help talking about graph databases, check them out if you have time :) > Any pratical advice warmly welcomed, I think I am thining too much aimlessly maybe. Like I said, previously IMO Django is less than perfect. There is hope, I read on the ML that Django 2 is coming ;) (with no ETA of course). Anyway, especially for beginners it's the obvious choice. And I think that if you are a newbie, it's always better to go for the obvious *first*. At my new company, we are aiming to move to Python. I'm not confident pushing something else than Django. Not only because it means "extra" work, but also, even if I hate it, because of marketing... (free) links regarding Django in particular: - https://www.djangopackages.com/ - http://lincolnloop.com/django-best-practices/ - http://roundup.lincolnloop.com/ - http://pyvideo.org/search?models=videos.video&q=Django Happy python-ing! -------------- next part -------------- An HTML attachment was scrubbed... URL: From fomcl at yahoo.com Fri May 23 09:53:43 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Fri, 23 May 2014 06:53:43 -0700 (PDT) Subject: shebang & windows: call an extensionless git hook In-Reply-To: <1400777937.43633.YahooMailNeo@web163802.mail.gq1.yahoo.com> References: <1400777937.43633.YahooMailNeo@web163802.mail.gq1.yahoo.com> Message-ID: <1400853223.2019.YahooMailNeo@web163806.mail.gq1.yahoo.com> ----- Original Message ----- > From: Albert-Jan Roskam > To: Python > Cc: > Sent: Thursday, May 22, 2014 6:58 PM > Subject: shebang & windows: call an extensionless git hook > > Hi, > > I wrote the git pre-commit hook below. It is supposed to reject commits that > contain large files (e.g. accidental commits by inexperienced users, think of > "git add .") > > > Anyway, I tried this under Linux, but the target platform is Windows. As per Git > design the hook name *must* be "pre-commit" (no .py extension). How > will Windows know that Python should be run? And (should it be relevant): how > does Windows know which Python version to invoke? I read about custom shebangs > with Pylauncher. Is that my only option? (see: > https://bitbucket.org/vinay.sajip/pylauncher, > http://legacy.python.org/dev/peps/pep-0397/) Ok, I just found out that the script works as-is under Windows (I need to save it as 'pre-commit', not as 'pre-commit.py'. That's great, though I still don't understand how Windows (or Git) knows how to do with it. And under Windows chmod +x does not exist, which means the hook is always ready to be used. This is exactly what I want in this case, but in general this poses a security risk ? regards, Albert-Jan From rosuav at gmail.com Fri May 23 10:01:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 24 May 2014 00:01:38 +1000 Subject: shebang & windows: call an extensionless git hook In-Reply-To: <1400853223.2019.YahooMailNeo@web163806.mail.gq1.yahoo.com> References: <1400777937.43633.YahooMailNeo@web163802.mail.gq1.yahoo.com> <1400853223.2019.YahooMailNeo@web163806.mail.gq1.yahoo.com> Message-ID: On Fri, May 23, 2014 at 11:53 PM, Albert-Jan Roskam wrote: > Ok, I just found out that the script works as-is under Windows (I need to save it as 'pre-commit', not as 'pre-commit.py'. That's great, though I still don't understand how Windows (or Git) knows how to do with it. > Are you running git from inside bash? If so, it's probably parsing the shebang and simulating a Unixesque environment, as part of the whole "let's try to make Unix stuff mostly work" policy. I'm amazed at how well it actually works; from drive letters to execution differences, everything's somehow finagled into operation. ChrisA From ronaksoni301 at gmail.com Fri May 23 10:56:02 2014 From: ronaksoni301 at gmail.com (Ronak Dhakan) Date: Fri, 23 May 2014 07:56:02 -0700 (PDT) Subject: Windows automatic rebooting due to faulty code Message-ID: I am learning python, and sometimes when I run a file with a faulty, windows gives a message that the system is rebooting and gives me 1 minute to save my work. Does anyone know how can I fix this? Most of the time a faulty code gives errors in python, but this is unique. I create files like Exercise 1.2.py and run it through IDLE. From rosuav at gmail.com Fri May 23 11:04:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 24 May 2014 01:04:31 +1000 Subject: Windows automatic rebooting due to faulty code In-Reply-To: References: Message-ID: On Sat, May 24, 2014 at 12:56 AM, Ronak Dhakan wrote: > I am learning python, and sometimes when I run a file with a faulty, windows gives a message that the system is rebooting and gives me 1 minute to save my work. Does anyone know how can I fix this? Most of the time a faulty code gives errors in python, but this is unique. I create files like Exercise 1.2.py and run it through IDLE. > I'm very much surprised that any Python coding error could do this. What code triggers this? Is it consistent? More likely it's something else in your system. Pure coincidence. ChrisA From ronaksoni301 at gmail.com Fri May 23 11:00:10 2014 From: ronaksoni301 at gmail.com (Ronak Dhakan) Date: Fri, 23 May 2014 08:00:10 -0700 (PDT) Subject: Windows rebooting due to faulty code Message-ID: <41e58dfd-b9c1-41b1-b849-ddc5ee8a978e@googlegroups.com> I am learning python, and sometimes when I run a file with a faulty code, windows gives a message that the system is rebooting and gives me 1 minute to save my work. Does anyone know how can I fix this? Most of the time a faulty code gives errors in python, but this is unique. I create files like Exercise 1.2.py and run it through IDLE. From fomcl at yahoo.com Fri May 23 11:09:33 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Fri, 23 May 2014 08:09:33 -0700 (PDT) Subject: shebang & windows: call an extensionless git hook In-Reply-To: References: <1400777937.43633.YahooMailNeo@web163802.mail.gq1.yahoo.com> <1400853223.2019.YahooMailNeo@web163806.mail.gq1.yahoo.com> Message-ID: <1400857773.79621.YahooMailNeo@web163804.mail.gq1.yahoo.com> ----- Original Message ----- > From: Chris Angelico > To: > Cc: Python > Sent: Friday, May 23, 2014 4:01 PM > Subject: Re: shebang & windows: call an extensionless git hook > > On Fri, May 23, 2014 at 11:53 PM, Albert-Jan Roskam > > wrote: >> Ok, I just found out that the script works as-is under Windows (I need to > save it as 'pre-commit', not as 'pre-commit.py'. That's > great, though I still don't understand how Windows (or Git) knows how to do > with it. >> > > Are you running git from inside bash? If so, it's probably parsing the > shebang and simulating a Unixesque environment, as part of the whole > "let's try to make Unix stuff mostly work" policy. I'm amazed > at how > well it actually works; from drive letters to execution differences, > everything's somehow finagled into operation. Hi, ? I just used cmd.exe and did some commits. And it just worked. Not sure about TortoiseGit.?(*note to self: check this next week!*) Maybe Git does something with the 'mode python' shebang (and python is on PATH).? ? regards, Albert-Jan? From ronaksoni301 at gmail.com Fri May 23 11:26:20 2014 From: ronaksoni301 at gmail.com (Ronak Dhakan) Date: Fri, 23 May 2014 08:26:20 -0700 (PDT) Subject: Windows automatic rebooting due to faulty code In-Reply-To: References: Message-ID: On Friday, May 23, 2014 8:34:31 PM UTC+5:30, Chris Angelico wrote: > On Sat, May 24, 2014 at 12:56 AM, Ronak Dhakan wrote: > > > I am learning python, and sometimes when I run a file with a faulty, windows gives a message that the system is rebooting and gives me 1 minute to save my work. Does anyone know how can I fix this? Most of the time a faulty code gives errors in python, but this is unique. I create files like Exercise 1.2.py and run it through IDLE. > > > > > > > I'm very much surprised that any Python coding error could do this. > > What code triggers this? Is it consistent? > > > > More likely it's something else in your system. Pure coincidence. > > > > ChrisA Even I am surprised, python errors should stay in python. But I am sure that the reboot is triggered exactly when I run some faulty code. And usually I change the code after reboot, so I haven't checked whether the same code is able to repeat the reboot. This happens even in simple code of 10-15 lines for drawing a polygon. There was a problem while creating the post asking the question. Here it is now: https://groups.google.com/d/msg/comp.lang.python/WINUrOfAey4/pvbnapLrRcsJ From rosuav at gmail.com Fri May 23 11:36:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 24 May 2014 01:36:32 +1000 Subject: Windows automatic rebooting due to faulty code In-Reply-To: References: Message-ID: On Sat, May 24, 2014 at 1:26 AM, Ronak Dhakan wrote: > Even I am surprised, python errors should stay in python. But I am sure that the reboot is triggered exactly when I run some faulty code. And usually I change the code after reboot, so I haven't checked whether the same code is able to repeat the reboot. This happens even in simple code of 10-15 lines for drawing a polygon. > Aim for consistency and reproducibility. Figure out something that always brings Windows down. More importantly... *tell us what modules you are using*. What draws a polygon here? What are you working with? That's kinda critical here, especially if (as I suspect) it's not part of the Python standard library. > There was a problem while creating the post asking the question. Here it is now: https://groups.google.com/d/msg/comp.lang.python/WINUrOfAey4/pvbnapLrRcsJ > Solution: Get off Google Groups. Subscribe to python-list at python.org and read it all in your email client, or read comp.lang.python in a real newsreader. That'll fix several other problems too. ChrisA From rustompmody at gmail.com Fri May 23 12:05:14 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 23 May 2014 09:05:14 -0700 (PDT) Subject: Windows automatic rebooting due to faulty code In-Reply-To: References: Message-ID: On Friday, May 23, 2014 9:06:32 PM UTC+5:30, Chris Angelico wrote: > > There was a problem while creating the post asking the question. Here it is now: https://groups.google.com/d/msg/comp.lang.python/WINUrOfAey4/pvbnapLrRcsJ > Solution: Get off Google Groups. Subscribe to python-list at python.org > and read it all in your email client, or read comp.lang.python in a > real newsreader. That'll fix several other problems too. Or read and follow: https://wiki.python.org/moin/GoogleGroupsPython From ronaksoni301 at gmail.com Fri May 23 12:08:24 2014 From: ronaksoni301 at gmail.com (Ronak Dhakan) Date: Fri, 23 May 2014 09:08:24 -0700 (PDT) Subject: Windows automatic rebooting due to faulty code In-Reply-To: References: Message-ID: <921d8985-0730-4604-985d-7e77a4a4b45f@googlegroups.com> It is a small file to draw an approximate circle using Turtle. The reboot does not happen consistently. Here is the code: http://pastebin.com/8T3aRCEd I was thinking whether there is a way to run python in a virtual environment. From joel.goldstick at gmail.com Fri May 23 12:33:56 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 23 May 2014 12:33:56 -0400 Subject: Windows automatic rebooting due to faulty code In-Reply-To: <921d8985-0730-4604-985d-7e77a4a4b45f@googlegroups.com> References: <921d8985-0730-4604-985d-7e77a4a4b45f@googlegroups.com> Message-ID: On May 23, 2014 12:12 PM, "Ronak Dhakan" wrote: > > It is a small file to draw an approximate circle using Turtle. The reboot does not happen consistently. Here is the code: http://pastebin.com/8T3aRCEd > > I was thinking whether there is a way to run python in a virtual environment. > -- > https://mail.python.org/mailman/listinfo/python-list Try on different machine. Maybe hardware or driver issue -------------- next part -------------- An HTML attachment was scrubbed... URL: From dihedral88888 at gmail.com Fri May 23 12:30:36 2014 From: dihedral88888 at gmail.com (CHIN Dihedral) Date: Fri, 23 May 2014 09:30:36 -0700 (PDT) Subject: Windows automatic rebooting due to faulty code In-Reply-To: <921d8985-0730-4604-985d-7e77a4a4b45f@googlegroups.com> References: <921d8985-0730-4604-985d-7e77a4a4b45f@googlegroups.com> Message-ID: On Saturday, May 24, 2014 12:08:24 AM UTC+8, Ronak Dhakan wrote: > It is a small file to draw an approximate circle using Turtle. The reboot does not happen consistently. Here is the code: http://pastebin.com/8T3aRCEd > > > > I was thinking whether there is a way to run python in a virtual environment. Check colinux or VMWARE. From davea at davea.name Fri May 23 13:52:41 2014 From: davea at davea.name (Dave Angel) Date: Fri, 23 May 2014 13:52:41 -0400 (EDT) Subject: Windows rebooting due to faulty code References: <41e58dfd-b9c1-41b1-b849-ddc5ee8a978e@googlegroups.com> Message-ID: Ronak Dhakan Wrote in message: > I am learning python, and sometimes when I run a file with a faulty code, windows gives a message that the system is rebooting and gives me 1 minute to save my work. Does anyone know how can I fix this? Most of the time a faulty code gives errors in python, but this is unique. I create files like Exercise 1.2.py and run it through IDLE. > It is very unlikely that running a program will cause a proper Windows system to reboot. The one example I can think of is the restart.exe program, which is deliberately doing it. It is even much less likely that it could be triggered by beginner's code written in python without 3rd party add-ons. Therefore I'd conclude you've either got a corrupted system, or you're tripping on a Windows bug. The first things I'd do, if stuck on Windows for some reason, is to check your system for Windows updates, then for viruses, hackers, and such. -- DaveA From tjreedy at udel.edu Fri May 23 15:10:04 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 May 2014 15:10:04 -0400 Subject: hashing strings to integers In-Reply-To: References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: On 5/23/2014 6:27 AM, Adam Funk wrote: > that. The only thing that really bugs me in Python 3 is that execfile > has been removed (I find it useful for testing things interactively). The spelling has been changed to exec(open(...).read(), ... . It you use it a lot, add a customized def execfile(filename, ... to your site module or local utils module. Execfile was a separate statement *only) because exec was a statememt. Once exec was was changed to a function taking arguments, that justification disappeared. Terry Jan Reedy From tjreedy at udel.edu Fri May 23 15:19:52 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 May 2014 15:19:52 -0400 Subject: Windows automatic rebooting due to faulty code In-Reply-To: <921d8985-0730-4604-985d-7e77a4a4b45f@googlegroups.com> References: <921d8985-0730-4604-985d-7e77a4a4b45f@googlegroups.com> Message-ID: On 5/23/2014 12:08 PM, Ronak Dhakan wrote: > It is a small file to draw an approximate circle using Turtle. > The reboot does not happen consistently. Here is the code: > http://pastebin.com/8T3aRCEd from swampy.TurtleWorld import * world = TurtleWorld() This is not the turtle module in the stdlib. It is most like the source of your reboot problem. Report your problem to the author. Also try running your example in the Windows console. (Not nearly as nice, I know.) There might possibly be a bad interaction with Idle. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Fri May 23 16:16:10 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 23 May 2014 21:16:10 +0100 Subject: How keep Python 3 moving forward Message-ID: An article by Brett Cannon that I thought might be of interest http://nothingbutsnark.svbtle.com/my-view-on-the-current-state-of-python-3 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From robert.snoeberger at icloud.com Fri May 23 16:52:33 2014 From: robert.snoeberger at icloud.com (Robert Snoeberger) Date: Fri, 23 May 2014 20:52:33 +0000 (GMT) Subject: how to create a frame object when embedding python? Message-ID: <4b27004e-57fa-4467-8a3a-1328f8961952@me.com> Hi python-list, I'm embedding Python in an application and I have encountered two crashes while calling built-in functions that expect a top-level frame. See the following bug reports:?http://bugs.python.org/issue21563?and http://bugs.python.org/issue21418.?The problem is that the workflow for embedding the Python interpreter does not involve creation of a frame.?RubyPython, a language interface to call Python from Ruby, has the same problem,?http://rubypython.rubyforge.org/#known-problems. Since there is not a top-level frame object, some built-in functions do not work properly. In most cases, this problem is easily worked-around because globals and locals can be passed as optional arguments. The crashes, however, are more unfortunate.? As an example, I can crash RubyPython by calling the built-in function execfile with a single argument. irb(main):001:0> require('rubypython') C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/blankslate-3.1.2/lib/blankslate.rb:51: warning: undefining `object_id' may cause serious problems => true irb(main):002:0> RubyPython.start => true irb(main):003:0> binmod = RubyPython.import('__builtin__') => irb(main):004:0> binmod.execfile('foo.py') The fourth line crashed the ruby interpreter. This is an example where an application might want to give full access to the functions in a Python module. It would be nice to find a way to prevent the crash without restricting the API. I am curious if anyone has suggestions for creating a top-level frame? Thank you, Rob ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From qhfgva at gmail.com Fri May 23 18:09:00 2014 From: qhfgva at gmail.com (qhfgva) Date: Fri, 23 May 2014 15:09:00 -0700 (PDT) Subject: trying to find nose.tools.assert_raises_regexp Message-ID: $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import nose.tools >>> nose.__version__ '1.3.3' >>> nose.tools.assert_raises_regexp Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'assert_raises_regexp' I see people using code like the following from nose.tools import assert_equals, assert_raises_regexp (the above line is from diy-lisp - a python project on githup) but I'm not able to find a version of nose that explicitly mentions this function. perplexed... From torriem at gmail.com Fri May 23 18:52:17 2014 From: torriem at gmail.com (Michael Torrie) Date: Fri, 23 May 2014 16:52:17 -0600 Subject: All-numeric script names and import In-Reply-To: References: <1714fbce-827f-4ba5-853c-f2f934a75466@googlegroups.com> Message-ID: <537FD121.1090404@gmail.com> On 05/23/2014 03:28 AM, Chris Angelico wrote: > On Fri, May 23, 2014 at 7:22 PM, Wolfgang Maier > wrote: >> I see, so what you should propose then is a change to import, so that when >> it can't find a module it will try to import an alternative that's >> pronounced the same way. Then you could simply do: >> >> import one >> >> and you're fine :) > > This strikes me as a very dangerous proposal. Imagine what would > happen when you try to "import chip" in New Zealand and it goes out > looking for "chup.py". Or the devastating results of "yes.py" and > "no.py" being indistinguishable on politicians' builds of Python... If you use a proper web framework, then you can define your urls to be anything you want. Just set up the appropriate mapping and away you go. Furthermore you can use apache directives to alias /1/ to something more importable. From torriem at gmail.com Fri May 23 18:54:26 2014 From: torriem at gmail.com (Michael Torrie) Date: Fri, 23 May 2014 16:54:26 -0600 Subject: Windows automatic rebooting due to faulty code In-Reply-To: References: Message-ID: <537FD1A2.9040408@gmail.com> On 05/23/2014 09:26 AM, Ronak Dhakan wrote: > Even I am surprised, python errors should stay in python. But I am > sure that the reboot is triggered exactly when I run some faulty > code. And usually I change the code after reboot, so I haven't > checked whether the same code is able to repeat the reboot. This > happens even in simple code of 10-15 lines for drawing a polygon. > > There was a problem while creating the post asking the question. Here > it is now: > https://groups.google.com/d/msg/comp.lang.python/WINUrOfAey4/pvbnapLrRcsJ Almost certainly you are experiencing a hardware fault. Possibly bad RAM. Windows will not let user-space code crash the operating system. Though user-space code could trigger something in the kernel that then faults. This is likely what's happening here. But the real cause is probably hardware. If it's not RAM, then it might be video hardware failing. From subhabangalore at gmail.com Fri May 23 19:15:14 2014 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Fri, 23 May 2014 16:15:14 -0700 (PDT) Subject: TextBlob on Windows Message-ID: Dear Group, It seems there is a nice language processing library named TextBlob, like NLTK. But I am being unable to install it on my Windows(MS-Windows 7 machine. I am using Python 2.7 If anyone of the esteemed members may kindly suggest me the solution. I tried the note in following URL http://stackoverflow.com/questions/20562768/trouble-installing-textblob-for-python but did not help much. Thanking in Advance, Regards, Subhabrata Banerjee. From roy at panix.com Fri May 23 19:57:24 2014 From: roy at panix.com (Roy Smith) Date: Fri, 23 May 2014 19:57:24 -0400 Subject: How keep Python 3 moving forward References: Message-ID: In article , Mark Lawrence wrote: > An article by Brett Cannon that I thought might be of interest > http://nothingbutsnark.svbtle.com/my-view-on-the-current-state-of-python-3 Thanks for the pointer. I installed and ran caniusepython3. It tells me: > Finding and checking dependencies ... > [WARNING] rpclib not found > > You need 19 projects to transition to Python 3. > Of those 19 projects, 17 have no direct dependencies blocking their > transition: > > beanstalkc > dateglob > diamond > django-multi-sessions > django-timedeltafield > dnspython > ecks > fabric > gevent (which is blocking grequests) > hash_ring > httmock > jellyfish > boto (which is blocking mrjob) > paste > pyephem > python-cjson > suds That's a big list. A few of those we could probably work around or replace with a different module without too much pain. But, between gevent, boto, fabric, and suds, any idea of migrating is a total non-starter for us. I imagine they're all working on ports, but I'll check back in a year and see how things stand. From ned at nedbatchelder.com Fri May 23 20:07:08 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 23 May 2014 20:07:08 -0400 Subject: trying to find nose.tools.assert_raises_regexp In-Reply-To: References: Message-ID: On 5/23/14 6:09 PM, qhfgva wrote: > $ python > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > [GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import nose.tools >>>> nose.__version__ > '1.3.3' >>>> nose.tools.assert_raises_regexp > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'assert_raises_regexp' > > > I see people using code like the following > > from nose.tools import assert_equals, assert_raises_regexp > > (the above line is from diy-lisp - a python project on githup) > > but I'm not able to find a version of nose that explicitly mentions this function. > > perplexed... > nose.tools auto-creates these names from the names in unittest, with this code: https://github.com/nose-devs/nose/blob/master/nose/tools/trivial.py#L46 You don't have assert_raises_regexp because your unittest module doesn't have assertRaisesRegexp. That method is new in 2.7, but you are using 2.6.5, so it doesn't exist. -- Ned Batchelder, http://nedbatchelder.com From irmen.NOSPAM at xs4all.nl Fri May 23 20:36:36 2014 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 24 May 2014 02:36:36 +0200 Subject: Windows automatic rebooting due to faulty code In-Reply-To: References: Message-ID: <537fe994$0$2831$e4fe514c@news.xs4all.nl> On 24-5-2014 0:54, Michael Torrie wrote: > On 05/23/2014 09:26 AM, Ronak Dhakan wrote: >> Even I am surprised, python errors should stay in python. But I am >> sure that the reboot is triggered exactly when I run some faulty >> code. And usually I change the code after reboot, so I haven't >> checked whether the same code is able to repeat the reboot. This >> happens even in simple code of 10-15 lines for drawing a polygon. >> >> There was a problem while creating the post asking the question. Here >> it is now: >> https://groups.google.com/d/msg/comp.lang.python/WINUrOfAey4/pvbnapLrRcsJ > > Almost certainly you are experiencing a hardware fault. Possibly bad > RAM. Windows will not let user-space code crash the operating system. > Though user-space code could trigger something in the kernel that then > faults. This is likely what's happening here. But the real cause is > probably hardware. If it's not RAM, then it might be video hardware > failing. > Or the computer has been infected by malware. -I. From ethan at stoneleaf.us Fri May 23 20:27:17 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 23 May 2014 17:27:17 -0700 Subject: How keep Python 3 moving forward In-Reply-To: References: Message-ID: <537FE765.4060807@stoneleaf.us> On 05/23/2014 04:57 PM, Roy Smith wrote: > > Thanks for the pointer. I installed and ran caniusepython3. It tells > me: [snip] > That's a big list. A few of those we could probably work around or > replace with a different module without too much pain. But, between > gevent, boto, fabric, and suds, any idea of migrating is a total > non-starter for us. I imagine they're all working on ports, but I'll > check back in a year and see how things stand. Don't imagine. Send 'em an email! Let them know there is one more user who'd like a Python 3 port. -- ~Ethan~ From roy at panix.com Fri May 23 21:12:48 2014 From: roy at panix.com (Roy Smith) Date: Fri, 23 May 2014 21:12:48 -0400 Subject: How keep Python 3 moving forward References: Message-ID: In article , Ethan Furman wrote: > On 05/23/2014 04:57 PM, Roy Smith wrote: > > > > Thanks for the pointer. I installed and ran caniusepython3. It tells > > me: > > [snip] > > > That's a big list. A few of those we could probably work around or > > replace with a different module without too much pain. But, between > > gevent, boto, fabric, and suds, any idea of migrating is a total > > non-starter for us. I imagine they're all working on ports, but I'll > > check back in a year and see how things stand. > > Don't imagine. Send 'em an email! Let them know there is one more user > who'd like a Python 3 port. But, you're assuming I want that. I don't. What I have now works. I'm not trying to be difficult here. I'm just looking at all the things I could be doing with my time that will improve my product and/or help grow the business. "Transition to Python 3" isn't even on the list. From qhfgva at gmail.com Fri May 23 22:14:27 2014 From: qhfgva at gmail.com (qhfgva) Date: Fri, 23 May 2014 19:14:27 -0700 (PDT) Subject: trying to find nose.tools.assert_raises_regexp In-Reply-To: References: Message-ID: <6777d173-3919-4d07-8a66-103fb4d91537@googlegroups.com> I knew it had to be something like that. Thanks. Time to upgrade. On Friday, May 23, 2014 6:07:08 PM UTC-6, Ned Batchelder wrote: > On 5/23/14 6:09 PM, qhfgva wrote: > > > $ python > > > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > > > [GCC 4.4.3] on linux2 > > > Type "help", "copyright", "credits" or "license" for more information. > > >>>> import nose.tools > > >>>> nose.__version__ > > > '1.3.3' > > >>>> nose.tools.assert_raises_regexp > > > Traceback (most recent call last): > > > File "", line 1, in > > > AttributeError: 'module' object has no attribute 'assert_raises_regexp' > > > > > > > > > I see people using code like the following > > > > > > from nose.tools import assert_equals, assert_raises_regexp > > > > > > (the above line is from diy-lisp - a python project on githup) > > > > > > but I'm not able to find a version of nose that explicitly mentions this function. > > > > > > perplexed... > > > > > > > nose.tools auto-creates these names from the names in unittest, with > > this code: > > https://github.com/nose-devs/nose/blob/master/nose/tools/trivial.py#L46 > > > > You don't have assert_raises_regexp because your unittest module doesn't > > have assertRaisesRegexp. That method is new in 2.7, but you are using > > 2.6.5, so it doesn't exist. > > > > -- > > Ned Batchelder, http://nedbatchelder.com On Friday, May 23, 2014 6:07:08 PM UTC-6, Ned Batchelder wrote: > On 5/23/14 6:09 PM, qhfgva wrote: > > > $ python > > > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > > > [GCC 4.4.3] on linux2 > > > Type "help", "copyright", "credits" or "license" for more information. > > >>>> import nose.tools > > >>>> nose.__version__ > > > '1.3.3' > > >>>> nose.tools.assert_raises_regexp > > > Traceback (most recent call last): > > > File "", line 1, in > > > AttributeError: 'module' object has no attribute 'assert_raises_regexp' > > > > > > > > > I see people using code like the following > > > > > > from nose.tools import assert_equals, assert_raises_regexp > > > > > > (the above line is from diy-lisp - a python project on githup) > > > > > > but I'm not able to find a version of nose that explicitly mentions this function. > > > > > > perplexed... > > > > > > > nose.tools auto-creates these names from the names in unittest, with > > this code: > > https://github.com/nose-devs/nose/blob/master/nose/tools/trivial.py#L46 > > > > You don't have assert_raises_regexp because your unittest module doesn't > > have assertRaisesRegexp. That method is new in 2.7, but you are using > > 2.6.5, so it doesn't exist. > > > > -- > > Ned Batchelder, http://nedbatchelder.com On Friday, May 23, 2014 6:07:08 PM UTC-6, Ned Batchelder wrote: > On 5/23/14 6:09 PM, qhfgva wrote: > > > $ python > > > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > > > [GCC 4.4.3] on linux2 > > > Type "help", "copyright", "credits" or "license" for more information. > > >>>> import nose.tools > > >>>> nose.__version__ > > > '1.3.3' > > >>>> nose.tools.assert_raises_regexp > > > Traceback (most recent call last): > > > File "", line 1, in > > > AttributeError: 'module' object has no attribute 'assert_raises_regexp' > > > > > > > > > I see people using code like the following > > > > > > from nose.tools import assert_equals, assert_raises_regexp > > > > > > (the above line is from diy-lisp - a python project on githup) > > > > > > but I'm not able to find a version of nose that explicitly mentions this function. > > > > > > perplexed... > > > > > > > nose.tools auto-creates these names from the names in unittest, with > > this code: > > https://github.com/nose-devs/nose/blob/master/nose/tools/trivial.py#L46 > > > > You don't have assert_raises_regexp because your unittest module doesn't > > have assertRaisesRegexp. That method is new in 2.7, but you are using > > 2.6.5, so it doesn't exist. > > > > -- > > Ned Batchelder, http://nedbatchelder.com From ben at benfinney.id.au Sat May 24 00:29:35 2014 From: ben at benfinney.id.au (Ben Finney) Date: Sat, 24 May 2014 14:29:35 +1000 Subject: Python 3 support for Fabric (was: How keep Python 3 moving forward) References: Message-ID: <85egzj6bps.fsf_-_@benfinney.id.au> Roy Smith writes: > Thanks for the pointer. I installed and ran caniusepython3. It tells > me: > > > Of those 19 projects, 17 have no direct dependencies blocking their > > transition: > > [?] > > fabric Fabric was for a long time held back by its dependency on the Paramiko library. But that library is now Python 3 compatible, and Fabric is moving steadily in the direction of Python 3 support. The latest is a change in the documentation to explicitly remove the last dependency hurdle . Now the only blockers are internal; Fabric 2.0 is AFAICT going to be the Python 3 compatible version of Fabric, and it is coming along well. -- \ ?Some people have a problem, and they think ?I know, I'll use | `\ Perl!?. Now they have some number of problems but they're not | _o__) sure whether it's a string or an integer.? ?Benno Rice, 2011 | Ben Finney From asmbansal2 at gmail.com Sat May 24 01:03:25 2014 From: asmbansal2 at gmail.com (Aseem Bansal) Date: Fri, 23 May 2014 22:03:25 -0700 (PDT) Subject: Advice for choosing correct architecture/tech for a hobby project In-Reply-To: References: <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0@googlegroups.com> Message-ID: The project is not a browser but a app for managing the bookmarks. Only managing by categories. A replacement for the bookmarks made in webbrowser. I wanted to make bookmarks easier to use. Hierarchical structure of bookmarks gives a lot of problems. I wanted to solve that for my use. On Friday, May 23, 2014 1:19:22 AM UTC+5:30, Mark H. Harris wrote: > On 5/22/14 1:54 PM, Aseem Bansal wrote: > > > I am working on a hobby project - a Bookmarker{snip} > > > > hi, no django is not really the correct tool-set. Django is for > > server-side content management, but who knows, you might come up with a > > great hack (I don't want to discourage you). But, a straight python > > trimmed down app would probably be better... what led you to django? > > > > It seems from your descriptions, which don't make sense by the way, that > > you are attempting to create your own 'browser' within your app (web > > api) and you want to use a standard browser (like firefox or chrome) to > > 'front-end' the apps bookmarks. So, your app needs to be able to read > > your browser's bookmarks file. > > > > Browsers most certainly can read http:// https:// file:// etc. (and many > > more). Your api may not be able to read local file:// urls, but I'm > > skeptical about that (most web api(s) have no trouble with file:// either). > > > > Provide some more info, somebody will help. > > > > > > marcus From asmbansal2 at gmail.com Sat May 24 01:07:14 2014 From: asmbansal2 at gmail.com (Aseem Bansal) Date: Fri, 23 May 2014 22:07:14 -0700 (PDT) Subject: Advice for choosing correct architecture/tech for a hobby project In-Reply-To: References: <6a3c5b20-bce5-4c95-b27f-3840e9cc7df0@googlegroups.com> Message-ID: <14da892a-7144-40b8-ac7d-1ba915d66550@googlegroups.com> I know that there are many online ways to do what I am trying to do but this was something I wanted to make. I have learnt Python myself and wanted to learn a way to make apps in Python. GUI development in Python has given a lot of headache while trying to find an appropriate framework with the addons(community, designer tool, documentation, open source etc.). The only nearly viable solution that I found was Kivy but the current project idea that I had was this bookmarker project which needed to have a way to add bookmarks easily through browser so I settled on the most popular web framework present. On Friday, May 23, 2014 2:58:51 AM UTC+5:30, Ethan Furman wrote: > On 05/22/2014 11:54 AM, Aseem Bansal wrote: > > > > > > I am working on a hobby project - a Bookmarker https://github.com/anshbansal/Bookmarker. > > > > Take a look at delicio.us -- it seems to be a similar type of experience. > > > > -- > > ~Ethan~ From charlesg at unixrealm.com Sat May 24 02:46:57 2014 From: charlesg at unixrealm.com (Charles Gagnon) Date: Fri, 23 May 2014 23:46:57 -0700 (PDT) Subject: Parallel python in the cloud Message-ID: We were happily using PiCloud for several long calculations and we very happy with with it. With their realtime cores, we could take really large calculations set and run through fairly quickly. Now that PiCloud is going away, we ran a few tests on Mutlyvac but so far, we are struggling to accomplish the same thing we had on PiCloud. I have several "pieces" of my puzzle but can't seem to be able to put it together. I've seen and tried StarCluster and also various parallel python options but all options seem challenging to put together. The goal is to mimic PiCloud, ie. loop through a function: def some_NP_func(x, y): ... return z some_cloud.call(some_NP_func, a1, a2) Which computes the function on the cloud. We use this often in for loops with arrays of arguments. The other scenario is: some_cloud.map(some_NP_intense_func, [...], [...]) Which iterates through and returns results. We need to run a lot of this in batch from a scheduler so I always try to avoid interactive environment (how does iPython parallel work in batch?). What is the preferred approach or method right now for heavy parallel computation like this? Regards, From wxjmfauth at gmail.com Sat May 24 03:13:56 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 24 May 2014 00:13:56 -0700 (PDT) Subject: How keep Python 3 moving forward In-Reply-To: References: Message-ID: Le vendredi 23 mai 2014 22:16:10 UTC+2, Mark Lawrence a ?crit : > An article by Brett Cannon that I thought might be of interest > > http://nothingbutsnark.svbtle.com/my-view-on-the-current-state-of-python-3 > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > > Mark Lawrence > > > > --- > > This email is free from viruses and malware because avast! Antivirus protection is active. > > http://www.avast.com ========= ========= Quote: """ And with Python 3.4 I really have not heard anyone complain that they wouldn't like to use Python 3 instead of Python 2. """ Or the devs do not wish to listen. Python 3 will never work. jmf From noone at nowhere.net Sat May 24 10:35:42 2014 From: noone at nowhere.net (blindanagram) Date: Sat, 24 May 2014 15:35:42 +0100 Subject: How keep Python 3 moving forward In-Reply-To: References: Message-ID: On 24/05/2014 08:13, wxjmfauth at gmail.com wrote: > Le vendredi 23 mai 2014 22:16:10 UTC+2, Mark Lawrence a ?crit : >> An article by Brett Cannon that I thought might be of interest >> >> http://nothingbutsnark.svbtle.com/my-view-on-the-current-state-of-python-3 >> >> >> >> -- >> >> My fellow Pythonistas, ask not what our language can do for you, ask >> >> what you can do for our language. >> >> >> >> Mark Lawrence >> >> >> >> --- >> >> This email is free from viruses and malware because avast! Antivirus protection is active. >> >> http://www.avast.com > > ========= > ========= > > Quote: > """ And with Python 3.4 I really have not heard anyone complain that they wouldn't like to use Python 3 instead of Python 2. """ > > Or the devs do not wish to listen. > > Python 3 will never work. It works for me. From robert.kern at gmail.com Sat May 24 05:57:21 2014 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 24 May 2014 10:57:21 +0100 Subject: Parallel python in the cloud In-Reply-To: References: Message-ID: On 2014-05-24 07:46, Charles Gagnon wrote: > We were happily using PiCloud for several long calculations and we very happy with with it. With their realtime cores, we could take really large calculations set and run through fairly quickly. > > Now that PiCloud is going away, we ran a few tests on Mutlyvac but so far, we are struggling to accomplish the same thing we had on PiCloud. > > I have several "pieces" of my puzzle but can't seem to be able to put it together. I've seen and tried StarCluster and also various parallel python options but all options seem challenging to put together. > > The goal is to mimic PiCloud, ie. loop through a function: > > def some_NP_func(x, y): > ... > return z > > some_cloud.call(some_NP_func, a1, a2) > > Which computes the function on the cloud. We use this often in for loops with arrays of arguments. The other scenario is: > > some_cloud.map(some_NP_intense_func, [...], [...]) > > Which iterates through and returns results. We need to run a lot of this in batch from a scheduler so I always try to avoid interactive environment (how does iPython parallel work in batch?). IPython parallel works just fine "in batch". As far as your client code (i.e. what you wrote above) is concerned, it's just another library. E.g. https://github.com/ipython/ipython/blob/master/examples/Parallel%20Computing/nwmerge.py https://github.com/ipython/ipython/blob/master/examples/Parallel%20Computing/itermapresult.py etc. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From marko at pacujo.net Sat May 24 05:59:01 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 24 May 2014 12:59:01 +0300 Subject: How keep Python 3 moving forward References: Message-ID: <87tx8fh50a.fsf@elektro.pacujo.net> blindanagram : >> Quote: >> """ And with Python 3.4 I really have not heard anyone complain that >> they wouldn't like to use Python 3 instead of Python 2. """ >> >> Or the devs do not wish to listen. >> >> Python 3 will never work. > > It works for me. Instead of focusing on bringing legacy libraries to Python3 (for which there never seems to be a critical need), Python3 needs a brand new killer module/application/library that is only available on Python3. Asyncio is a baby step in that direction. Marko From rustompmody at gmail.com Sat May 24 06:40:44 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 24 May 2014 03:40:44 -0700 (PDT) Subject: How keep Python 3 moving forward In-Reply-To: <87tx8fh50a.fsf@elektro.pacujo.net> References: <87tx8fh50a.fsf@elektro.pacujo.net> Message-ID: <825b8996-4674-4d73-bd7d-756b505c3464@googlegroups.com> On Saturday, May 24, 2014 3:29:01 PM UTC+5:30, Marko Rauhamaa wrote: > > > > Instead of focusing on bringing legacy libraries to Python3 (for which > there never seems to be a critical need), Python3 needs a brand new > killer module/application/library that is only available on Python3. > I think those times are over http://en.wikipedia.org/wiki/Long_tail > > Asyncio is a baby step in that direction. > No issue with that > > > > > Marko From invalid at invalid.invalid Sat May 24 10:06:26 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 24 May 2014 14:06:26 +0000 (UTC) Subject: How keep Python 3 moving forward References: Message-ID: On 2014-05-24, wxjmfauth at gmail.com wrote: > Python 3 will never work. Neither will color TV. All that phase detection stuff and that shadow-mask thing? And airplanes? Bah! Completely ridiculous. -- Grant From roland at rptd.ch Sat May 24 10:48:23 2014 From: roland at rptd.ch (=?ISO-8859-1?Q?Roland_Pl=FCss?=) Date: Sat, 24 May 2014 16:48:23 +0200 Subject: Loading modules from files through C++ In-Reply-To: <537D2433.7080606@rptd.ch> References: <5376ACE7.8030706@rptd.ch> <53775D68.2010009@rptd.ch> <537768FB.7060303@rptd.ch> <53778005.8030105@rptd.ch> <53778E22.3040701@rptd.ch> <53790CCF.1070905@rptd.ch> <537B8E31.7000607@rptd.ch> <537D2433.7080606@rptd.ch> Message-ID: <5380B137.2030106@rptd.ch> > # CODE # > PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, NULL, NULL, 0, NULL, > NULL, NULL, NULL, NULL }; > > moduledef.m_name = "MyModule"; > moduledef.m_doc = "MyModule"; > pModule = PyModule_Create( &moduledef ); > PyState_AddModule( pModule, &moduledef ); > > PyRun_SimpleString( "print( globals() )\n" ); > PyRun_SimpleString( "import MyModule\nprint( globals() )\n" ); > # CODE # > > yields this: > > {'__name__': '__main__', '__builtins__': , > '__doc__': None, '__loader__': '_frozen_importlib.BuiltinImporter'>, '__package__': None} > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named 'MyModule' > Anybody got an idea? Somebody has a working example where he create a valid module from C++? It's just a namespace not even yet script sources applied. -- Yours sincerely Pl?ss Roland Leader and Head Programmer - Game: Epsylon ( http://www.indiedb.com/games/epsylon ) - Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine , http://dragengine.rptd.ch/wiki ) - Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php ) - As well as various Blender export scripts und game tools -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 263 bytes Desc: OpenPGP digital signature URL: From jeanpierreda at gmail.com Sat May 24 12:03:11 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 24 May 2014 09:03:11 -0700 Subject: How keep Python 3 moving forward In-Reply-To: <87tx8fh50a.fsf@elektro.pacujo.net> References: <87tx8fh50a.fsf@elektro.pacujo.net> Message-ID: On Sat, May 24, 2014 at 2:59 AM, Marko Rauhamaa wrote: > blindanagram : > Instead of focusing on bringing legacy libraries to Python3 (for which > there never seems to be a critical need), Python3 needs a brand new > killer module/application/library that is only available on Python3. > > Asyncio is a baby step in that direction. Yikes! Backwards incompatibility is a poor excuse for NIH syndrome. Don't reinvent the wheel, please. If there's an existing implementation of a thing, that can save you a lot of work. Even if it ties you to Python 2, that's worth it, most of the time. If you want to migrate to Python 3, help that library forward, rather than trying to make some bespoke replacement you think will be a killer app. -- Devin From travisgriggs at gmail.com Sat May 24 14:02:07 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Sat, 24 May 2014 11:02:07 -0700 Subject: How keep Python 3 moving forward In-Reply-To: References: Message-ID: Sent from my iPhone > On May 24, 2014, at 7:35, blindanagram wrote: > >> On 24/05/2014 08:13, wxjmfauth at gmail.com wrote: >> Le vendredi 23 mai 2014 22:16:10 UTC+2, Mark Lawrence a ?crit : >>> An article by Brett Cannon that I thought might be of interest >>> >>> http://nothingbutsnark.svbtle.com/my-view-on-the-current-state-of-python-3 >>> >>> >>> >>> -- >>> >>> My fellow Pythonistas, ask not what our language can do for you, ask >>> >>> what you can do for our language. >>> >>> >>> >>> Mark Lawrence >>> >>> >>> >>> --- >>> >>> This email is free from viruses and malware because avast! Antivirus protection is active. >>> >>> http://www.avast.com >> >> ========= >> ========= >> >> Quote: >> """ And with Python 3.4 I really have not heard anyone complain that they wouldn't like to use Python 3 instead of Python 2. """ >> >> Or the devs do not wish to listen. >> >> Python 3 will never work. > > It works for me. Works for me too. I do python3 exclusively. If the library/tool I need is python 2 only, I figure it's obvious it's in maintenance mode only and find something else. From ethan at stoneleaf.us Sat May 24 15:08:47 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 24 May 2014 12:08:47 -0700 Subject: How keep Python 3 moving forward In-Reply-To: References: <87tx8fh50a.fsf@elektro.pacujo.net> Message-ID: <5380EE3F.90701@stoneleaf.us> On 05/24/2014 09:03 AM, Devin Jeanpierre wrote: > On Sat, May 24, 2014 at 2:59 AM, Marko Rauhamaa wrote: >> >> Instead of focusing on bringing legacy libraries to Python3 (for which >> there never seems to be a critical need), Python3 needs a brand new >> killer module/application/library that is only available on Python3. > > Yikes! Backwards incompatibility is a poor excuse for NIH syndrome. > > Don't reinvent the wheel, please. If there's an existing > implementation of a thing, that can save you a lot of work. Even if it > ties you to Python 2, that's worth it, most of the time. If you want > to migrate to Python 3, help that library forward, rather than trying > to make some bespoke replacement you think will be a killer app. +1 -- ~Ethan~ From stefan_ml at behnel.de Sat May 24 15:44:35 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 24 May 2014 21:44:35 +0200 Subject: How keep Python 3 moving forward In-Reply-To: References: <87tx8fh50a.fsf@elektro.pacujo.net> Message-ID: Devin Jeanpierre, 24.05.2014 18:03: > On Sat, May 24, 2014 at 2:59 AM, Marko Rauhamaa wrote: >> blindanagram: >> Instead of focusing on bringing legacy libraries to Python3 (for which >> there never seems to be a critical need), Python3 needs a brand new >> killer module/application/library that is only available on Python3. >> >> Asyncio is a baby step in that direction. > > Yikes! Backwards incompatibility is a poor excuse for NIH syndrome. > > Don't reinvent the wheel, please. If there's an existing > implementation of a thing, that can save you a lot of work. Even if it > ties you to Python 2, that's worth it, most of the time. If you want > to migrate to Python 3, help that library forward, rather than trying > to make some bespoke replacement you think will be a killer app. http://www.joelonsoftware.com/articles/fog0000000069.html There might still be something that doesn't exist yet, and if you start working on that, going with Py3 is certainly the right way. For everything that's there already, however, reusing working, tested code is way better. And making it work in Py3. Stefan From marko at pacujo.net Sat May 24 15:49:26 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 24 May 2014 22:49:26 +0300 Subject: How keep Python 3 moving forward References: <87tx8fh50a.fsf@elektro.pacujo.net> Message-ID: <87ha4fgdo9.fsf@elektro.pacujo.net> Devin Jeanpierre : > If you want to migrate to Python 3, help that library forward, rather > than trying to make some bespoke replacement you think will be a > killer app. Few people have Python 3 as an objective. What I'm saying is that if Python 3 had something everybody wants and nothing else provides, the people will come, even the legacy libraries will be ported then. Marko From breamoreboy at yahoo.co.uk Sat May 24 16:11:45 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 24 May 2014 21:11:45 +0100 Subject: How keep Python 3 moving forward In-Reply-To: <87ha4fgdo9.fsf@elektro.pacujo.net> References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> Message-ID: On 24/05/2014 20:49, Marko Rauhamaa wrote: > Devin Jeanpierre : > >> If you want to migrate to Python 3, help that library forward, rather >> than trying to make some bespoke replacement you think will be a >> killer app. > > Few people have Python 3 as an objective. What I'm saying is that if > Python 3 had something everybody wants and nothing else provides, the > people will come, even the legacy libraries will be ported then. > Legacy libraries are being ported, as shown by the green on the Python Wall of Superpowers here https://python3wos.appspot.com/ (remember this used to be called the Python Wall of Shame, or something like that). What makes you think that they're not being ported? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From codemonkey at inbox.com Sat May 24 15:51:01 2014 From: codemonkey at inbox.com (Deb Wyatt) Date: Sat, 24 May 2014 11:51:01 -0800 Subject: is there a list/group for beginners? Message-ID: <55D91F514EA.000005A3codemonkey@inbox.com> An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sat May 24 17:39:01 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 24 May 2014 22:39:01 +0100 Subject: is there a list/group for beginners? In-Reply-To: <55D91F514EA.000005A3codemonkey@inbox.com> References: <55D91F514EA.000005A3codemonkey@inbox.com> Message-ID: On 24/05/2014 20:51, Deb Wyatt wrote: > Hello. I am a total python newbie and would like to ask questions but > all my questions seem so stinkin' elementary compared to the posts I've > read so far. Is there a beginning python list anywhere? I have > searched and searched. Meanwhile I will continue to read the messages > here to cram as much info into my brain as possible. > > Thanks in advance, > Deb in WA, USA > ------------------------------------------------------------------------ > Protect your computer files with professional cloud backup. Get PCRx > Backup and upload unlimited files automatically. > > > Welcome :) See https://mail.python.org/mailman/listinfo/tutor also available as gmane.comp.python.tutor. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From luisjosenovoa at gmail.com Sat May 24 18:05:52 2014 From: luisjosenovoa at gmail.com (=?ISO-8859-1?Q?Luis_Jos=E9_Novoa?=) Date: Sat, 24 May 2014 15:05:52 -0700 (PDT) Subject: Numpy Array of Sets Message-ID: <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> Hi All, Hope you're doing great. One quick question. I am defining an array of sets using numpy as: a=array([set([])]*3) Now, if I want to add an element to the set in, lets say, a[0], and I use the .add(4) operation, which results in: array([set([4]), set([4]), set([4])], dtype=object) which I do not want. If I use the union operator a[0] = a[0] | set([4]) then I obtain what I want: array([set([4]), set([]), set([])], dtype=object) Can anyone explain whay this happens? Thank you very much. From ikorot01 at gmail.com Sat May 24 18:12:23 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Sat, 24 May 2014 15:12:23 -0700 Subject: Run pip Message-ID: Hi, ALL, I'm running Windows XP SP3 with python 2.7. According to https://pip.pypa.io/en/latest/installing.html all I need is to download get-pip.py and then run "python get-pip.py". However, after that running pip does not do anything. It says "pip is not recognized as an internal command". My goal is to install PyOpenGL, which I can do by running "pip install PyOpenGL" according to http://pyopengl.sourceforge.net/documentation/installation.html. The global search for "pip" didn't produce any results. What am I missing? Thank you. From robert.kern at gmail.com Sat May 24 18:14:32 2014 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 24 May 2014 23:14:32 +0100 Subject: Numpy Array of Sets In-Reply-To: <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> References: <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> Message-ID: On 2014-05-24 23:05, Luis Jos? Novoa wrote: > Hi All, > > Hope you're doing great. One quick question. I am defining an array of sets using numpy as: > > a=array([set([])]*3) > > Now, if I want to add an element to the set in, lets say, a[0], and I use the .add(4) operation, which results in: > > array([set([4]), set([4]), set([4])], dtype=object) > > which I do not want. If I use the union operator > > a[0] = a[0] | set([4]) > > then I obtain what I want: > > array([set([4]), set([]), set([])], dtype=object) > > Can anyone explain whay this happens? Same reason why you shouldn't make a list of lists like so: [[]]*3 https://docs.python.org/2/faq/programming.html#how-do-i-create-a-multidimensional-list -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From wolfgang.maier at biologie.uni-freiburg.de Sat May 24 18:25:55 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Sun, 25 May 2014 00:25:55 +0200 Subject: Numpy Array of Sets In-Reply-To: References: <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> Message-ID: <53811C73.6030308@biologie.uni-freiburg.de> On 25.05.2014 00:14, Robert Kern wrote: > On 2014-05-24 23:05, Luis Jos? Novoa wrote: >> Hi All, >> >> Hope you're doing great. One quick question. I am defining an array of >> sets using numpy as: >> >> a=array([set([])]*3) >> Has nothing to do with numpy, but the problem is exclusively with your innermost expression [set([])]*3. >> Now, if I want to add an element to the set in, lets say, a[0], and I >> use the .add(4) operation, which results in: >> with .add you are modifying the *existing* set. >> array([set([4]), set([4]), set([4])], dtype=object) >> >> which I do not want. If I use the union operator >> >> a[0] = a[0] | set([4]) >> here you are forming a *new* set and put it in a[0] replacing the old set at this position. >> then I obtain what I want: >> >> array([set([4]), set([]), set([])], dtype=object) >> >> Can anyone explain whay this happens? > > Same reason why you shouldn't make a list of lists like so: [[]]*3 > > https://docs.python.org/2/faq/programming.html#how-do-i-create-a-multidimensional-list > The above link explains the underlying problem. Best, Wolfgang From breamoreboy at yahoo.co.uk Sat May 24 18:34:47 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 24 May 2014 23:34:47 +0100 Subject: Run pip In-Reply-To: References: Message-ID: On 24/05/2014 23:12, Igor Korot wrote: > Hi, ALL, > I'm running Windows XP SP3 with python 2.7. > > According to https://pip.pypa.io/en/latest/installing.html all I need > is to download get-pip.py and then run "python get-pip.py". > > However, after that running pip does not do anything. It says "pip is > not recognized as an internal command". > > My goal is to install PyOpenGL, which I can do by running "pip install > PyOpenGL" according to > http://pyopengl.sourceforge.net/documentation/installation.html. > > The global search for "pip" didn't produce any results. > > What am I missing? > > Thank you. > a) set up pip on your windows path. b) cd to (say) c:\python27\scripts pip install PyOpenGL c) c:\python27\scripts\pip install PyOpenGL -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ikorot01 at gmail.com Sat May 24 18:47:10 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Sat, 24 May 2014 15:47:10 -0700 Subject: Run pip In-Reply-To: References: Message-ID: Mark, On Sat, May 24, 2014 at 3:34 PM, Mark Lawrence wrote: > On 24/05/2014 23:12, Igor Korot wrote: >> >> Hi, ALL, >> I'm running Windows XP SP3 with python 2.7. >> >> According to https://pip.pypa.io/en/latest/installing.html all I need >> is to download get-pip.py and then run "python get-pip.py". >> >> However, after that running pip does not do anything. It says "pip is >> not recognized as an internal command". >> >> My goal is to install PyOpenGL, which I can do by running "pip install >> PyOpenGL" according to >> http://pyopengl.sourceforge.net/documentation/installation.html. >> >> The global search for "pip" didn't produce any results. >> >> What am I missing? >> >> Thank you. >> > > a) set up pip on your windows path. > b) cd to (say) c:\python27\scripts > pip install PyOpenGL > c) c:\python27\scripts\pip install PyOpenGL As I said: "global search for pip does not produce any results". So I have no idea where to point my $PATH variable on step a)... Thank you. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what > you can do for our language. > > Mark Lawrence > > --- > This email is free from viruses and malware because avast! Antivirus > protection is active. > http://www.avast.com > > > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sat May 24 18:57:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 May 2014 08:57:29 +1000 Subject: is there a list/group for beginners? In-Reply-To: <55D91F514EA.000005A3codemonkey@inbox.com> References: <55D91F514EA.000005A3codemonkey@inbox.com> Message-ID: On Sun, May 25, 2014 at 5:51 AM, Deb Wyatt wrote: > > Hello. I am a total python newbie and would like to ask questions but all my questions seem so stinkin' elementary compared to the posts I've read so far. Is there a beginning python list anywhere? I have searched and searched. Meanwhile I will continue to read the messages here to cram as much info into my brain as possible. > There does happen to be a python-tutor list (as Mark mentioned), but as a general rule, it's not a problem to have a mixture of levels of question on the same list. Don't be afraid to ask basic questions while people are asking more complicated ones; this is one of the beauties of mailing lists and newsgroups, the separation of threads. ChrisA From breamoreboy at yahoo.co.uk Sat May 24 19:18:18 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 25 May 2014 00:18:18 +0100 Subject: Run pip In-Reply-To: References: Message-ID: On 24/05/2014 23:47, Igor Korot wrote: > Mark, > > On Sat, May 24, 2014 at 3:34 PM, Mark Lawrence wrote: >> On 24/05/2014 23:12, Igor Korot wrote: >>> >>> Hi, ALL, >>> I'm running Windows XP SP3 with python 2.7. >>> >>> According to https://pip.pypa.io/en/latest/installing.html all I need >>> is to download get-pip.py and then run "python get-pip.py". >>> >>> However, after that running pip does not do anything. It says "pip is >>> not recognized as an internal command". >>> >>> My goal is to install PyOpenGL, which I can do by running "pip install >>> PyOpenGL" according to >>> http://pyopengl.sourceforge.net/documentation/installation.html. >>> >>> The global search for "pip" didn't produce any results. >>> >>> What am I missing? >>> >>> Thank you. >>> >> >> a) set up pip on your windows path. >> b) cd to (say) c:\python27\scripts >> pip install PyOpenGL >> c) c:\python27\scripts\pip install PyOpenGL > > As I said: "global search for pip does not produce any results". > So I have no idea where to point my $PATH variable on step a)... > > Thank you. > Sorry I should have said either a), b) or c). On my machine. c:\Users\Mark>dir c:\Python27\Scripts\pi*.exe Volume in drive C has no label. Volume Serial Number is 2453-A837 Directory of c:\Python27\Scripts 04/01/2014 16:16 65,536 pip.exe 04/01/2014 16:16 65,536 pip2.7.exe 04/01/2014 16:16 65,536 pip2.exe -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From tjreedy at udel.edu Sat May 24 20:27:11 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 May 2014 20:27:11 -0400 Subject: How keep Python 3 moving forward In-Reply-To: <87ha4fgdo9.fsf@elektro.pacujo.net> References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> Message-ID: On 5/24/2014 3:49 PM, Marko Rauhamaa wrote: > Few people have Python 3 as an objective. What I'm saying is that if > Python 3 had something everybody wants and nothing else provides, the > people will come, even the legacy libraries will be ported then. I cannot think of anything beyond the core that 'everybody' wants. However, Python 3.3 has unicode that works for all characters on all platforms, and some people want that. -- Terry Jan Reedy From rorsoft at gmail.com Sat May 24 23:06:47 2014 From: rorsoft at gmail.com (bookaa bookaa) Date: Sat, 24 May 2014 20:06:47 -0700 (PDT) Subject: Make Python Compilable, convert to Python source to Go Message-ID: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Make Python Compilable This tool can be called 'Python to GoLang', which translate Python source to Golang source. And then you can compile the Go files to executable binary. (btw: Go is a new C-like compilable language, open source). Generally, people consider Python as a script language. It has high development efficiency, but run too slowly, interpret running, and can not compile. It depends to Python environment, can not employ alone. For years, many people have do a lot of job try to improve running speed of Python, include Pypy, Cython. But all of these are not satisfied. In my opinion, Python only define a development rule. You can easily express your logic idea with this rule. It doesnot confines that it must be run as script. Only that we only have this C Python interpretor(CPython). So we take it for granted that Python is a script language. I think no matter how you program your work, it only represent some logics. There should be possible to convert from one computer language to another. Based on this, after some months of work, we have this utility. I consider Python as the most efficient langrage. Many genius programmers love Python and Go. Now with this tool, we can make Python compilable, and run more quickly. Python will be perfectly! We do not need C and C++ anymore! Python is not as before! Q1: Why do we need convert Python source to Go ? Why not coding with Go directly ? First, Python is good at develop efficiency. And Go is too simply and do not have many really-need functions. I do not suggest you choose Go as your primary development langrage. Second, Python has a lot of 3rd part libraries. And Go been as a new language, if can inherit all libraries from Python, it will be more powerful. This tool can work in 2 options: op1: If you want your product run under Python environment, or debug, you can choose op1. With this option, I will only convert your Python source files to Go, and ignore 'import' of system libraries. Mostly one line of Python will produce 1.5 lines of Go source, basicly preserve function, function names, variable names, calling graphics. The output Go source is easy to understand, optimize. op2: Convert all Python source to Go including system libraries. Generally this will product more than 150 thousand lines of Go source. After compile, your execute binary file can run without Python installation. You should include Python27.dll and some PYD file if need. Now its possible to deply your Python product. Q2: Why do you need python27.dll ? If you include this dll, why just run with one line of 'exec' ? If you run with 'exec', it is run with Python interpretor. You can not improve running speed. And its not safe. I will convert all function of Python to a correspond Go function. All variable becomes a Go variable. I will try to identify data type of each variable. If I find a var is integer, I will use int in Go. This make it possible to improve running speed. For variables I do not know data type, or list, tuple etc, I use PyObject. So there is no choice but call correspond operation functions from python27.dll. And many 3rd part libraries of Python is PYD compiled from C. This PYD file is actually DLL which dependance to python27.dll. With this tool, we can benefit all libraries of Python in Go. This makes Go more powful. For example, we still do not have good GUI libraries for Go, now we can try GUI libraries of Python and its possible to begin GUI development with Go now. It takes me more than 7 month to do this job, with more than 30000 lines of source, mostly in Python with some Go and C. As you may think, I can convert myself to Go! During the convertion, I must deal with complex Python logics. I must carefully understand any Python acknownledge point and try to find solution in Go. Its very difficault! Especially for some concept of Python which missing in Go, like try/exception, yield, var scope, no use var, var declare. This tool will public and open source later. Up for now, only support Python 2.7.6, do not support Python3. I have tested it on Win32, Win64, and I am sure its easy to run on all OS support Python and Go. Python is open source in C, Go is also open source in G. There can run on almost all operation system. With my Python to Go, I believe Python+Go will become popular development trend. You can download this to have a look how Python to Go work. This is a small tool for listen and dictation of learning Foreigin languages by me. http://pan.baidu.com/s/1eQADiHc including Python source, and converted Go sourced(more than 170000 lines), and compiled executable binary(win32). I may help you: 1. convert your Python project to Go. Its quick and safe and easy to deploy. 2. optimize running speed of your Python project 3. Make a speech. LiuTaoTao 9870365 at qq.com From rosuav at gmail.com Sun May 25 00:47:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 May 2014 14:47:27 +1000 Subject: Make Python Compilable, convert to Python source to Go In-Reply-To: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: On Sun, May 25, 2014 at 1:06 PM, bookaa bookaa wrote: > This tool can be called 'Python to GoLang', which translate Python source to Golang source. And then you can compile the Go files to executable binary. (btw: Go is a new C-like compilable language, open source). > Sounds like you're writing a Python implementation that uses a Go backend. As Pythons go, this is comparable to using Java, or Mono, or RPython, or C, or anything else. So there are two questions: 1) How compatible is your Python-to-Golang converter with all the nuances of Python code? Does it work perfectly on any arbitrary Python script? And, what version of Python is it aimed at? 2) What's performance like? Presumably significantly better than CPython, as that's what you're boasting here. Have you run a standardized benchmark? How do the numbers look? If the answer is "It'll work on anything, but it's only faster if you restrict yourself to a specific subset of Python syntax", that's still useful. But we'd need to see figures that tell us when it's worth adding a separate dependency and another translation layer (after all, every layer adds its own bug potential). ChrisA From wxjmfauth at gmail.com Sun May 25 02:43:59 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 24 May 2014 23:43:59 -0700 (PDT) Subject: How keep Python 3 moving forward In-Reply-To: References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> Message-ID: <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> Le dimanche 25 mai 2014 02:27:11 UTC+2, Terry Reedy a ?crit?: > On 5/24/2014 3:49 PM, Marko Rauhamaa wrote: > > > > > Few people have Python 3 as an objective. What I'm saying is that if > > > Python 3 had something everybody wants and nothing else provides, the > > > people will come, even the legacy libraries will be ported then. > > > > I cannot think of anything beyond the core that 'everybody' wants. > > However, Python 3.3 has unicode that works for all characters on all > > platforms, and some people want that. > > ======== ======== Python and unicode: a buggy hobbyist toy. Voil?. Nothing either good or bad. jmf From chris_news at arcor.de Sun May 25 03:01:43 2014 From: chris_news at arcor.de (Christian) Date: Sun, 25 May 2014 09:01:43 +0200 Subject: WSGI (was: Re: Python CGI) In-Reply-To: <20140519205252.264fc764@bigbox.christie.dr> References: <20140519205252.264fc764@bigbox.christie.dr> Message-ID: <53819557.2060402@arcor.de> On 05/20/2014 03:52 AM, Tim Chase wrote: > While Burak addressed your (Fast-)CGI issues, once you have a > test-script successfully giving you output, you can use the > standard-library's getpass.getuser() function to tell who your script > is running as. LoadModule wsgi_module modules/mod_wsgi.so AddHandler wsgi-script .wsgi WSGIDaemonProcess myproj user=chris threads=3 [root at t-centos1 ~]# ps -ef|grep chris chris 1201 1199 0 08:47 ? 00:00:00 /usr/sbin/httpd -------------------------------------------------------8<------- #!/usr/bin/python import getpass def application(environ, start_response): status = '200 OK' output = 'Hello World!' output += getpass.getuser() response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] ------------------------------------------------------->8------- Hello World!root Hmm, why is it root? I'm using Apache and mod_userdir. Can I define WSGIDaemonProcess for each user? - Chris From wxjmfauth at gmail.com Sun May 25 03:57:32 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 25 May 2014 00:57:32 -0700 (PDT) Subject: Make Python Compilable, convert to Python source to Go In-Reply-To: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: <707913a9-785a-4194-be76-cf8577658801@googlegroups.com> My opinions about Go. i) go build XXX that creates an exe, one can put on a usb stick and run (distribute) it, is a feature hard to beat. I do not know, if it will be rendered correctly. D:\jm\jmgo>hello3.exe ASCII abcde xyz German ??? ??? ? Polish ?????? Russian ??????? ??? CJK ?? French ???? Misc ??????* D:\jm\jmgo> ii) From a unicode perspective, excellent, coherent and very well constructed, but... iii) Having to work with an utf-8 arithmetic (strings <-> runes conversion), no thanks. jmf From ch2009 at arcor.de Sun May 25 03:06:18 2014 From: ch2009 at arcor.de (Chris) Date: Sun, 25 May 2014 09:06:18 +0200 Subject: WSGI (was: Re: Python CGI) In-Reply-To: <20140519205252.264fc764@bigbox.christie.dr> References: <20140519205252.264fc764@bigbox.christie.dr> Message-ID: <5381966A.1030801@arcor.de> On 05/20/2014 03:52 AM, Tim Chase wrote: > While Burak addressed your (Fast-)CGI issues, once you have a > test-script successfully giving you output, you can use the > standard-library's getpass.getuser() function to tell who your script > is running as. LoadModule wsgi_module modules/mod_wsgi.so AddHandler wsgi-script .wsgi WSGIDaemonProcess myproj user=chris threads=3 [root at t-centos1 ~]# ps -ef|grep chris chris 1201 1199 0 08:47 ? 00:00:00 /usr/sbin/httpd -------------------------------------------------------8<------- #!/usr/bin/python import getpass def application(environ, start_response): status = '200 OK' output = 'Hello World!' output += getpass.getuser() response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] ------------------------------------------------------->8------- Hello World!root Hmm, why is it root? I'm using Apache and mod_userdir. Can I define WSGIDaemonProcess for each user? - Chris -- Gru?, Christian From rorsoft at gmail.com Sun May 25 04:17:36 2014 From: rorsoft at gmail.com (bookaa bookaa) Date: Sun, 25 May 2014 01:17:36 -0700 (PDT) Subject: Make Python Compilable, convert to Python source to Go In-Reply-To: References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: On Sunday, May 25, 2014 12:47:27 PM UTC+8, Chris Angelico wrote: > On Sun, May 25, 2014 at 1:06 PM, bookaa wrote: > > > This tool can be called 'Python to GoLang', which translate Python source to Golang source. And then you can compile the Go files to executable binary. (btw: Go is a new C-like compilable language, open source). > > > > Sounds like you're writing a Python implementation that uses a Go > backend. As Pythons go, this is comparable to using Java, or Mono, or > RPython, or C, or anything else. So there are two questions: > > 1) How compatible is your Python-to-Golang converter with all the > nuances of Python code? Does it work perfectly on any arbitrary Python > script? And, what version of Python is it aimed at? I try to support all Python syntax, any arbitray script. From the example attached,you can see I translate all import system libraries needed and produce up to 170000?lines of Go. Up to now, only support Python 2.7.6. Maybe I will work on Python 3 later. > 2) What's performance like? Presumably significantly better than > CPython, as that's what you're boasting here. Have you run a > standardized benchmark? How do the numbers look? I must admit that after automaticaly convert Python source to Go, compile to EXE, the running speed is just as before. For compatible reason, I must make it behave?just as it before, support any Python feathers. Take a example, if we find a function?call func1(2), I can not simply convert it to Go function call as func1_in_go(2), but?something like this: current_module_scope.GetAttributeString("func1").CallObject(2) because func1 maybe overwrited. I think the significance of Python to Go, is it give us opportunity to make Python project run fast. We may edit the output Go source. or We may add some Python decorator to tell the converter its safe to convert it in simple form. > If the answer is "It'll work on anything, but it's only faster if you > restrict yourself to a specific subset of Python syntax", that's still > useful. But we'd need to see figures that tell us when it's worth > adding a separate dependency and another translation layer (after all, > every layer adds its own bug potential). > > ChrisA thanks, LiuTaoTao From gandalf at shopzeus.com Sun May 25 04:11:45 2014 From: gandalf at shopzeus.com (=?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Sun, 25 May 2014 10:11:45 +0200 Subject: compiled cx_freeze Message-ID: <5381A5C1.6000003@shopzeus.com> Anyone knows where to get a compiled cx_freeze that has already has this patch? http://hg.python.org/cpython/rev/7d20e30bd540 https://bitbucket.org/anthony_tuininga/cx_freeze/issue/81/python-34-venv-importlib-attributeerror The installer on the sourceforge site still has this bug. :-( I don't have the tools to compile it, and I cannot find any other place to download the patched version. Thanks From rosuav at gmail.com Sun May 25 04:52:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 May 2014 18:52:25 +1000 Subject: Make Python Compilable, convert to Python source to Go In-Reply-To: References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: On Sun, May 25, 2014 at 6:17 PM, bookaa bookaa wrote: >> 1) How compatible is your Python-to-Golang converter with all the >> nuances of Python code? Does it work perfectly on any arbitrary Python >> script? And, what version of Python is it aimed at? > > I try to support all Python syntax, any arbitray script. From the example > attached,you can see I translate all import system libraries needed and > produce up to 170000?lines of Go. Up to now, only support Python 2.7.6. > Maybe I will work on Python 3 later. > >> 2) What's performance like? Presumably significantly better than >> CPython, as that's what you're boasting here. Have you run a >> standardized benchmark? How do the numbers look? > > I must admit that after automaticaly convert Python source to Go, compile > to EXE, the running speed is just as before. For compatible reason, I must > make it behave?just as it before, support any Python feathers. Take a > example, if we find a function?call func1(2), I can not simply convert it > to Go function call as func1_in_go(2), but?something like this: current_module_scope.GetAttributeString("func1").CallObject(2) > because func1 maybe overwrited. > > I think the significance of Python to Go, is it give us opportunity to > make Python project run fast. We may edit the output Go source. or We > may add some Python decorator to tell the converter its safe to convert > it in simple form. This is extremely unsurprising. Everyone who says "Python is so slow" is comparing against a less dynamic language. Python lets you change any name *at any time*, so all lookups must be done at the time they're asked for. (By comparison, Pike binds all global names at compile time - effectively, when you import the module. If you want to change one, you need to reimport code that's using it. C, of course, binds everything early, and that's that.) There have been a variety of proposals to remove some of Python's dynamism with markers saying "This is read-only". Victor Stinner started a thread on python-ideas this week with some serious proposals and decent argument (backed by a POC fork of CPython 3.5). Also, I'm not 100% sure but I suspect that PyPy quite possibly optimizes on the basis of "this probably hasn't changed the meaning of len()", and does a quick check ("if len has been rebound, go to the slow path, otherwise run the fast path") rather than checking each time. Both of these options are viable, both have their trade-offs... and neither requires actually compiling via an unrelated language. I have never liked any system that involves converting code from one language to another and then hand-editing the resulting code. There is a reason the languages are different; they have different strengths and different weaknesses. There's always going to be something that's messy in the target language. Sometimes you don't care (you can probably write an 8086 Assembler interpreter in Python and have it run at 4.77MHz as long as the Python interpreter is running on fast enough hardware), but if your goal is an overall speed improvement, you're up against a number of Python interpreters that have specifically looked at performance (I know CPython may be considered slow, but the devs do care about running time; and PyPy touts running times of 16% of CPython's), so you're going to have to boast some pretty good numbers. Strong recommendation: If you want to move forward with this, compare against Python 3.x. New projects want to be written for Py3 rather than Py2, and you're limiting your project's usefulness if it's compatible only with Py2. As an added "bonus", Py3 is currently a bit slower than Py2 in a lot of benchmarks, so you get yourself a slightly easier target :) ChrisA From jurko.gospodnetic at pke.hr Sun May 25 04:54:48 2014 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Sun, 25 May 2014 10:54:48 +0200 Subject: How keep Python 3 moving forward - suds & Python 3 In-Reply-To: References: Message-ID: <5381AFD8.4050106@pke.hr> Hi Roy. On 24.5.2014. 1:57, Roy Smith wrote: >> You need 19 projects to transition to Python 3. >> Of those 19 projects, 17 have no direct dependencies blocking their >> transition: >> >>[...snipped...] >> suds > > That's a big list. A few of those we could probably work around or > replace with a different module without too much pain. But, between > gevent, boto, fabric, and suds, any idea of migrating is a total > non-starter for us. I imagine they're all working on ports, but I'll > check back in a year and see how things stand. FYI, the suds-jurko fork works on Python 3. And since I'm not aware of any other actively maintained fork, should I find more free time in the future I might rename it to suds and try to convert it to a formal successor to suds. Hope this helps. Best regards, Jurko Gospodneti? From stefan_ml at behnel.de Sun May 25 05:25:44 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 25 May 2014 11:25:44 +0200 Subject: How keep Python 3 moving forward In-Reply-To: References: Message-ID: Roy Smith, 24.05.2014 01:57: > I installed and ran caniusepython3. It tells me: > >> Finding and checking dependencies ... >> [WARNING] rpclib not found >> >> You need 19 projects to transition to Python 3. >> Of those 19 projects, 17 have no direct dependencies blocking their >> transition: >> >> beanstalkc >> dateglob >> diamond >> django-multi-sessions >> django-timedeltafield >> dnspython >> ecks >> fabric >> gevent (which is blocking grequests) >> hash_ring >> httmock >> jellyfish >> boto (which is blocking mrjob) >> paste >> pyephem >> python-cjson >> suds > > That's a big list. A few of those we could probably work around or > replace with a different module without too much pain. But, between > gevent, boto, fabric, and suds, any idea of migrating is a total > non-starter for us. I imagine they're all working on ports, but I'll > check back in a year and see how things stand. Ubuntu provides a (partial) Py3 port of boto. And I don't really see why you would consider fabric a dependency that keeps you from switching to Py3. In many cases, you can just keep running it in Py2 as you did before. Taking a closer look at the "big list" that caniusepython3 spits out will usually make it shrink to a manageable size. Meaning, the blind size of that list is not an excuse for anything. Stefan From stefan_ml at behnel.de Sun May 25 05:30:02 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 25 May 2014 11:30:02 +0200 Subject: Make Python Compilable, convert to Python source to Go In-Reply-To: References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: bookaa bookaa, 25.05.2014 10:17: > I think the significance of Python to Go, is it give us opportunity to > make Python project run fast. You shouldn't make that your only goal, because you'll have a really hard time achieving it (to put it mildly). Stefan From alister.nospam.ware at ntlworld.com Sun May 25 06:04:05 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Sun, 25 May 2014 10:04:05 GMT Subject: WSGI (was: Re: Python CGI) References: <20140519205252.264fc764@bigbox.christie.dr> Message-ID: On Sun, 25 May 2014 09:06:18 +0200, Chris wrote: > On 05/20/2014 03:52 AM, Tim Chase wrote: >> While Burak addressed your (Fast-)CGI issues, once you have a >> test-script successfully giving you output, you can use the >> standard-library's getpass.getuser() function to tell who your script >> is running as. > > LoadModule wsgi_module modules/mod_wsgi.so AddHandler wsgi-script .wsgi > WSGIDaemonProcess myproj user=chris threads=3 > > [root at t-centos1 ~]# ps -ef|grep chris chris 1201 1199 0 08:47 ? > 00:00:00 /usr/sbin/httpd > > -------------------------------------------------------8<------- > #!/usr/bin/python import getpass def application(environ, > start_response): > status = '200 OK' > output = 'Hello World!' > output += getpass.getuser() > response_headers = [('Content-type', 'text/plain'), > ('Content-Length', str(len(output)))] > start_response(status, response_headers) > > return [output] > ------------------------------------------------------->8------- > > Hello World!root > > Hmm, why is it root? > > I'm using Apache and mod_userdir. Can I define WSGIDaemonProcess for > each user? > > - Chris is your apache server running as root? if so it probably should be corrected -- Why is it taking so long for her to bring out all the good in you? From hauzer at gmx.com Sun May 25 06:01:28 2014 From: hauzer at gmx.com (=?UTF-8?B?0J3QuNC60L7Qu9CwINCS0YPQutC+0YHQsNCy0ZnQtdCy0LjRmw==?=) Date: Sun, 25 May 2014 12:01:28 +0200 Subject: compiled cx_freeze In-Reply-To: <5381A5C1.6000003@shopzeus.com> References: <5381A5C1.6000003@shopzeus.com> Message-ID: <5381BF78.5000504@gmx.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 25.5.2014 10:11, Nagy L?szl? Zsolt wrote: > Anyone knows where to get a compiled cx_freeze that has already has > this patch? > > http://hg.python.org/cpython/rev/7d20e30bd540 > https://bitbucket.org/anthony_tuininga/cx_freeze/issue/81/python-34-venv-importlib-attributeerror > > > > The installer on the sourceforge site still has this bug. :-( I > don't have the tools to compile it, and I cannot find any other > place to download the patched version. > > Thanks Actually, I've built cx_freeze 4.3.2 (the current version is 4.3.3) with that patch some time ago. I'm not sure how would I distribute it to you. `setup.py install` still requires a compiler for building extensions (even though they're already built), while wheels (and eggs) don't distribute the scripts (cxfreeze, cxfreeze-postinstall, cxfreeze-quickstart) needed to run cx_freeze. I guess you could install the wheel, manually run cxfreeze-postinstall and then add the .py extension to cxfreeze. Here are the files: https://www.dropbox.com/sh/ka8jyt5shyqn4t9/AACLTHMXHpsPsn5YeXCrWEBma -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBAgAGBQJTgb94AAoJEB1x37R9kdwnmWcQAMg73yM9hDzAH3yJjDHtxlHP PIBaOvg+7tNovAEjMXne3IBczZ7SrtwJW0smUT8j/GBMiGSSxUz4rydqAl2hAZ2A EPGyOiIFEvQMutjvtyMRNTUT9G0IUXbCXy9+tnHcK9pIUbNOV9QGSfY5jlxNGH4P ckssgi8GPYDUABwzxBlsrT2UZbSR2ef9JqPGgDn0c38b3YIWeHE3KYXP0zj4La/j iw7XjEwe275HNC2QuDcXzFPIBwLTbf4swPHd4v16BtTOM0m476x+wEj/OOTcHzud C8vMDKmxT3UIrrBxlWHVAQo+s1cUajYB9RuarsR3M6TOv+oMtncm2QJhtXyW/CzX 0SDqzFpekp3Ltpo3jU9aITR+BJHoSFsPp+ff4NoGNBW7zV/WpIS2rMagxHs4BzF5 HMcvknPE5bhCWk/hjF2i/jql8EZUpGi9d7xQIGZqXw+gpy6u0HIJa3nmCgTrruOI TW3I3KprH1WcyEEIHJI58MUqoQ8C1I60BY/0sPtMIg/tn7wn8PyOCVDNalGJJ7DU HVyE0r5i0n0cy2CfbZFLEs6D3Q9y0JdA1ITYL4uCQ/svMOR40+AmJhthxMpxF2Wl 5DA4GfNF/i7g6dZlToQcR+BpYSl9bk/6+C8R777q1VraYmL6b87Wg7jC3tG0kHB5 Fd7BNCFEX7Um/wMxIJ5x =ZaSc -----END PGP SIGNATURE----- From breamoreboy at yahoo.co.uk Sun May 25 06:24:38 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 25 May 2014 11:24:38 +0100 Subject: Make Python Compilable, convert to Python source to Go In-Reply-To: References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: On 25/05/2014 09:17, bookaa bookaa wrote: > Maybe I will work on Python 3 later. > That's good to know, it'll save me wasting my time looking at it now. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From none at mailinator.com Sun May 25 07:02:30 2014 From: none at mailinator.com (mm0fmf) Date: Sun, 25 May 2014 12:02:30 +0100 Subject: Make Python Compilable, convert to Python source to Go In-Reply-To: References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: On 25/05/2014 11:24, Mark Lawrence wrote: > On 25/05/2014 09:17, bookaa bookaa wrote: >> Maybe I will work on Python 3 later. >> > > That's good to know, it'll save me wasting my time looking at it now. > OT: Mark, you've been pro-Python3 enough in your recent postings you have forced me to act. I've just upgraded my 1st Python2 app to Python3. 2to3 did 99.999% of the work and I had to get a more modern version of a package which was Python3 compatible. From Tuesday (Monday is a holiday), all new Python code at work will be Python3 Andy From breamoreboy at yahoo.co.uk Sun May 25 07:40:15 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 25 May 2014 12:40:15 +0100 Subject: Make Python Compilable, convert to Python source to Go In-Reply-To: References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: On 25/05/2014 12:02, mm0fmf wrote: > On 25/05/2014 11:24, Mark Lawrence wrote: >> On 25/05/2014 09:17, bookaa bookaa wrote: >>> Maybe I will work on Python 3 later. >>> >> >> That's good to know, it'll save me wasting my time looking at it now. >> > OT: > Mark, you've been pro-Python3 enough in your recent postings you have > forced me to act. I've just upgraded my 1st Python2 app to Python3. 2to3 > did 99.999% of the work and I had to get a more modern version of a > package which was Python3 compatible. > > From Tuesday (Monday is a holiday), all new Python code at work will be > Python3 > > Andy I merely think Python 3 is the way to go, and that the Python 2.8 crew don't so much have loose screws, but never had them fitted in the first place. FTR I entirely agree with Roy Smith about sticking with Python 2 in his situation, strikes me as a complete no brainer. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From gandalf at shopzeus.com Sun May 25 07:47:42 2014 From: gandalf at shopzeus.com (=?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Sun, 25 May 2014 13:47:42 +0200 Subject: os.stat and time zones Message-ID: <5381D85E.8010502@shopzeus.com> This might be a silly question. Documentation of os.stat: > The exact meaning and resolution of the st_atime, st_mtime, and > st_ctime attributes depend on the operating system and the file > system. For example, on Windows systems using the FAT or FAT32 file > systems, st_mtime has 2-second resolution, and st_atime has only 1-day > resolution. See your operating system documentation for details. So it says that the meaning is platform dependent. But here is something interesting. Supposedly, os.stat(fpath).st_mtime and os.path.getmtime(path) return the same thing. The documentation of os.path.getmtime says that it "returns the number of seconds since the epoch". And the time module says that "To find out what the epoch is, look at gmtime(0)". And the documentation of gmtime says that it converts the given value to a struct_time *that is in UTC*. If the above are true, then as far as I can see, the meaning of st_mtime is NOT platform dependent. It always means the number of seconds elapsed since the epoch in UTC. (The resolution can be platform dependent, I admit that.) So what is the truth? What other difference can be in the meaning that is platform dependent? From luisjosenovoa at gmail.com Sun May 25 08:29:49 2014 From: luisjosenovoa at gmail.com (LJ) Date: Sun, 25 May 2014 05:29:49 -0700 (PDT) Subject: Numpy Array of Sets In-Reply-To: References: <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> Message-ID: Wolfgang, thank you very much for your reply. Following the example in the link, the problem appears: >>> A = [[0]*2]*3 >>> A [[0, 0], [0, 0], [0, 0]] >>> A[0][0] = 5 >>> A [[5, 0], [5, 0], [5, 0]] Now, if I use a numpy array: >>> d=array([[0]*2]*3) >>> d array([[0, 0], [0, 0], [0, 0]]) >>> d[0][0]=5 >>> d array([[5, 0], [0, 0], [0, 0]]) What is the difference here? Thank you, From ikorot01 at gmail.com Sun May 25 08:55:00 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 25 May 2014 05:55:00 -0700 Subject: Loop thru the dictionary with tuples Message-ID: Hi, ALL, I have a following data structure: my_dict[(var1,var2,var3)] = None my_dict[(var4,var5,var6)] = 'abc' What I'm trying to do is this: for (key,value) in my_dict: #Do some stuff but I'm getting an error "Too many values to unpack". What am I doing wrong? Thank you. From jcasale at activenetwerx.com Sun May 25 08:55:19 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 25 May 2014 12:55:19 +0000 Subject: compiled cx_freeze In-Reply-To: <5381A5C1.6000003@shopzeus.com> References: <5381A5C1.6000003@shopzeus.com> Message-ID: <22f6643f690f49d7a88178eccb9477fc@exch.activenetwerx.com> > Anyone knows where to get a compiled cx_freeze that has already has this > patch? http://www.lfd.uci.edu/~gohlke/pythonlibs/#cx_freeze From no.email at nospam.invalid Sun May 25 08:59:39 2014 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 25 May 2014 05:59:39 -0700 Subject: Loop thru the dictionary with tuples References: Message-ID: <7x61kuc8uc.fsf@ruckus.brouhaha.com> Igor Korot writes: > for (key,value) in my_dict: > #Do some stuff > > but I'm getting an error "Too many values to unpack". Use for (key,value) in mydict.iteritems(): ... otherwise you loop through just the keys, whicn in your dictionary happens to be 3-tuples. So you try to unpack a 3-tuple to a 2-tuple and get a too-many-values error. From python.list at tim.thechases.com Sun May 25 09:07:14 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 May 2014 08:07:14 -0500 Subject: Loop thru the dictionary with tuples In-Reply-To: <7x61kuc8uc.fsf@ruckus.brouhaha.com> References: <7x61kuc8uc.fsf@ruckus.brouhaha.com> Message-ID: <20140525080714.29e865f9@bigbox.christie.dr> On 2014-05-25 05:59, Paul Rubin wrote: > Igor Korot writes: > > for (key,value) in my_dict: > > #Do some stuff > > > > but I'm getting an error "Too many values to unpack". > > Use > for (key,value) in mydict.iteritems(): ... You can even use for ((k1,k2,k3), value) in mydict.iteritems(): ... if you need to unpack the key at the same time. -tkc -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From roy at panix.com Sun May 25 09:22:03 2014 From: roy at panix.com (Roy Smith) Date: Sun, 25 May 2014 09:22:03 -0400 Subject: Loop thru the dictionary with tuples References: Message-ID: In article , Igor Korot wrote: > for (key,value) in my_dict: > #Do some stuff > > but I'm getting an error "Too many values to unpack". Several people have already given you the right answer, so I'll just suggest a general debugging technique. Break this down into the smallest possible steps and print out the intermediate values. When you write: > for (key,value) in my_dict: two things are happening. One is that you're iterating over my_dict, the other is that you're unpacking the iterated-over things. So break those up into individual steps: for thing in my_dict: (key, value) = thing and see what that gives you. Do you still get an error? If so, does it occur on the "for" line or on the assignment line? Hint: in this case, it will happen on the assignment line, so, your next step is to print everything out and see what's going on: for thing in my_dict: print thing (key, value) = thing At this point, it should be obvious what's going on, but just in case it's not, sometimes I find it useful to be even more verbose: for thing in my_dict: print type(thing), repr(thing) (key, value) = thing From __peter__ at web.de Sun May 25 09:26:42 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 25 May 2014 15:26:42 +0200 Subject: Numpy Array of Sets References: <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> Message-ID: LJ wrote: > Wolfgang, thank you very much for your reply. > > Following the example in the link, the problem appears: > >>>> A = [[0]*2]*3 You can see this as a shortcut for value = 0 inner = [value, value] A = [inner, inner, inner] When the value is mutable (like your original set) a modification of the value shows in all six entries. Likewise if you change the `inner` list the modification shows in all three rows. >>>> A > [[0, 0], [0, 0], [0, 0]] >>>> A[0][0] = 5 >>>> A > [[5, 0], [5, 0], [5, 0]] > > Now, if I use a numpy array: > >>>> d=array([[0]*2]*3) >>>> d > array([[0, 0], > [0, 0], > [0, 0]]) >>>> d[0][0]=5 >>>> d > array([[5, 0], > [0, 0], > [0, 0]]) > > > What is the difference here? Basically a numpy array doesn't reference the lists, it uses them to determine the required shape of the array. A simplified implementation might be class Array: def __init__(self, data): self.shape = (len(data), len(data[0])) self._data = [] for row in data: self._data.extend(row) def __getitem__(self, index): y, x = index return self._data[y * self.shape[1] + x] With that approach you may only see simultaneous changes of multiple entries when using mutable values. From gandalf at shopzeus.com Sun May 25 09:32:24 2014 From: gandalf at shopzeus.com (=?ISO-8859-1?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Sun, 25 May 2014 15:32:24 +0200 Subject: compiled cx_freeze In-Reply-To: <22f6643f690f49d7a88178eccb9477fc@exch.activenetwerx.com> References: <5381A5C1.6000003@shopzeus.com> <22f6643f690f49d7a88178eccb9477fc@exch.activenetwerx.com> Message-ID: <5381F0E8.6090204@shopzeus.com> >> Anyone knows where to get a compiled cx_freeze that has already has this >> patch? > http://www.lfd.uci.edu/~gohlke/pythonlibs/#cx_freeze Unfortunately, this is buggy too. Here is a test output from a compiled console exe created with the above version of cx freeze: Traceback (most recent call last): File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in exec(code, m.__dict__) File "backup.py", line 6, in File "X:\Python34\lib\importlib\_bootstrap.py", line 2214, in _find_and_load File "X:\Python34\lib\importlib\_bootstrap.py", line 2203, in _find_and_load_unlocked File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible AttributeError: 'module' object has no attribute '_fix_up_module' This is clearly the aforementioned bootstrap bug. From ned at nedbatchelder.com Sun May 25 09:58:04 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 25 May 2014 09:58:04 -0400 Subject: Loop thru the dictionary with tuples In-Reply-To: References: Message-ID: On 5/25/14 8:55 AM, Igor Korot wrote: > Hi, ALL, > I have a following data structure: > > my_dict[(var1,var2,var3)] = None > my_dict[(var4,var5,var6)] = 'abc' > > What I'm trying to do is this: > > for (key,value) in my_dict: > #Do some stuff > > but I'm getting an error "Too many values to unpack". > > What am I doing wrong? > > Thank you. > You want: for key, value in my_dict.items(): # or .iteritems() Iterating over a dictionary gives you its keys. items() will give you key,value pairs. -- Ned Batchelder, http://nedbatchelder.com From rosuav at gmail.com Sun May 25 09:58:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 May 2014 23:58:55 +1000 Subject: Loop thru the dictionary with tuples In-Reply-To: References: Message-ID: On Sun, May 25, 2014 at 11:22 PM, Roy Smith wrote: > Hint: in this case, > it will happen on the assignment line, so, your next step is to print > everything out and see what's going on: > > for thing in my_dict: > print thing > (key, value) = thing Aside: I know that you (Roy) are still using Python 2, but the OP could be on either branch. As a matter of safety, I'd put parens around the print: for thing in my_dict: print(thing) (key, value) = thing That way, it works on either. ChrisA From luisjosenovoa at gmail.com Sun May 25 10:14:13 2014 From: luisjosenovoa at gmail.com (LJ) Date: Sun, 25 May 2014 07:14:13 -0700 (PDT) Subject: Numpy Array of Sets In-Reply-To: References: <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> Message-ID: <9929f123-705c-4656-a400-171e48935244@googlegroups.com> Thank you for the reply. So, as long as I access and modify the elements of, for example, A=array([[set([])]*4]*3) as (for example): a[0][1] = a[0][1] | set([1,2]) or: a[0][1]=set([1,2]) then I should have no problems? From jcasale at activenetwerx.com Sun May 25 10:21:16 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 25 May 2014 14:21:16 +0000 Subject: compiled cx_freeze In-Reply-To: <5381F0E8.6090204@shopzeus.com> References: <5381A5C1.6000003@shopzeus.com> <22f6643f690f49d7a88178eccb9477fc@exch.activenetwerx.com> <5381F0E8.6090204@shopzeus.com> Message-ID: <804c5f4fb64244e8a504e2410f8be878@exch.activenetwerx.com> > Unfortunately, this is buggy too. Here is a test output from a compiled > console exe created with the above version of cx freeze: Let Christoph know, he is very responsive and extremely helpful. From __peter__ at web.de Sun May 25 11:12:25 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 25 May 2014 17:12:25 +0200 Subject: Numpy Array of Sets References: <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> <9929f123-705c-4656-a400-171e48935244@googlegroups.com> Message-ID: LJ wrote: > Thank you for the reply. > > So, as long as I access and modify the elements of, for example, > > A=array([[set([])]*4]*3) > > > as (for example): > > a[0][1] = a[0][1] | set([1,2]) > > or: > > a[0][1]=set([1,2]) > > then I should have no problems? As long as you set (i. e. replace) elements you're fine, but modifying means trouble. You can prevent accidental modification by using immutable values -- in your case frozenset: >>> b = numpy.array([[frozenset()]*4]*3) >>> b[0,0].update("123") Traceback (most recent call last): File "", line 1, in AttributeError: 'frozenset' object has no attribute 'update' Or you take the obvious approach and ensure that there are no shared values. I don't know if there's a canonical form to do this in numpy, but >>> a = numpy.array([[set()]*3]*4) >>> a |= set() works: >>> assert len(set(map(id, a.flat))) == 3*4 From luisjosenovoa at gmail.com Sun May 25 11:17:34 2014 From: luisjosenovoa at gmail.com (LJ) Date: Sun, 25 May 2014 08:17:34 -0700 (PDT) Subject: Numpy Array of Sets In-Reply-To: References: <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> <9929f123-705c-4656-a400-171e48935244@googlegroups.com> Message-ID: Thank you very much! From ethan at stoneleaf.us Sun May 25 11:21:18 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 25 May 2014 08:21:18 -0700 Subject: How keep Python 3 moving forward In-Reply-To: <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> Message-ID: <53820A6E.8090900@stoneleaf.us> On 05/24/2014 11:43 PM, wxjmfauth at gmail.com wrote: > > Python and unicode: a buggy hobbyist toy. > Voil?. Nothing either good or bad. I thought this was a moderated list. What exactly are the moderators doing? -- ~Ethan~ From rosuav at gmail.com Sun May 25 11:52:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 May 2014 01:52:06 +1000 Subject: How keep Python 3 moving forward In-Reply-To: <53820A6E.8090900@stoneleaf.us> References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <53820A6E.8090900@stoneleaf.us> Message-ID: On Mon, May 26, 2014 at 1:21 AM, Ethan Furman wrote: > On 05/24/2014 11:43 PM, wxjmfauth at gmail.com wrote: >> >> >> Python and unicode: a buggy hobbyist toy. >> Voil?. Nothing either good or bad. > > > I thought this was a moderated list. What exactly are the moderators doing? It's not a moderated list. We just collectively ignore the (few) people who aren't saying anything worth reading. ChrisA From dimmaim at gmail.com Sun May 25 12:01:29 2014 From: dimmaim at gmail.com (dimmaim at gmail.com) Date: Sun, 25 May 2014 09:01:29 -0700 (PDT) Subject: How to pass variable through scipts Message-ID: My code has this structure: class Example(wx.Frame,listmix.ColumnSorterMixin): def __init__(self,parent): wx.Frame.__init__(self,parent) self.InitUI() def InitUI(self): ..... some other functions and other stuff when a button is clicked this function is called and i take the self.id_number which is a number def OnB(self, event): self.id_number = self.text_ctrl_number.GetValue() xx = latitude[int(self.id_number)] yy = longitude[int(self.id_number)] i want to pass the variables xx and yy to a different script called application. This script by calling it with import, automatically pop up a window. I need by clicking the button that is linked with OnB definition to pop up the window from the other script as it does when i am running it alone and display lets say for example the variables xx and yy, how can i do it From breamoreboy at yahoo.co.uk Sun May 25 12:32:24 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 25 May 2014 17:32:24 +0100 Subject: How keep Python 3 moving forward In-Reply-To: <53820A6E.8090900@stoneleaf.us> References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <53820A6E.8090900@stoneleaf.us> Message-ID: On 25/05/2014 16:21, Ethan Furman wrote: > On 05/24/2014 11:43 PM, wxjmfauth at gmail.com wrote: >> >> Python and unicode: a buggy hobbyist toy. >> Voil?. Nothing either good or bad. > > I thought this was a moderated list. What exactly are the moderators > doing? > > -- > ~Ethan~ > I don't think the list is moderated. I do think this guy has had thirty strikes rather than three, so isn't it time he was finally given out? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From chris at simplistix.co.uk Sun May 25 12:44:41 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Sun, 25 May 2014 17:44:41 +0100 Subject: testfixtures 3.1.0 Released! Message-ID: <53821DF9.4030900@simplistix.co.uk> Hi All, I'm pleased to announce the release of testfixtures 3.1.0. This is a new feature and bug fix release featuring the following changes: - New RoundComparison object for comparing numbers to a given precision - New 'unless' parameter to ShouldRaise, for situations where an exception is raised in Python 2 but not Python 3. - Fixes for missing imports in fix for rare failures when cleaning up TempDirectory instances on Windows. The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: http://www.simplistix.co.uk/software/python/testfixtures Any questions, please do ask on the Testing in Python list or on the Simplistix open source mailing list... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rosuav at gmail.com Sun May 25 13:07:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 May 2014 03:07:12 +1000 Subject: How to pass variable through scipts In-Reply-To: References: Message-ID: On Mon, May 26, 2014 at 2:01 AM, wrote: > i want to pass the variables xx and yy to a different script called application. This script by calling it with import, automatically pop up a window. I need by clicking the button that is linked with OnB definition to pop up the window from the other script as it does when i am running it alone and display lets say for example the variables xx and yy, how can i do it > When you import another script, you gain access to its functions and classes and such. All you need to do is write your function to take a couple of arguments, and then pass xx and yy as those arguments. I recommend you read and work through the Python tutorial - one of these, depending on which version of Python you use: https://docs.python.org/2/tutorial/ https://docs.python.org/3/tutorial/ It'll explain a lot of these sorts of things. Chris Angelico From memilanuk at gmail.com Sun May 25 13:25:59 2014 From: memilanuk at gmail.com (memilanuk) Date: Sun, 25 May 2014 10:25:59 -0700 Subject: Shared web hosting where python is *not* a second class citizen Message-ID: Right now we have a fairly basic shared hosting plan via bluehost.com, running WordPress for a club web site. I've looked at setting up python on this account, but the default is the version of python that comes with the OS (CentOS 5.x currently). There are some basic instructions on upgrading that at a user level to 2.7... but nothing for python3, and most of the python posts in their user forums go unanswered. Not exactly confidence inspiring! The irony is that one of my web searches included a review of shared hosting and listed BlueHost as the number one recommendation! So I'm left wondering if there is someplace that people here would recommend (for this kind of plan or others) where python isn't a second class citizen. Really not interested (for my current uses) in a VPS. I just want some place where it doesn't feel like python support is some sort of bone thrown out there just to say that they 'support' python. Monte From mail at timgolden.me.uk Sun May 25 13:29:09 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 25 May 2014 18:29:09 +0100 Subject: Shared web hosting where python is *not* a second class citizen In-Reply-To: References: Message-ID: <53822865.3060401@timgolden.me.uk> On 25/05/2014 18:25, memilanuk wrote: > Right now we have a fairly basic shared hosting plan via bluehost.com, > running WordPress for a club web site. I've looked at setting up python > on this account, but the default is the version of python that comes > with the OS (CentOS 5.x currently). There are some basic instructions > on upgrading that at a user level to 2.7... but nothing for python3, and > most of the python posts in their user forums go unanswered. Not > exactly confidence inspiring! The irony is that one of my web searches > included a review of shared hosting and listed BlueHost as the number > one recommendation! > > So I'm left wondering if there is someplace that people here would > recommend (for this kind of plan or others) where python isn't a second > class citizen. Really not interested (for my current uses) in a VPS. I > just want some place where it doesn't feel like python support is some > sort of bone thrown out there just to say that they 'support' python. Webfaction. Without a doubt TJG From kwpolska at gmail.com Sun May 25 13:32:09 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sun, 25 May 2014 19:32:09 +0200 Subject: Shared web hosting where python is *not* a second class citizen In-Reply-To: References: Message-ID: On Sun, May 25, 2014 at 7:25 PM, memilanuk wrote: > Right now we have a fairly basic shared hosting plan via bluehost.com, > running WordPress for a club web site. I've looked at setting up python > on this account, but the default is the version of python that comes > with the OS (CentOS 5.x currently). There are some basic instructions on > upgrading that at a user level to 2.7... but nothing for python3, and most > of the python posts in their user forums go unanswered. Not exactly > confidence inspiring! The irony is that one of my web searches included a > review of shared hosting and listed BlueHost as the number one > recommendation! > > So I'm left wondering if there is someplace that people here would recommend > (for this kind of plan or others) where python isn't a second class citizen. > Really not interested (for my current uses) in a VPS. I just want some > place where it doesn't feel like python support is some sort of bone thrown > out there just to say that they 'support' python. Heroku, Google App Engine, or pretty much any other Platform-as-a-Service provider. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From rustompmody at gmail.com Sun May 25 13:38:42 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 25 May 2014 10:38:42 -0700 (PDT) Subject: How keep Python 3 moving forward In-Reply-To: References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> Message-ID: <7b84454a-3ff9-4d68-bb53-77c0fd9f333a@googlegroups.com> On Sunday, May 25, 2014 8:51:18 PM UTC+5:30, Ethan Furman wrote: > On 05/24/2014 11:43 PM, jmf wrote: > > > > Python and unicode: a buggy hobbyist toy. > > Voil???. Nothing either good or bad. > > > I thought this was a moderated list. What exactly are the moderators doing? Your unicode is mojibaked Ethan! Voil???. You are hereby banished to a lonely island with python 1.5 and jmf for company :D From gandalf at shopzeus.com Sun May 25 13:40:56 2014 From: gandalf at shopzeus.com (=?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Sun, 25 May 2014 19:40:56 +0200 Subject: win32serviceutil: ImportError: DLL load failed: The specified module could not be found Message-ID: <53822B28.4070609@shopzeus.com> >>> import win32service Traceback (most recent call last): File "", line 1, in ImportError: DLL load failed: The specified module could not be found I have no problem loading the same module with Python 2.7. Strange thing is that win32serviceutil.py is part of the pywin32 distribution, so I guess I should be able to import it, right? From roy at panix.com Sun May 25 14:03:43 2014 From: roy at panix.com (Roy Smith) Date: Sun, 25 May 2014 14:03:43 -0400 Subject: How keep Python 3 moving forward References: Message-ID: In article , Stefan Behnel wrote: > Ubuntu provides a (partial) Py3 port of boto. As long as the part that's ported includes all the bits of boto we currently need, plus all the bits of boto we haven't yet discovered we need, but will sometime in the future, we're good :-) > And I don't really see why you would consider fabric a dependency > that keeps you from switching to Py3. In many cases, you can just > keep running it in Py2 as you did before. In theory, that's possible. In practice, it would mean having to maintain two different versions of Python, and test everything against both. That adds a lot of complexity, for very little value. From steve+comp.lang.python at pearwood.info Sun May 25 14:17:47 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2014 18:17:47 GMT Subject: How keep Python 3 moving forward References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <7b84454a-3ff9-4d68-bb53-77c0fd9f333a@googlegroups.com> Message-ID: <538233cb$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 25 May 2014 10:38:42 -0700, Rustom Mody wrote: > On Sunday, May 25, 2014 8:51:18 PM UTC+5:30, Ethan Furman wrote: >> On 05/24/2014 11:43 PM, jmf wrote: >> > >> > Python and unicode: a buggy hobbyist toy. Voil???. Nothing either >> > good or bad. >> >> >> I thought this was a moderated list. What exactly are the moderators >> doing? > > > Your unicode is mojibaked Ethan! Voil???. You are hereby banished to a > lonely island with python 1.5 and jmf for company :D Nope, it's you. Ethan's post is fine. He correctly quotes JMF stating "Voil?" (that's LATIN SMALL LETTER A WITH GRAVE), and Ethan's post correctly gives an encoding header: Content-Type: text/plain; charset=iso-8859-1; format=flowed (although, boo to Thunderbird for using a legacy encoding instead of UTF-8). So his post is fine. Whatever the problem is, it's at your end. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ch2009 at arcor.de Sun May 25 08:22:08 2014 From: ch2009 at arcor.de (Chris) Date: Sun, 25 May 2014 14:22:08 +0200 Subject: WSGI In-Reply-To: References: <20140519205252.264fc764@bigbox.christie.dr> Message-ID: <5381E070.90806@arcor.de> On 05/25/2014 12:04 PM, alister wrote: > is your apache server running as root? > if so it probably should be corrected One is running as chris, the others as apache: [root at t-centos1 ~]# ps -ef|grep httpd root 1199 1 0 08:47 ? 00:00:01 /usr/sbin/httpd chris 1293 1199 0 09:47 ? 00:00:00 /usr/sbin/httpd apache 1294 1199 0 09:47 ? 00:00:00 /usr/sbin/httpd apache 1295 1199 0 09:47 ? 00:00:00 /usr/sbin/httpd apache 1296 1199 0 09:47 ? 00:00:00 /usr/sbin/httpd apache 1297 1199 0 09:47 ? 00:00:00 /usr/sbin/httpd apache 1298 1199 0 09:47 ? 00:00:00 /usr/sbin/httpd apache 1299 1199 0 09:47 ? 00:00:00 /usr/sbin/httpd apache 1300 1199 0 09:47 ? 00:00:00 /usr/sbin/httpd apache 1301 1199 0 09:47 ? 00:00:00 /usr/sbin/httpd root 1578 1566 0 14:21 pts/0 00:00:00 grep httpd -- Gru?, Christian From python.list at tim.thechases.com Sun May 25 14:56:08 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 May 2014 13:56:08 -0500 Subject: How keep Python 3 moving forward In-Reply-To: <538233cb$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <7b84454a-3ff9-4d68-bb53-77c0fd9f333a@googlegroups.com> <538233cb$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140525135608.7a5ecb99@bigbox.christie.dr> On 2014-05-25 18:17, Steven D'Aprano wrote: > On Sun, 25 May 2014 10:38:42 -0700, Rustom Mody wrote: > > Your unicode is mojibaked Ethan! Voil???. You are hereby > > banished to a lonely island with python 1.5 and jmf for company :D > > Nope, it's you. Ethan's post is fine. He correctly quotes JMF > stating "Voil?" (that's LATIN SMALL LETTER A WITH GRAVE), and > Ethan's post correctly gives an encoding header: > > Content-Type: text/plain; charset=iso-8859-1; format=flowed I corroborate Steven's findings, that Ethan's post was correctly encoded & displayed. > (although, boo to Thunderbird for using a legacy encoding instead > of UTF-8). So his post is fine. Whatever the problem is, it's at > your end. Thunderbird does offer the ability to change default character encodings (Edit -> Preferences -> Display -> Formatting tab -> Advanced...) for sending and receiving, but you have to go out of your way to change them to something like UTF-8. On the same preferences screen TB provides the option to "when possible, use the default character encoding in replies". -tkc From ethan at stoneleaf.us Sun May 25 14:34:59 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 25 May 2014 11:34:59 -0700 Subject: How keep Python 3 moving forward In-Reply-To: <7b84454a-3ff9-4d68-bb53-77c0fd9f333a@googlegroups.com> References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <7b84454a-3ff9-4d68-bb53-77c0fd9f333a@googlegroups.com> Message-ID: <538237D3.8080700@stoneleaf.us> On 05/25/2014 10:38 AM, Rustom Mody wrote: > > Your unicode is mojibaked Ethan! Voil???. > You are hereby banished to a lonely island with python 1.5 and jmf for company :D 1.5 I could live with. :( Surely the company would count as cruel and unusual punishment? -- ~Ethan~ From breamoreboy at yahoo.co.uk Sun May 25 16:24:54 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 25 May 2014 21:24:54 +0100 Subject: How keep Python 3 moving forward In-Reply-To: <538237D3.8080700@stoneleaf.us> References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <7b84454a-3ff9-4d68-bb53-77c0fd9f333a@googlegroups.com> <538237D3.8080700@stoneleaf.us> Message-ID: On 25/05/2014 19:34, Ethan Furman wrote: > On 05/25/2014 10:38 AM, Rustom Mody wrote: >> >> Your unicode is mojibaked Ethan! Voil???. >> You are hereby banished to a lonely island with python 1.5 and jmf for >> company :D > > 1.5 I could live with. :( Surely the company would count as cruel and > unusual punishment? > > -- > ~Ethan~ The latter is definitely true, but does being king make up for it, on the grounds that he's clearly blind? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ethan at stoneleaf.us Sun May 25 16:18:28 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 25 May 2014 13:18:28 -0700 Subject: How keep Python 3 moving forward In-Reply-To: <20140525135608.7a5ecb99@bigbox.christie.dr> References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <7b84454a-3ff9-4d68-bb53-77c0fd9f333a@googlegroups.com> <538233cb$0$29978$c3e8da3$5496439d@news.astraweb.com> <20140525135608.7a5ecb99@bigbox.christie.dr> Message-ID: <53825014.5070805@stoneleaf.us> On 05/25/2014 11:56 AM, Tim Chase wrote: > > Thunderbird does offer the ability to change default character > encodings (Edit -> Preferences -> Display -> Formatting tab -> > Advanced...) for sending and receiving, but you have to go out of your > way to change them to something like UTF-8. On the same preferences > screen TB provides the option to "when possible, use the default > character encoding in replies". Thanks, fixed. :) -- ~Ethan~ From tjreedy at udel.edu Sun May 25 17:49:32 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 25 May 2014 17:49:32 -0400 Subject: win32serviceutil: ImportError: DLL load failed: The specified module could not be found In-Reply-To: <53822B28.4070609@shopzeus.com> References: <53822B28.4070609@shopzeus.com> Message-ID: On 5/25/2014 1:40 PM, Nagy L?szl? Zsolt wrote: > >>> import win32service > Traceback (most recent call last): > File "", line 1, in > ImportError: DLL load failed: The specified module could not be found > > I have no problem loading the same module with Python 2.7. So the above is with ??? > Strange thing is that win32serviceutil.py is part of the pywin32 > distribution, so I guess I should be able to import it, right? Make sure you have a pywin32 that matches ???. Matching includes python version and bitness. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sun May 25 19:09:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 26 May 2014 00:09:31 +0100 Subject: How keep Python 3 moving forward In-Reply-To: References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <7b84454a-3ff9-4d68-bb53-77c0fd9f333a@googlegroups.com> <538237D3.8080700@stoneleaf.us> Message-ID: On 25/05/2014 23:22, Dennis Lee Bieber wrote: > On Sun, 25 May 2014 11:34:59 -0700, Ethan Furman > declaimed the following: > >> On 05/25/2014 10:38 AM, Rustom Mody wrote: >>> >>> Your unicode is mojibaked Ethan! Voil???. >>> You are hereby banished to a lonely island with python 1.5 and jmf for company :D >> >> 1.5 I could live with. :( Surely the company would count as cruel and >> unusual punishment? >> > "company"... Or emergency rations? > I suspect that chewing razor blades would be preferable to listening to the permanent rant about what's wrong with the FSR. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From memilanuk at gmail.com Sun May 25 19:53:15 2014 From: memilanuk at gmail.com (memilanuk) Date: Sun, 25 May 2014 16:53:15 -0700 Subject: Shared web hosting where python is *not* a second class citizen In-Reply-To: <53822865.3060401@timgolden.me.uk> References: <53822865.3060401@timgolden.me.uk> Message-ID: On 05/25/2014 10:29 AM, Tim Golden wrote: > On 25/05/2014 18:25, memilanuk wrote: >> So I'm left wondering if there is someplace that people here would >> recommend (for this kind of plan or others) where python isn't a second >> class citizen. Really not interested (for my current uses) in a VPS. I >> just want some place where it doesn't feel like python support is some >> sort of bone thrown out there just to say that they 'support' python. > > > Webfaction. Without a doubt > Wow! Webfaction looks like it is *exactly* what I'm looking for. Thanks, Monte From rosuav at gmail.com Sun May 25 20:24:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 May 2014 10:24:41 +1000 Subject: How keep Python 3 moving forward In-Reply-To: References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <7b84454a-3ff9-4d68-bb53-77c0fd9f333a@googlegroups.com> <538237D3.8080700@stoneleaf.us> Message-ID: On Mon, May 26, 2014 at 8:22 AM, Dennis Lee Bieber wrote: > On Sun, 25 May 2014 11:34:59 -0700, Ethan Furman > declaimed the following: > >>On 05/25/2014 10:38 AM, Rustom Mody wrote: >>> >>> Your unicode is mojibaked Ethan! Voil???. >>> You are hereby banished to a lonely island with python 1.5 and jmf for company :D >> >>1.5 I could live with. :( Surely the company would count as cruel and >>unusual punishment? >> > "company"... Or emergency rations? Unfortunately not as effective as these guys: http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=46017 ChrisA From ethan at stoneleaf.us Sun May 25 20:32:55 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 25 May 2014 17:32:55 -0700 Subject: How keep Python 3 moving forward In-Reply-To: References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <7b84454a-3ff9-4d68-bb53-77c0fd9f333a@googlegroups.com> <538237D3.8080700@stoneleaf.us> Message-ID: <53828BB7.8080006@stoneleaf.us> On 05/25/2014 03:22 PM, Dennis Lee Bieber wrote: > On Sun, 25 May 2014 11:34:59 -0700, Ethan Furman > declaimed the following: > >> On 05/25/2014 10:38 AM, Rustom Mody wrote: >>> >>> Your unicode is mojibaked Ethan! Voil?. >>> You are hereby banished to a lonely island with python 1.5 and jmf for company :D >> >> 1.5 I could live with. :( Surely the company would count as cruel and >> unusual punishment? >> > "company"... Or emergency rations? Well, the thought had crossed my mind... I guess the deciding factor would have to be if I had any ketchup. -- ~Ethan~ From tjreedy at udel.edu Sun May 25 21:32:08 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 25 May 2014 21:32:08 -0400 Subject: How keep Python 3 moving forward In-Reply-To: References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <53820A6E.8090900@stoneleaf.us> Message-ID: On 5/25/2014 6:20 PM, Dennis Lee Bieber wrote: > the mailing > list and gmane group may have some spam filters in place but no real > moderation. They *do* have spam, structure, and source filters. Please do not mis-inform people that they post most anything to python-list without consequence. -- Terry Jan Reedy From codemonkey at inbox.com Sun May 25 19:55:34 2014 From: codemonkey at inbox.com (Deb Wyatt) Date: Sun, 25 May 2014 15:55:34 -0800 Subject: confused about the different built-in functions in Python Message-ID: <648E6136A80.00000651codemonkey@inbox.com> An HTML attachment was scrubbed... URL: From gheskett at wdtv.com Sun May 25 20:45:11 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 25 May 2014 20:45:11 -0400 Subject: How keep Python 3 moving forward In-Reply-To: References: <538237D3.8080700@stoneleaf.us> Message-ID: <201405252045.11424.gheskett@wdtv.com> On Sunday 25 May 2014 18:22:11 Dennis Lee Bieber did opine And Gene did reply: > On Sun, 25 May 2014 11:34:59 -0700, Ethan Furman > > declaimed the following: > >On 05/25/2014 10:38 AM, Rustom Mody wrote: > >> Your unicode is mojibaked Ethan! Voil???. > >> You are hereby banished to a lonely island with python 1.5 and jmf > >> for company :D > > > >1.5 I could live with. :( Surely the company would count as cruel > >and unusual punishment? > > "company"... Or emergency rations? Humm, now thats a thought... Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From davea at davea.name Sun May 25 22:09:28 2014 From: davea at davea.name (Dave Angel) Date: Sun, 25 May 2014 22:09:28 -0400 (EDT) Subject: Loop thru the dictionary with tuples References: Message-ID: Ned Batchelder Wrote in message: > On 5/25/14 8:55 AM, Igor Korot wrote: >> Hi, ALL, >> I have a following data structure: >> >> my_dict[(var1,var2,var3)] = None >> my_dict[(var4,var5,var6)] = 'abc' >> >> What I'm trying to do is this: >> >> for (key,value) in my_dict: >> #Do some stuff >> >> but I'm getting an error "Too many values to unpack". >> >> What am I doing wrong? >> >> Thank you. >> > > You want: > > for key, value in my_dict.items(): # or .iteritems() > > Iterating over a dictionary gives you its keys. items() will give you > key,value pairs. Or, if the dict is large, you might want for key in my_dict: value = my_dict [key] ... -- DaveA From ned at nedbatchelder.com Sun May 25 22:12:19 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 25 May 2014 22:12:19 -0400 Subject: confused about the different built-in functions in Python In-Reply-To: <648E6136A80.00000651codemonkey@inbox.com> References: <648E6136A80.00000651codemonkey@inbox.com> Message-ID: On 5/25/14 7:55 PM, Deb Wyatt wrote: > I am confused about how various built-in functions are called. Some are > called with dot notation > > each_item.isalpha() > > and some are called like 'normal' > > sum(numlist) > > How do you know/remember which way to call them? > > TIA, > Deb in WA, USA It can be confusing. Generally, built-in functions (like sum, len, etc) are used when the operation could apply to many different types. For example, sum() can be used with any iterable that produces addable things. Operations that are defined only for a single type (like .isalpha as a string operation) are usually defined as methods on the type. This is not a black/white distinction, I'm sure there are interesting counter-examples. But this is the general principle. -- Ned Batchelder, http://nedbatchelder.com From ned at nedbatchelder.com Sun May 25 22:13:57 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 25 May 2014 22:13:57 -0400 Subject: Loop thru the dictionary with tuples In-Reply-To: References: Message-ID: On 5/25/14 10:09 PM, Dave Angel wrote: > Ned Batchelder Wrote in message: >> On 5/25/14 8:55 AM, Igor Korot wrote: >>> Hi, ALL, >>> I have a following data structure: >>> >>> my_dict[(var1,var2,var3)] = None >>> my_dict[(var4,var5,var6)] = 'abc' >>> >>> What I'm trying to do is this: >>> >>> for (key,value) in my_dict: >>> #Do some stuff >>> >>> but I'm getting an error "Too many values to unpack". >>> >>> What am I doing wrong? >>> >>> Thank you. >>> >> >> You want: >> >> for key, value in my_dict.items(): # or .iteritems() >> >> Iterating over a dictionary gives you its keys. items() will give you >> key,value pairs. > > > Or, if the dict is large, you might want > > for key in my_dict: > value = my_dict [key] > ... For a large dict, .iteritems (Python 2) or .items (Python 3) are perfectly fine and don't have a cost to avoid. .items (Python 2) produces a list, which would be bad. -- Ned Batchelder, http://nedbatchelder.com From cs at zip.com.au Sun May 25 22:36:58 2014 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 26 May 2014 12:36:58 +1000 Subject: confused about the different built-in functions in Python In-Reply-To: <648E6136A80.00000651codemonkey@inbox.com> References: <648E6136A80.00000651codemonkey@inbox.com> Message-ID: <20140526023658.GA50792@cskk.homeip.net> On 25May2014 15:55, Deb Wyatt wrote: >I am confused about how various built-in functions are called. Some are >called with dot notation > >each_item.isalpha() > >and some are called like 'normal' > >sum(numlist) > >How do you know/remember which way to call them? Documentation. However, some context: each_item.isalpha() is not a builtin function as such. It is a method of the "str" class. Whereas "sum" _is_ a builtin function, a globally known name which can be accessed and used without explicitly importing any module. There's an explicit list of the builtin functions in the Python doco. For a class, you can look at the doco for the class ("String methods" in the python doco, for the "str" class), or run: help(str) at the interactive Python prompt. Cheers, Cameron Simpson Steinbach's Law: 2 is not equal to 3 -- even for large values of 2. From cs at zip.com.au Sun May 25 22:47:04 2014 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 26 May 2014 12:47:04 +1000 Subject: os.stat and time zones In-Reply-To: <5381D85E.8010502@shopzeus.com> References: <5381D85E.8010502@shopzeus.com> Message-ID: <20140526024704.GA60311@cskk.homeip.net> On 25May2014 13:47, Nagy L?szl? Zsolt wrote: >This might be a silly question. Documentation of os.stat: > >>The exact meaning and resolution of the st_atime, st_mtime, and >>st_ctime attributes depend on the operating system and the file >>system. For example, on Windows systems using the FAT or FAT32 file >>systems, st_mtime has 2-second resolution, and st_atime has only >>1-day resolution. See your operating system documentation for >>details. >So it says that the meaning is platform dependent. > >But here is something interesting. Supposedly, os.stat(fpath).st_mtime >and os.path.getmtime(path) return the same thing. The documentation of >os.path.getmtime says that it "returns the number of seconds since the >epoch". And the time module says that "To find out what the epoch is, >look at gmtime(0)". And the documentation of gmtime says that it >converts the given value to a struct_time *that is in UTC*. > >If the above are true, then as far as I can see, the meaning of >st_mtime is NOT platform dependent. It always means the number of >seconds elapsed since the epoch in UTC. You have conflated two things here. The "offset since the epoch" is a number of seconds since a (platform dependent) epoch: the "start of time" for the OS time counters on that system. It has _nothing_ to do with UTC. As far as st_atime and friends go, the epoch itself is platform dependent and so is the resolution (FAT filesystems having lower precision than might seem sane, probably to get a longer time range from a small field). The field names come from POSIX, which comes from UNIX. The .st_atime etc field names are still presented on Windows to make code more portable. But Windows has a different epoch (UNIX time starts at the beginning of 1 January 1970; that is its "epoch"). The gmtime() function takes the platform dependent offset-from-epoch and gives you a struct_time, which has human friendly date and hours/minutes/etc fields. These necessarily must be in a timezone, and UTC is a common frame of reference and the zone returned by gmtime() ("gmt" means GMT, Greenwich Mean Time, which is close to a synonym for UTC). Between Windows and UNIX, the differences are the resolution and the epoch. UTC is not platform dependent and not called so by the doco. That also makes it a useful zone to pass around in some contexts. Cheers, Cameron Simpson From ben at benfinney.id.au Sun May 25 23:16:10 2014 From: ben at benfinney.id.au (Ben Finney) Date: Mon, 26 May 2014 13:16:10 +1000 Subject: Build tools, and Python 3 dependencies (was: How keep Python 3 moving forward) References: Message-ID: <85a9a55ix1.fsf_-_@benfinney.id.au> Roy Smith writes: > Stefan Behnel wrote: > > > And I don't really see why you would consider fabric a dependency > > that keeps you from switching to Py3. In many cases, you can just > > keep running it in Py2 as you did before. > > In theory, that's possible. In practice, it would mean having to > maintain two different versions of Python Why would using Fabric ? a build tool ? require you to ?maintain two different versions of Python?? You only need to maintain the build scripts, not Python itself. > and test everything against both. That makes even less sense. The build system runs under whatever version of Python it needs, and your code runs under whatever version of Python you like. The two don't affect each other at run time, and don't affect each other's testing dependencies. How would Fabric's dependency on Python 2 require you to ?test everything against both [Python 2 and Python 3]?? Fabric needs Python 2 (for now), but your code doesn't. At least one of us seems to be misunderstanding what is required. -- \ ?Science and religion are incompatible in the same sense that | `\ the serious pursuit of knowledge of reality is incompatible | _o__) with bullshit.? ?Paul Z. Myers, 2010-03-14 | Ben Finney From ben at benfinney.id.au Sun May 25 23:20:22 2014 From: ben at benfinney.id.au (Ben Finney) Date: Mon, 26 May 2014 13:20:22 +1000 Subject: Make Python Compilable, convert to Python source to Go References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: <8561kt5iq1.fsf@benfinney.id.au> bookaa bookaa writes: > Generally, people consider Python as a script language. Count me as one who does not. Python is a general-purpose language. > It has high development efficiency True. > but run too slowly Which Python implementation are you talking about? Run time is not a property of the language. It is a property of the language implementation. > interpret running, and can not compile. Python is always compiled in order to run. The process of turning Python source into Python bytecode *is* compilation. > It depends to Python environment, can not employ alone. True. > For years, many people have do a lot of job try to improve running > speed of Python, include Pypy, Cython. But all of these are not > satisfied. I don't know what this sweeping statement means. Who is not satisfied? There are a great many people who are satisfied with Python for many general purpose needs. Python is not ?a scripting language?, it's general purpose. It is compiled. It has many implementations and some are faster than others. So I think you'll need to work on your arguments some more, in order to justify what points you're making. -- \ ?? it's best to confuse only one issue at a time.? ?Brian W. | `\ Kernighan and Dennis M. Ritchie, _The C programming language_, | _o__) 1988 | Ben Finney From ben at benfinney.id.au Sun May 25 23:33:09 2014 From: ben at benfinney.id.au (Ben Finney) Date: Mon, 26 May 2014 13:33:09 +1000 Subject: os.stat and time zones References: <5381D85E.8010502@shopzeus.com> Message-ID: <851tvh5i4q.fsf@benfinney.id.au> Nagy L?szl? Zsolt writes: > This might be a silly question. Documentation of os.stat: > > > The exact meaning and resolution of the st_atime, st_mtime, and > > st_ctime attributes depend on the operating system and the file > > system. For example, on Windows systems using the FAT or FAT32 file > > systems, st_mtime has 2-second resolution, and st_atime has only > > 1-day resolution. See your operating system documentation for > > details. > So it says that the meaning is platform dependent. It says what it means: ?The exact meaning and resolution of the st_atime, st_mtime, and st_ctime attributes depend on the operating system and the file system.? That doesn't mean quite what you've said in your paraphrase. > But here is something interesting. Supposedly, os.stat(fpath).st_mtime > and os.path.getmtime(path) return the same thing. The implementation of ?os? is platform-dependent. So, the meaning of the return value of ?os.stat? and of ?os.path.getmtime? will also be platform-dependent. > If the above are true, then as far as I can see, the meaning of > st_mtime is NOT platform dependent. You've missed the part where the ?os? module is platform-dependent, and hence the ?os.stat? behaviour is platform-dependent. > It always means the number of seconds elapsed since the epoch in UTC. The time elapsed doesn't change in meaning. The meaning of ?modification time? (and ?creation time?, and ?access time?) is what changes, because different filesystems and different operating systems have different meanings for those. > So what is the truth? What other difference can be in the meaning that > is platform dependent? Read up on the different filesystems implemented on the operating systems and filesystems relevant to you, and what meanings are assigned by each specific filesystem to those timestamps. -- \ Moriarty: ?Forty thousand million billion dollars? That money | `\ must be worth a fortune!? ?The Goon Show, _The Sale of | _o__) Manhattan_ | Ben Finney From garg.pankaj83 at gmail.com Mon May 26 02:15:53 2014 From: garg.pankaj83 at gmail.com (garg.pankaj83 at gmail.com) Date: Sun, 25 May 2014 23:15:53 -0700 (PDT) Subject: Standard Delay Format (SDF) Parsing In-Reply-To: References: Message-ID: <0c3541a3-5a28-4d21-8b7a-bc68fb4b8f82@googlegroups.com> Hi Steven, did you get the module to parse the sdf file? regards, pankaj From gandalf at shopzeus.com Mon May 26 02:20:26 2014 From: gandalf at shopzeus.com (=?UTF-8?B?TmFneSBMw6FzemzDsyBac29sdA==?=) Date: Mon, 26 May 2014 08:20:26 +0200 Subject: win32serviceutil: ImportError: DLL load failed: The specified module could not be found In-Reply-To: References: <53822B28.4070609@shopzeus.com> Message-ID: <5382DD2A.6040304@shopzeus.com> 2014.05.25. 23:49 keltez?ssel, Terry Reedy ?rta: > On 5/25/2014 1:40 PM, Nagy L?szl? Zsolt wrote: >> >>> import win32service >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: DLL load failed: The specified module could not be found >> >> I have no problem loading the same module with Python 2.7. > > So the above is with ??? Is with 3.4 amd64 > >> Strange thing is that win32serviceutil.py is part of the pywin32 >> distribution, so I guess I should be able to import it, right? > > Make sure you have a pywin32 that matches ???. Matching includes > python version and bitness. It does. Installed Python 3.4.1 (64-bit) and pywin32-219 (64-bit) taken from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32 From jeanpierreda at gmail.com Mon May 26 02:31:54 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 25 May 2014 23:31:54 -0700 Subject: Make Python Compilable, convert to Python source to Go In-Reply-To: References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: On Sun, May 25, 2014 at 3:24 AM, Mark Lawrence wrote: > On 25/05/2014 09:17, bookaa bookaa wrote: >> >> Maybe I will work on Python 3 later. >> > > That's good to know, it'll save me wasting my time looking at it now. This seems like an unnecessarily harsh way of putting it, Mark. Could you be less dismissive of the hard work others put into improving the Python world? -- Devin From moogyd at yahoo.co.uk Mon May 26 03:08:47 2014 From: moogyd at yahoo.co.uk (moogyd at yahoo.co.uk) Date: Mon, 26 May 2014 00:08:47 -0700 (PDT) Subject: Standard Delay Format (SDF) Parsing In-Reply-To: <0c3541a3-5a28-4d21-8b7a-bc68fb4b8f82@googlegroups.com> References: <0c3541a3-5a28-4d21-8b7a-bc68fb4b8f82@googlegroups.com> Message-ID: <86f9e4cb-19b1-4934-af20-6290860942f0@googlegroups.com> On Monday, 26 May 2014 08:15:53 UTC+2, garg.p... at gmail.com wrote: > Hi Steven, > > > > did you get the module to parse the sdf file? > > > > regards, > > pankaj Unfortunately not. I actually can't remember why I wanted/needed this. I guess that it wasn't that important since I didn't actually do any parsing. Steven From stefan_ml at behnel.de Mon May 26 03:18:20 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 26 May 2014 09:18:20 +0200 Subject: Make Python Compilable, convert to Python source to Go In-Reply-To: <8561kt5iq1.fsf@benfinney.id.au> References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> <8561kt5iq1.fsf@benfinney.id.au> Message-ID: Ben Finney, 26.05.2014 05:20: > bookaa bookaa writes: >> Generally, people consider Python as a script language. >> It has high development efficiency >> but run too slowly > > Which Python implementation are you talking about? Run time is not a > property of the language. It is a property of the language > implementation. That, plus the fact that talking about a language or language implementation "being slow" actually makes no sense at all without referring to a specific piece of code or at least an application scenario in which it is (provably) slow when compared to something (specific) else. Stefan From gandalf at shopzeus.com Mon May 26 02:28:19 2014 From: gandalf at shopzeus.com (=?ISO-8859-1?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Mon, 26 May 2014 08:28:19 +0200 Subject: compiled cx_freeze In-Reply-To: <804c5f4fb64244e8a504e2410f8be878@exch.activenetwerx.com> References: <5381A5C1.6000003@shopzeus.com> <22f6643f690f49d7a88178eccb9477fc@exch.activenetwerx.com> <5381F0E8.6090204@shopzeus.com> <804c5f4fb64244e8a504e2410f8be878@exch.activenetwerx.com> Message-ID: <5382DF03.9040508@shopzeus.com> > Let Christoph know, he is very responsive and extremely helpful. He did help. The new version is available on his site and it works. Thank you. From barbosraduioan at yahoo.ro Mon May 26 05:27:54 2014 From: barbosraduioan at yahoo.ro (Radu Ioan Barbos) Date: Mon, 26 May 2014 10:27:54 +0100 (BST) Subject: Hello and sorry for disturbing ! Message-ID: <1401096474.34975.YahooMailNeo@web172605.mail.ir2.yahoo.com> Greetings from Romania,sorry for my english,i just wanted to ask you if i need any other software/program beside the one software from the next pagehttps://www.python.org/downloads/ or is it enough the software on that page , download and install it ? This question goes for both windows 7 & ubuntu (ubuntu). Il be waiting for your answer , thank you verry much ! Barbos RauTimisoara,Romania ! -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon May 26 07:17:10 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 26 May 2014 12:17:10 +0100 Subject: Make Python Compilable, convert to Python source to Go In-Reply-To: References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: On 26/05/2014 07:31, Devin Jeanpierre wrote: > On Sun, May 25, 2014 at 3:24 AM, Mark Lawrence wrote: >> On 25/05/2014 09:17, bookaa bookaa wrote: >>> >>> Maybe I will work on Python 3 later. >>> >> >> That's good to know, it'll save me wasting my time looking at it now. > > This seems like an unnecessarily harsh way of putting it, Mark. Could > you be less dismissive of the hard work others put into improving the > Python world? > > -- Devin > Like Python 2.8? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rustompmody at gmail.com Mon May 26 07:27:56 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 26 May 2014 04:27:56 -0700 (PDT) Subject: Hello and sorry for disturbing ! In-Reply-To: References: Message-ID: <3948d417-cac6-4730-9736-3c11233bbc04@googlegroups.com> On Monday, May 26, 2014 2:57:54 PM UTC+5:30, Radu Ioan Barbos wrote: > Greetings from Romania,sorry > for my english,i just wanted to ask you if i need any other > software/program beside the one software from the next page https://www.python.org/downloads/ > or is it enough the software on that page , download and install it ? > This question goes for both windows 7 & ubuntu (ubuntu). Il be > waiting for your answer , thank you verry much ! > > Barbos RauTimisoara,Romania ! Hello and welcome! For ubuntu you should need nothing for python. In other words python should run on a basic ubuntu installation. >From the shell just type python and the interpreter should start. For more specialized work there are dozens (maybe hundreds?) of packages in the apt repos. Better to use that rather than trying to directly download. For windows, I guess thats the link you posted. However I will let someone more knowledgeable give the details From wolfgang.maier at biologie.uni-freiburg.de Mon May 26 07:48:21 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 26 May 2014 13:48:21 +0200 Subject: Hello and sorry for disturbing ! In-Reply-To: <3948d417-cac6-4730-9736-3c11233bbc04@googlegroups.com> References: <3948d417-cac6-4730-9736-3c11233bbc04@googlegroups.com> Message-ID: On 26.05.2014 13:27, Rustom Mody wrote: > On Monday, May 26, 2014 2:57:54 PM UTC+5:30, Radu Ioan Barbos wrote: >> Greetings from Romania,sorry >> for my english,i just wanted to ask you if i need any other >> software/program beside the one software from the next page https://www.python.org/downloads/ >> or is it enough the software on that page , download and install it ? >> This question goes for both windows 7 & ubuntu (ubuntu). Il be >> waiting for your answer , thank you verry much ! >> >> Barbos RauTimisoara,Romania ! > > Hello and welcome! > > For ubuntu you should need nothing for python. > In other words python should run on a basic ubuntu installation. > From the shell just type python and the interpreter should start. > If you're planning to use Python3, which is arguably (see various other threads on this list) a good idea for a beginner, make sure you upgrade to the latest Ubuntu LTS version (14.04 Trusty Tahr). This comes with Python 3.4 available from the shell as python3. From roy at panix.com Mon May 26 08:44:51 2014 From: roy at panix.com (Roy Smith) Date: Mon, 26 May 2014 08:44:51 -0400 Subject: Build tools, and Python 3 dependencies (was: How keep Python 3 moving forward) References: Message-ID: In article , Ben Finney wrote: > Roy Smith writes: > > > Stefan Behnel wrote: > > > > > And I don't really see why you would consider fabric a dependency > > > that keeps you from switching to Py3. In many cases, you can just > > > keep running it in Py2 as you did before. > > > > In theory, that's possible. In practice, it would mean having to > > maintain two different versions of Python > > Why would using Fabric ??? a build tool ??? require you to ???maintain two > different versions of Python???? You only need to maintain the build > scripts, not Python itself. Because to run these tools, we need have both versions installed on every machine. So, we don't need to maintain Python in the sense of building it from source, but we do need to have our deployment scripts install it everyplace it's needed (or, at least, make sure it's installed as part of some base deployment package) > > and test everything against both. > > That makes even less sense. The build system runs under whatever version > of Python it needs, and your code runs under whatever version of Python > you like. The two don't affect each other at run time, and don't affect > each other's testing dependencies. The are tightly integrated, and share code. > At least one of us seems to be misunderstanding what is required. Yes :-) When you start working with large systems, reducing complexity becomes important. Every time you add a component, it comes with its own set of dependencies and constraints. Those things come back to bite you when you least expect it. From fomcl at yahoo.com Mon May 26 08:57:54 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Mon, 26 May 2014 05:57:54 -0700 (PDT) Subject: win32serviceutil: ImportError: DLL load failed: The specified module could not be found In-Reply-To: References: <53822B28.4070609@shopzeus.com> Message-ID: <1401109074.81861.YahooMailNeo@web163801.mail.gq1.yahoo.com> ---- Original Message ----- > From: Terry Reedy > To: python-list at python.org > Cc: > Sent: Sunday, May 25, 2014 11:49 PM > Subject: Re: win32serviceutil: ImportError: DLL load failed: The specified module could not be found > > On 5/25/2014 1:40 PM, Nagy L?szl? Zsolt wrote: >> ? >>> import win32service >> Traceback (most recent call last): >> ? ? File "", line 1, in >> ImportError: DLL load failed: The specified module could not be found >> >> I have no problem loading the same module with Python 2.7. > > So the above is with ??? > >> Strange thing is that win32serviceutil.py is part of the pywin32 >> distribution, so I guess I should be able to import it, right? > > Make sure you have a pywin32 that matches ???. Matching includes python > version and bitness. In addition, c:\python27\DLLs should also be on your %PATH%: setx PATH "%PATH%;c:\python27\DLLs" From gandalf at shopzeus.com Mon May 26 09:24:35 2014 From: gandalf at shopzeus.com (=?ISO-8859-1?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Mon, 26 May 2014 15:24:35 +0200 Subject: win32serviceutil: ImportError: DLL load failed: The specified module could not be found In-Reply-To: <1401109074.81861.YahooMailNeo@web163801.mail.gq1.yahoo.com> References: <53822B28.4070609@shopzeus.com> <1401109074.81861.YahooMailNeo@web163801.mail.gq1.yahoo.com> Message-ID: <53834093.9090302@shopzeus.com> >>> Strange thing is that win32serviceutil.py is part of the pywin32 >>> distribution, so I guess I should be able to import it, right? >> Make sure you have a pywin32 that matches ???. Matching includes python >> version and bitness. > In addition, c:\python27\DLLs should also be on your %PATH%: > setx PATH "%PATH%;c:\python27\DLLs" Just curious: what if I don't have python2.7 installed at all? How on earth python3.4 + pywin32 requires DLL files from python2.7 ? BTW it did not help. Here is my path: Path=C:\Python34\;C:\Python34\Scripts;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\SlikSvn\bin;C:\texlive\2013\bin\win32;c:\Python34\DLLs;c:\Python27\DLLs I have both Python27 and Python34 installed. Python 3.4: "import win32service" still throws ImportError: DLL load failed. Python 2.7: "import win32service" succeeds Build information: Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)] on win32 It is the official latest. pywin32 is also the latest (build 219). From mail at timgolden.me.uk Mon May 26 09:32:19 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 26 May 2014 14:32:19 +0100 Subject: win32serviceutil: ImportError: DLL load failed: The specified module could not be found In-Reply-To: <53834093.9090302@shopzeus.com> References: <53822B28.4070609@shopzeus.com> <1401109074.81861.YahooMailNeo@web163801.mail.gq1.yahoo.com> <53834093.9090302@shopzeus.com> Message-ID: <53834263.80208@timgolden.me.uk> On 26/05/2014 14:24, Nagy L?szl? Zsolt wrote: > >>>> Strange thing is that win32serviceutil.py is part of the pywin32 >>>> distribution, so I guess I should be able to import it, right? >>> Make sure you have a pywin32 that matches ???. Matching includes python >>> version and bitness. >> In addition, c:\python27\DLLs should also be on your %PATH%: >> setx PATH "%PATH%;c:\python27\DLLs" > Just curious: what if I don't have python2.7 installed at all? How on > earth python3.4 + pywin32 requires DLL files from python2.7 ? > > BTW it did not help. Here is my path: > > Path=C:\Python34\;C:\Python34\Scripts;C:\Program Files (x86)\NVIDIA > Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program > Files\SlikSvn\bin;C:\texlive\2013\bin\win32;c:\Python34\DLLs;c:\Python27\DLLs > > > I have both Python27 and Python34 installed. > > Python 3.4: "import win32service" still throws ImportError: DLL load > failed. > Python 2.7: "import win32service" succeeds > > Build information: > > Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 > bit (AMD64)] on win32 > > It is the official latest. pywin32 is also the latest (build 219). Nagy -- could you post to the python-win32 list? There's nothing wrong with putting it out here, but I don't know if the pywin32 guys hang out here, and I know they definitely do there. (Which is also lower volume). I'm not seeing any changes to the win32service code, but a "missing DLL" error is almost always about some combination of permissions / UAC on install. Adding anything to your PATH is unlikely to help (unless you have a truly outlandish PATH). I'll try to reproduce later if I can but I don't have time right now. TJG From breamoreboy at yahoo.co.uk Mon May 26 09:49:04 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 26 May 2014 14:49:04 +0100 Subject: Hello and sorry for disturbing ! In-Reply-To: <1401096474.34975.YahooMailNeo@web172605.mail.ir2.yahoo.com> References: <1401096474.34975.YahooMailNeo@web172605.mail.ir2.yahoo.com> Message-ID: On 26/05/2014 10:27, Radu Ioan Barbos wrote: > Greetings from Romania,sorry for my english,i just wanted to ask you if > i need any other software/program beside the one software from the next > pagehttps://www.python.org/downloads/ > or is it enough the software on that > page , download and install it ? This question goes for both windows 7 & > ubuntu (ubuntu). Il be waiting for your answer , thank you verry much ! > Barbos Rau > Timisoara,Romania ! > As you've had answers to your questions I'll just say please don't apologise for your English, it's an extremely difficult language to learn. Thank you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From wxjmfauth at gmail.com Mon May 26 10:03:57 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 26 May 2014 07:03:57 -0700 (PDT) Subject: How keep Python 3 moving forward In-Reply-To: References: <87tx8fh50a.fsf@elektro.pacujo.net> <87ha4fgdo9.fsf@elektro.pacujo.net> <656a6a98-edbd-4784-801f-df82db976084@googlegroups.com> <7b84454a-3ff9-4d68-bb53-77c0fd9f333a@googlegroups.com> <538237D3.8080700@stoneleaf.us> Message-ID: Le lundi 26 mai 2014 01:09:31 UTC+2, Mark Lawrence a ?crit?: > On 25/05/2014 23:22, Dennis Lee Bieber wrote: > > > On Sun, 25 May 2014 11:34:59 -0700, Ethan Furman > > > declaimed the following: > > > > > >> On 05/25/2014 10:38 AM, Rustom Mody wrote: > > >>> > > >>> Your unicode is mojibaked Ethan! Voil???. > > >>> You are hereby banished to a lonely island with python 1.5 and jmf for company :D > > >> > > >> 1.5 I could live with. :( Surely the company would count as cruel and > > >> unusual punishment? > > >> > > > "company"... Or emergency rations? > > > > > > > I suspect that chewing razor blades would be preferable to listening to > > the permanent rant about what's wrong with the FSR. > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > =========== =========== It's just a mathematical absurdity. (No problems, to explain this to some other people, who are agreeing). jmf From gaurangnshah at gmail.com Mon May 26 10:26:20 2014 From: gaurangnshah at gmail.com (gaurangnshah at gmail.com) Date: Mon, 26 May 2014 07:26:20 -0700 (PDT) Subject: Verify JSON Data Message-ID: Hi Guys, Would someone let me know how to verify JSON data in python. There are so many modules available to verify XML file, however i didn't find any good module to verify JSON Data. After searching on the internet i came across JSON module, however it only coverts the JSON data to python. it's good, however the problem comes when JSON response is very large. Is there any module through which i can verify JSON file like DOM or Object oriented way. ( i.e. data.key) From cjgohlke at gmail.com Mon May 26 11:06:07 2014 From: cjgohlke at gmail.com (cjgohlke at gmail.com) Date: Mon, 26 May 2014 08:06:07 -0700 (PDT) Subject: win32serviceutil: ImportError: DLL load failed: The specified module could not be found In-Reply-To: References: <53822B28.4070609@shopzeus.com> <1401109074.81861.YahooMailNeo@web163801.mail.gq1.yahoo.com> <53834093.9090302@shopzeus.com> Message-ID: On Monday, May 26, 2014 6:32:19 AM UTC-7, Tim Golden wrote: > On 26/05/2014 14:24, Nagy L???szl??? Zsolt wrote: > > > > > >>>> Strange thing is that win32serviceutil.py is part of the pywin32 > > >>>> distribution, so I guess I should be able to import it, right? > > >>> Make sure you have a pywin32 that matches ???. Matching includes python > > >>> version and bitness. > > >> In addition, c:\python27\DLLs should also be on your %PATH%: > > >> setx PATH "%PATH%;c:\python27\DLLs" > > > Just curious: what if I don't have python2.7 installed at all? How on > > > earth python3.4 + pywin32 requires DLL files from python2.7 ? > > > > > > BTW it did not help. Here is my path: > > > > > > Path=C:\Python34\;C:\Python34\Scripts;C:\Program Files (x86)\NVIDIA > > > Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program > > > Files\SlikSvn\bin;C:\texlive\2013\bin\win32;c:\Python34\DLLs;c:\Python27\DLLs > > > > > > > > > I have both Python27 and Python34 installed. > > > > > > Python 3.4: "import win32service" still throws ImportError: DLL load > > > failed. > > > Python 2.7: "import win32service" succeeds > > > > > > Build information: > > > > > > Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 > > > bit (AMD64)] on win32 > > > > > > It is the official latest. pywin32 is also the latest (build 219). > > > > Nagy -- could you post to the python-win32 list? There's nothing wrong > > with putting it out here, but I don't know if the pywin32 guys hang out > > here, and I know they definitely do there. (Which is also lower volume). > > > > I'm not seeing any changes to the win32service code, but a "missing DLL" > > error is almost always about some combination of permissions / UAC on > > install. Adding anything to your PATH is unlikely to help (unless you > > have a truly outlandish PATH). > > > > I'll try to reproduce later if I can but I don't have time right now. > > > > TJG Python 3.4 does not run any bdist_wininst postinstall scripts. Try to run `C:\Python34\python.exe C:\Python34\Scripts\pywin32_postinstall.py -install` manually from an elevated command prompt. Christoph From codemonkey at inbox.com Mon May 26 11:15:53 2014 From: codemonkey at inbox.com (Deb Wyatt) Date: Mon, 26 May 2014 07:15:53 -0800 Subject: confused about the different built-in functions in Python In-Reply-To: References: <648e6136a80.00000651codemonkey@inbox.com> Message-ID: <6C977160E42.0000036Ccodemonkey@inbox.com> > > On 5/25/14 7:55 PM, Deb Wyatt wrote: >> I am confused about how various built-in functions are called. Some are >> called with dot notation >> >> How do you know/remember which way to call them? >> >> TIA, >> Deb in WA, USA > > It can be confusing. Generally, built-in functions (like sum, len, etc) > are used when the operation could apply to many different types. For > example, sum() can be used with any iterable that produces addable > things. > > Operations that are defined only for a single type (like .isalpha as a > string operation) are usually defined as methods on the type. > > This is not a black/white distinction, I'm sure there are interesting > counter-examples. But this is the general principle. > > -- > Ned Batchelder, http://nedbatchelder.com > > -- > https://mail.python.org/mailman/listinfo/python-list Thank you for answering. I meant to send this to the tutor list, but messed up. So, I guess there isn't a magic answer to this one, and I'll learn as I learn the language. Have a great day. Deb in WA, USA ____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! Check it out at http://www.inbox.com/earth From roy at panix.com Mon May 26 11:19:53 2014 From: roy at panix.com (Roy Smith) Date: Mon, 26 May 2014 11:19:53 -0400 Subject: Verify JSON Data References: Message-ID: In article , gaurangnshah at gmail.com wrote: > Hi Guys, > > Would someone let me know how to verify JSON data in python. There are so > many modules available to verify XML file, however i didn't find any good > module to verify JSON Data. Python comes with a built-in json module. Just use json.load() or json.loads() to parse your JSON data. The first call reads from a string, the second on from a file, but in all other ways, they're identical. There are a bunch of third-party modules (ujson, etc) which are faster, but fundamentally, they're all the same. If I understand you correctly, you're reading a JSON document which is so large that if you store the converted data as a Python object, you run out of memory? If that's the case, I'm not sure if there's a good pure Python solution. I don't know of any json modules which parse, but don't store, the data. Depending on what operating system you're on, there may be a command-line utility which parse JSON. For example, on Ubuntu linux, there's "json_xs". Perhaps shell out to that, use the "-t null" output format, redirect the output to /dev/null, and see what exit status you get: # Good JSON $ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo $? 0 # Bad JSON $ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo $? 255 Wrap this up in a subprocess.check_output() call, and you're done. From burak.arslan at arskom.com.tr Mon May 26 11:28:42 2014 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Mon, 26 May 2014 17:28:42 +0200 Subject: Verify JSON Data In-Reply-To: References: Message-ID: <53835DAA.5050008@arskom.com.tr> On 26/05/14 16:26, gaurangnshah at gmail.com wrote: > Hi Guys, > > Would someone let me know how to verify JSON data in python. There are so many modules available to verify XML file, however i didn't find any good module to verify JSON Data. > Hi, Spyne re-implements (a useful subset of) Xml Schema validation so that it can be applied to other document formats like json. It's 'soft' validation in Spyne's terms. http://spyne.io Disclosure: I'm the author of Spyne and starting to feel like I'm talking a little bit too much about my project on this list :) Hth, Burak From gheskett at shentel.net Mon May 26 11:37:10 2014 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 26 May 2014 11:37:10 -0400 Subject: Verify JSON Data In-Reply-To: References: Message-ID: <201405261137.10750.gheskett@wdtv.com> On Monday 26 May 2014 11:19:53 Roy Smith did opine And Gene did reply: > In article , > > gaurangnshah at gmail.com wrote: > > Hi Guys, > > > > Would someone let me know how to verify JSON data in python. There > > are so many modules available to verify XML file, however i didn't > > find any good module to verify JSON Data. > > Python comes with a built-in json module. Just use json.load() or > json.loads() to parse your JSON data. The first call reads from a > string, the second on from a file, but in all other ways, they're > identical. > > There are a bunch of third-party modules (ujson, etc) which are faster, > but fundamentally, they're all the same. > > If I understand you correctly, you're reading a JSON document which is > so large that if you store the converted data as a Python object, you > run out of memory? If that's the case, I'm not sure if there's a good > pure Python solution. I don't know of any json modules which parse, > but don't store, the data. > > Depending on what operating system you're on, there may be a > command-line utility which parse JSON. For example, on Ubuntu linux, > there's "json_xs". Perhaps shell out to that, use the "-t null" output > format, redirect the output to /dev/null, and see what exit status you > get: > > # Good JSON > $ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo $? > 0 > > # Bad JSON > $ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo $? > 255 > > Wrap this up in a subprocess.check_output() call, and you're done. Just for S&G, and without checking the version numbers of anything, this may not be all that bulletproof a test: gene at coyote:~$ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo $? 127 gene at coyote:~$ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo $? 127 Old, buntu 10.04.4 LTS system, all up to date security patches wise. kernal 3.13.9, PAE on a quad core phenom. Interesting result. Source of error? DamnedifIknow. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From denismfmcmahon at gmail.com Mon May 26 11:43:30 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 26 May 2014 15:43:30 +0000 (UTC) Subject: Verify JSON Data References: Message-ID: On Mon, 26 May 2014 07:26:20 -0700, gaurangnshah wrote: > Is there any module through which i can verify JSON file like DOM or > Object oriented way. ( i.e. data.key) Where is the json data coming from? What do you mean by verify? https://docs.python.org/2/library/json.html#encoders-and-decoders explains how json object strings get decoded to python data types. A json object string should at the highest level be either an object or an array, although the python decoder can also handle strings, numbers and a few special values. Are you trying to check that the json string is valid json code (ie json lint) or are you trying to check that it meets some specific structure, in which case the only way to verify it is to decode it and check the structure. Note that not all valid python structures can be successfully converted to json objects, for example a python dictionary can have tuples as keys, but a json object can not have an array as an attribute name. For example: d = { (1,2,3):'one',('a','b','c'):'two' } print d print json.JSONEncoder().encode( d ) Gives a TypeError in the json code "keys must be a string" If you have a debian based linux distro, you can get jsonlint with: sudo apt-get install python-demjson which provides a command line json syntax checker and formatter. Otherwise, google json lint, there are several web based tools that seem to be able to do something similar. -- Denis McMahon, denismfmcmahon at gmail.com From rosuav at gmail.com Mon May 26 11:58:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 May 2014 01:58:06 +1000 Subject: Verify JSON Data In-Reply-To: <201405261137.10750.gheskett@wdtv.com> References: <201405261137.10750.gheskett@wdtv.com> Message-ID: On Tue, May 27, 2014 at 1:37 AM, Gene Heskett wrote: > Just for S&G, and without checking the version numbers of anything, this > may not be all that bulletproof a test: > > gene at coyote:~$ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo $? > 127 > gene at coyote:~$ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo $? > 127 > > Old, buntu 10.04.4 LTS system, all up to date security patches wise. > kernal 3.13.9, PAE on a quad core phenom. > > Interesting result. Source of error? DamnedifIknow. > Return value 127 might well mean that json_xs isn't installed. It's very difficult for a non-program to tell you whether JSON is valid or not :) So I'd be checking 'which json_xs' before continuing. ChrisA From roy at panix.com Mon May 26 11:55:29 2014 From: roy at panix.com (Roy Smith) Date: Mon, 26 May 2014 11:55:29 -0400 Subject: Verify JSON Data References: Message-ID: In article , Gene Heskett wrote: > > $ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo $? > 0 > > $ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo $? > 255 > gene at coyote:~$ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo $? > 127 > gene at coyote:~$ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo $? > 127 I don't see what the problem is. On average, we got the same result :-) From rosuav at gmail.com Mon May 26 12:00:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 May 2014 02:00:30 +1000 Subject: Verify JSON Data In-Reply-To: References: Message-ID: On Tue, May 27, 2014 at 1:19 AM, Roy Smith wrote: > Python comes with a built-in json module. Just use json.load() or > json.loads() to parse your JSON data. The first call reads from a > string, the second on from a file, but in all other ways, they're > identical. Minor nit-pick: they're the other way around - load() reads from a file and loads() reads from a string. I wouldn't bother commenting, except that load() could plausibly mean "load from string", and "'str' object has no attribute 'read'" might be a bit of a surprise else :) ChrisA From rosuav at gmail.com Mon May 26 12:02:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 May 2014 02:02:00 +1000 Subject: Verify JSON Data In-Reply-To: References: Message-ID: On Tue, May 27, 2014 at 1:55 AM, Roy Smith wrote: > In article , > Gene Heskett wrote: > >> > $ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo $? >> 0 > >> > $ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo $? >> 255 > > >> gene at coyote:~$ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo $? >> 127 >> gene at coyote:~$ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo $? >> 127 > > I don't see what the problem is. On average, we got the same result :-) Ahh but if you were using Python 3, those averages would be 127.5 each. ChrisA From gheskett at shentel.net Mon May 26 12:43:27 2014 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 26 May 2014 12:43:27 -0400 Subject: Verify JSON Data In-Reply-To: References: Message-ID: <201405261243.28017.gheskett@wdtv.com> On Monday 26 May 2014 11:55:29 Roy Smith did opine And Gene did reply: > In article , > > Gene Heskett wrote: > > > $ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo $? > > > > 0 > > > > > $ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo $? > > > > 255 > > > > > > gene at coyote:~$ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo > > $? 127 > > gene at coyote:~$ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo > > $? 127 > > I don't see what the problem is. On average, we got the same result > :-) If I was still smoking Roy, I'd ask for a hit on whatever you are having. :) Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From gheskett at shentel.net Mon May 26 12:44:52 2014 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 26 May 2014 12:44:52 -0400 Subject: Verify JSON Data In-Reply-To: References: <201405261137.10750.gheskett@wdtv.com> Message-ID: <201405261244.52310.gheskett@wdtv.com> On Monday 26 May 2014 11:58:06 Chris Angelico did opine And Gene did reply: > On Tue, May 27, 2014 at 1:37 AM, Gene Heskett wrote: > > Just for S&G, and without checking the version numbers of anything, > > this may not be all that bulletproof a test: > > > > gene at coyote:~$ echo '[1, 2, 3]' | json_xs -t null 2>/dev/null; echo > > $? 127 > > gene at coyote:~$ echo '[1; 2, 3]' | json_xs -t null 2>/dev/null; echo > > $? 127 > > > > Old, buntu 10.04.4 LTS system, all up to date security patches wise. > > kernal 3.13.9, PAE on a quad core phenom. > > > > Interesting result. Source of error? DamnedifIknow. > > Return value 127 might well mean that json_xs isn't installed. It's > very difficult for a non-program to tell you whether JSON is valid or > not :) So I'd be checking 'which json_xs' before continuing. > > ChrisA And locate comes back empty. So much for that. ;-) Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From dfnsonfsduifb at gmx.de Mon May 26 13:00:11 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Mon, 26 May 2014 19:00:11 +0200 Subject: Python is horribly slow compared to bash!! In-Reply-To: <8848706d-405b-482e-8fba-4470e903ba02@googlegroups.com> References: <8848706d-405b-482e-8fba-4470e903ba02@googlegroups.com> Message-ID: On 22.05.2014 15:43, wxjmfauth at gmail.com wrote: > I can take the same application and replace 'z' by ..., and > ... No, I do not win :-( . Python fails. That's nothing. I can make an application a TOUSAND times slower by changing the constant 1 to a 2. Python is such utter garbage! import time def myfunction(constant): if constant == 1: time.sleep(1) else: time.sleep(1000) constant = 1 myfunction(constant) Now let's all code Itanium assembler, yes? Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From andre.miras at gmail.com Mon May 26 14:25:51 2014 From: andre.miras at gmail.com (andre.miras at gmail.com) Date: Mon, 26 May 2014 11:25:51 -0700 (PDT) Subject: Send commands to USB device in Python In-Reply-To: <74d95ce4-cd83-43d4-aa09-c0cb417a3431@googlegroups.com> References: <74d95ce4-cd83-43d4-aa09-c0cb417a3431@googlegroups.com> Message-ID: <4c4a5589-5042-4020-bec9-a89855645440@googlegroups.com> Hi, I saw your thread on SourceFourge (http://sourceforge.net/p/pyusb/mailman/message/31969943/), but I don't have an account. I also have MTI RU-824 reader. I sniffed the USB communication in the Windows demo program and I saw that the header should be written backward. So rather than: HEADER = bytearray("MTIC") try: HEADER = bytearray("MTIC"[::-1]) I tested it and it works. On Tuesday, 11 February 2014 06:55:03 UTC+1, Setia Budi wrote: > Hi fellows, > > I am facing difficulties in order to send USB commands to an RFID reader. > > This is the command reference of the device: https://github.com/mti-rfid/RFID_Explorer > > > > I am working with the MTI RU-824 model. > > > > The manufacturer of the device only provide a driver for Windows (using .Net), but we need to run the device on Linux. That's why I need to write few lines of code in Python as a new "driver". > > > > I am using PyUSB for accessing the device, and this is few lines of my code: > > > > ============================================================================ > > > > import usb.core > > import usb.util > > import sys > > > > VENDOR_ID = 0x24e9 > > PRODUCT_ID = 0x0824 > > > > device = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID) > > > > if device is None: > > sys.exit("Could not find Id System Barcode Reader.") > > else: > > print 'Device detected' > > > > device.set_configuration() > > > > cfg = device.get_active_configuration() > > interface_number = cfg[(0, 0)].bInterfaceNumber > > alternate_setting = usb.control.get_interface(device, interface_number) > > usb_interface = usb.util.find_descriptor( > > cfg, bInterfaceNumber=interface_number, > > bAlternateSetting=alternate_setting > > ) > > > > endpoint_out = usb.util.find_descriptor( > > usb_interface, > > # match the first OUT endpoint > > custom_match=lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_OUT > > ) > > > > endpoint_in = usb.util.find_descriptor( > > usb_interface, > > # match the first IN endpoint > > custom_match=lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_IN > > ) > > > > endpoint_out.write('0x01') > > print endpoint_in.read(len('0x01'), 1000) > > > > ============================================================================= > > My question is on the last 2 lines. > > I am using endpoint_out to send a command and endpoint_in to read data from the reader. Am I correct? > > > > The problem is, when I run the code, there is an error message like this: > > usb.core.USBError: [Errno 110] Operation timed out > > > > Anyone can give a clue? > > Thank you. From invalid at invalid.invalid Mon May 26 14:35:58 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 26 May 2014 18:35:58 +0000 (UTC) Subject: Verify JSON Data References: Message-ID: On 2014-05-26, gaurangnshah at gmail.com wrote: > Would someone let me know how to verify JSON data in python. Parse the file into a data structure with whatever parser you like, then write a program to go thorugh the data structure and verify it. > There are so many modules available to verify XML file, however i > didn't find any good module to verify JSON Data. XML has various "schema" languages which can be used to write a definition of what is valid and what isn't valid. There really is anything like that in widespread use for JSON. > After searching on the internet i came across JSON module, however it > only coverts the JSON data to python. it's good, however the problem > comes when JSON response is very large. What's the problem? > Is there any module through which i can verify JSON file like DOM or > Object oriented way. ( i.e. data.key) I don't know what you're asking. -- Grant Edwards grant.b.edwards Yow! Actually, what I'd at like is a little toy gmail.com spaceship!! From tjreedy at udel.edu Mon May 26 14:51:05 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 May 2014 14:51:05 -0400 Subject: confused about the different built-in functions in Python In-Reply-To: <6C977160E42.0000036Ccodemonkey@inbox.com> References: <648e6136a80.00000651codemonkey@inbox.com> <6C977160E42.0000036Ccodemonkey@inbox.com> Message-ID: On 5/26/2014 11:15 AM, Deb Wyatt wrote: > >> >> On 5/25/14 7:55 PM, Deb Wyatt wrote: >>> I am confused about how various built-in functions are called. Some are >>> called with dot notation >>> > >>> How do you know/remember which way to call them? >> It can be confusing. Generally, built-in functions (like sum, len, etc) >> are used when the operation could apply to many different types. For >> example, sum() can be used with any iterable that produces addable >> things. >> >> Operations that are defined only for a single type (like .isalpha as a >> string operation) are usually defined as methods on the type. >> >> This is not a black/white distinction, I'm sure there are interesting >> counter-examples. But this is the general principle. Part of the answer is Python's history. Up to about 2.1, most built-in types did not have methods, though I know lists did. Ints and strings did not, or chr and ord might have been int.chr() and str.ord(). (The current string methods were originally functions in the string module.) > Thank you for answering. I meant to send this to the tutor list, but messed up. > So, I guess there isn't a magic answer to this one, and I'll learn > as I learn the language. Have a great day. -- Terry Jan Reedy From marko at pacujo.net Mon May 26 15:00:21 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 26 May 2014 22:00:21 +0300 Subject: confused about the different built-in functions in Python References: <648e6136a80.00000651codemonkey@inbox.com> <6C977160E42.0000036Ccodemonkey@inbox.com> Message-ID: <87r43gfjqy.fsf@elektro.pacujo.net> Terry Reedy : > Part of the answer is Python's history. Up to about 2.1, most built-in > types did not have methods, though I know lists did. Ints and strings > did not, or chr and ord might have been int.chr() and str.ord(). (The > current string methods were originally functions in the string > module.) Ints still aren't quite like regular objects. For example: >>> x = 500 >>> x.__str__ is x.__str__ False Marko From gandalf at shopzeus.com Mon May 26 15:18:10 2014 From: gandalf at shopzeus.com (=?ISO-8859-1?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Mon, 26 May 2014 21:18:10 +0200 Subject: win32serviceutil: ImportError: DLL load failed: The specified module could not be found [SOLVED] In-Reply-To: References: <53822B28.4070609@shopzeus.com> <1401109074.81861.YahooMailNeo@web163801.mail.gq1.yahoo.com> <53834093.9090302@shopzeus.com> Message-ID: <53839372.7040703@shopzeus.com> > Python 3.4 does not run any bdist_wininst postinstall scripts. Try to run `C:\Python34\python.exe C:\Python34\Scripts\pywin32_postinstall.py -install` manually from an elevated command prompt. > > Christoph C:\>C:\Python34\python.exe C:\Python34\Scripts\pywin32_postinstall.py -install Copied pythoncom34.dll to C:\Python34\pythoncom34.dll Copied pywintypes34.dll to C:\Python34\pywintypes34.dll You do not have the permissions to install COM objects. The sample COM objects were not registered. -> Software\Python\PythonCore\3.4\Help[None]=None -> Software\Python\PythonCore\3.4\Help\Pythonwin Reference[None]='C:\\Python34\\ Lib\\site-packages\\PyWin32.chm' Pythonwin has been registered in context menu Creating directory C:\Python34\Lib\site-packages\win32com\gen_py Can't install shortcuts - 'C:\\Users\\Laci\\AppData\\Roaming\\Microsoft\\Windows \\Start Menu\\Programs\\Python 3.4' is not a folder The pywin32 extensions were successfully installed. C:\>python Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AM D64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32service >>> Thanks! From gandalf at shopzeus.com Mon May 26 15:22:10 2014 From: gandalf at shopzeus.com (=?ISO-8859-1?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Mon, 26 May 2014 21:22:10 +0200 Subject: win32serviceutil: ImportError: DLL load failed: The specified module could not be found In-Reply-To: References: <53822B28.4070609@shopzeus.com> <1401109074.81861.YahooMailNeo@web163801.mail.gq1.yahoo.com> <53834093.9090302@shopzeus.com> Message-ID: <53839462.7000003@shopzeus.com> > Python 3.4 does not run any bdist_wininst postinstall scripts. Try to run `C:\Python34\python.exe C:\Python34\Scripts\pywin32_postinstall.py -install` manually from an elevated command prompt. Much better when ran as an administrator: C:\Python\Projects\test>C:\Python34\python.exe C:\Python34\Scripts\pywin32_postinstall.py -install Copied pythoncom34.dll to C:\Windows\system32\pythoncom34.dll Copied pywintypes34.dll to C:\Windows\system32\pywintypes34.dll Registered: Python.Interpreter Registered: Python.Dictionary Registered: Python -> Software\Python\PythonCore\3.4\Help[None]=None -> Software\Python\PythonCore\3.4\Help\Pythonwin Reference[None]='C:\\Python34\\Lib\\site-packages\\PyWin32.chm' Pythonwin has been registered in context menu Shortcut for Pythonwin created Shortcut to documentation created The pywin32 extensions were successfully installed. I wonder why is a difference between 2.7 and 3.4 in this? From christian at python.org Mon May 26 15:47:24 2014 From: christian at python.org (Christian Heimes) Date: Mon, 26 May 2014 21:47:24 +0200 Subject: confused about the different built-in functions in Python In-Reply-To: <87r43gfjqy.fsf@elektro.pacujo.net> References: <648e6136a80.00000651codemonkey@inbox.com> <6C977160E42.0000036Ccodemonkey@inbox.com> <87r43gfjqy.fsf@elektro.pacujo.net> Message-ID: On 26.05.2014 21:00, Marko Rauhamaa wrote: > Terry Reedy : > >> Part of the answer is Python's history. Up to about 2.1, most built-in >> types did not have methods, though I know lists did. Ints and strings >> did not, or chr and ord might have been int.chr() and str.ord(). (The >> current string methods were originally functions in the string >> module.) > > Ints still aren't quite like regular objects. For example: > > >>> x = 500 > >>> x.__str__ is x.__str__ > False Just like every other object: >>> class Example(object): pass ... >>> e = Example() >>> e.__str__ is e.__str__ False Python creates a new bound method object every time. A bound method object is a callable object that keeps a strong reference to the function, class and object. The bound method object adds the object as first argument to the function (aka 'self'). Christian From marko at pacujo.net Mon May 26 16:32:40 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 26 May 2014 23:32:40 +0300 Subject: confused about the different built-in functions in Python References: <648e6136a80.00000651codemonkey@inbox.com> <6C977160E42.0000036Ccodemonkey@inbox.com> <87r43gfjqy.fsf@elektro.pacujo.net> Message-ID: <87ioosffh3.fsf@elektro.pacujo.net> Christian Heimes : > Python creates a new bound method object every time. A bound method > object is a callable object that keeps a strong reference to the > function, class and object. The bound method object adds the object as > first argument to the function (aka 'self'). I stand corrected. I had thought the trampoline ("bound method object") was created once and for all. Marko From marko at pacujo.net Mon May 26 16:58:37 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 26 May 2014 23:58:37 +0300 Subject: confused about the different built-in functions in Python References: <648e6136a80.00000651codemonkey@inbox.com> <6C977160E42.0000036Ccodemonkey@inbox.com> <87r43gfjqy.fsf@elektro.pacujo.net> <87ioosffh3.fsf@elektro.pacujo.net> Message-ID: <87egzgfe9u.fsf@elektro.pacujo.net> Marko Rauhamaa : > Christian Heimes : > >> Python creates a new bound method object every time. A bound method >> object is a callable object that keeps a strong reference to the >> function, class and object. The bound method object adds the object as >> first argument to the function (aka 'self'). > > I stand corrected. I had thought the trampoline ("bound method > object") was created once and for all. Sure enough. The principle is explicitly specified in . Thus: >>> class X: ... def f(self): ... print("Hello") ... >>> x = X() >>> x.f() Hello >>> def f(): print("Meh") ... >>> x.f = f >>> x.f() Meh >>> delattr(x, "f") >>> x.f() Hello IOW, you can override a method with setattr() but you cannot delete a method with delattr(). Marko From greg.ewing at canterbury.ac.nz Mon May 26 19:14:38 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 27 May 2014 11:14:38 +1200 Subject: confused about the different built-in functions in Python In-Reply-To: <87egzgfe9u.fsf@elektro.pacujo.net> References: <648e6136a80.00000651codemonkey@inbox.com> <6C977160E42.0000036Ccodemonkey@inbox.com> <87r43gfjqy.fsf@elektro.pacujo.net> <87ioosffh3.fsf@elektro.pacujo.net> <87egzgfe9u.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > IOW, you can override a method with setattr() but you cannot delete a > method with delattr(). Actually, you can -- but you need to delete it from the class, not the instance: >>> delattr(X, 'f') >>> x.f() Traceback (most recent call last): File "", line 1, in AttributeError: 'X' object has no attribute 'f' -- Greg From ps16thypresenceisfullnessofjoy at gmail.com Mon May 26 20:03:58 2014 From: ps16thypresenceisfullnessofjoy at gmail.com (ps16thypresenceisfullnessofjoy at gmail.com) Date: Mon, 26 May 2014 17:03:58 -0700 (PDT) Subject: Command prompt not shown when running Python script with subprocess on Windows Message-ID: <29c26176-b573-4ac9-bf41-a18a53d7dfb9@googlegroups.com> I have written a Python script with a wxPython GUI that uses subprocess.Popen to open a list of files that the user provides. One of my users would like to be able to run a Python script with my application. The Python script he is trying to run uses the command line and gets keyboard input from the user several times. The problem is that if the Python script is run on Windows with subprocess.Popen, no command prompt is shown (my GUI application is a .pyw file). The user's script runs silently but then does not quit because it is waiting for input, but there is no way for the input to be given, since there is no command prompt visible. I think this may be related to the fact that I am calling subprocess.Popen with shell=True. I tried calling it with shell=False (the default), but then I got an error that the file is not a valid Win32 application. I would appreciate any help with this problem. -- Timothy From steve+comp.lang.python at pearwood.info Mon May 26 21:21:36 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2014 01:21:36 GMT Subject: confused about the different built-in functions in Python References: <648e6136a80.00000651codemonkey@inbox.com> <6C977160E42.0000036Ccodemonkey@inbox.com> <87r43gfjqy.fsf@elektro.pacujo.net> <87ioosffh3.fsf@elektro.pacujo.net> <87egzgfe9u.fsf@elektro.pacujo.net> Message-ID: <5383e89f$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 26 May 2014 23:58:37 +0300, Marko Rauhamaa wrote: > Marko Rauhamaa : > >> Christian Heimes : >> >>> Python creates a new bound method object every time. A bound method >>> object is a callable object that keeps a strong reference to the >>> function, class and object. The bound method object adds the object as >>> first argument to the function (aka 'self'). >> >> I stand corrected. I had thought the trampoline ("bound method object") >> was created once and for all. > > Sure enough. The principle is explicitly specified in https://docs.python.org/3.2/reference/datamodel.html#index-46>. > > Thus: > > >>> class X: > ... def f(self): > ... print("Hello") > ... > >>> x = X() > >>> x.f() > Hello > >>> def f(): print("Meh") > ... > >>> x.f = f > >>> x.f() > Meh > >>> delattr(x, "f") > >>> x.f() > Hello > > IOW, you can override a method with setattr() but you cannot delete a > method with delattr(). Of course you can. You just need to know where methods are found. Hint: we write this: class Example: def method(self): ... not this: class Example: def __init__(self): def method(self): ... self.method = method Methods are attributes of the class, not the instance. Like all class attributes, you can retrieve them by doing a lookup on the instance, you can shadow them by storing an attribute of the same name on the instance, but you cannot rebind or delete them directly on the instance, since they aren't on the instance. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Mon May 26 21:24:35 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2014 01:24:35 GMT Subject: Make Python Compilable, convert to Python source to Go References: <4300c94d-316b-46b8-9d51-856b60273334@googlegroups.com> Message-ID: <5383e953$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 26 May 2014 12:17:10 +0100, Mark Lawrence wrote: > On 26/05/2014 07:31, Devin Jeanpierre wrote: >> On Sun, May 25, 2014 at 3:24 AM, Mark Lawrence >> wrote: >>> On 25/05/2014 09:17, bookaa bookaa wrote: >>>> >>>> Maybe I will work on Python 3 later. >>>> >>>> >>> That's good to know, it'll save me wasting my time looking at it now. >> >> This seems like an unnecessarily harsh way of putting it, Mark. Could >> you be less dismissive of the hard work others put into improving the >> Python world? >> >> -- Devin >> >> > Like Python 2.8? I think you may have drifted into an alternate universe. There is no Python 2.8 and nobody has done any hard work on writing it, so I have no idea what point you think you are making. (That's the trouble with snappy one-line answers to serious questions -- they often make no sense to anyone outside of your head.) The OP has done a lot of hard work at writing a Python 2 to Go translator (allegedly -- we haven't actually been shown his project) and assuming it works and done what he says it does, that's valuable. Python 2.7 will be part of the Python ecosystem until at least 2022. Furthermore, adapting an existing Python2 to Go compiler to work with Python3 will be much easier than writing one from scratch. -- Steven D'Aprano http://import-that.dreamwidth.org/ From tjreedy at udel.edu Mon May 26 22:00:03 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 May 2014 22:00:03 -0400 Subject: confused about the different built-in functions in Python In-Reply-To: <87ioosffh3.fsf@elektro.pacujo.net> References: <648e6136a80.00000651codemonkey@inbox.com> <6C977160E42.0000036Ccodemonkey@inbox.com> <87r43gfjqy.fsf@elektro.pacujo.net> <87ioosffh3.fsf@elektro.pacujo.net> Message-ID: On 5/26/2014 4:32 PM, Marko Rauhamaa wrote: > I stand corrected. I had thought the trampoline ("bound method object") > was created once and for all. Assuming that bound methods are immutable, this is an implementation detail, either way. However, it is common for a specific method to be called just once on a specific instance. If you have a mixed-case string Ss and want the lowercase version, ss = Ss.lower(), you keep ss around as long as needed. If the bound method is needed repeatedly, you can keep *that* around too. stack = [] spush = stack.append spop = stack.pop for item in it: spush(item) while stack and condition: p = process(spop) ... -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Mon May 26 22:59:13 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2014 02:59:13 GMT Subject: Build tools, and Python 3 dependencies (was: How keep Python 3 moving forward) References: Message-ID: <5383ff81$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 26 May 2014 08:44:51 -0400, Roy Smith wrote: >> That makes even less sense. The build system runs under whatever >> version of Python it needs, and your code runs under whatever version >> of Python you like. The two don't affect each other at run time, and >> don't affect each other's testing dependencies. > > The are tightly integrated, and share code. Well there's your problem, right there. Tight coupling is a *bad* thing, you're supposed to minimize it, not maximize it :-) I'm having trouble understanding why your build system should be integrated with your production code. You should, in principle, be able to replace your build system with one written in Perl or bash without having to touch a single line of your application. If what you say is correct, your design tends towards the sort of perplexing errors like "We added extra debugging code to the build script, and now the application won't print!" The programmer's attitude towards tightly coupled code ought to be like Batman's attitude towards crime: something to be stamped out, at any cost, unless it is absolutely for the purpose of a higher cause. In Batman's case that higher cause is justice and the good of Gotham City. What's your higher cause? -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Mon May 26 23:06:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2014 03:06:01 GMT Subject: Build tools, and Python 3 dependencies (was: How keep Python 3 moving forward) References: Message-ID: <53840119$0$29978$c3e8da3$5496439d@news.astraweb.com> Oh, I was a bit trigger-happy with my earlier post. On Mon, 26 May 2014 08:44:51 -0400, Roy Smith wrote about his build system and production code: > The are tightly integrated, and share code. [...] > When you start working with large systems, reducing complexity becomes > important. Every time you add a component, it comes with its own set of > dependencies and constraints. Those things come back to bite you when > you least expect it. How ironic that you have now got *more* constraints, *stronger* dependencies and *more* complexity than if you had written a less tightly coupled system. Complexity is not, in and of itself, the most serious problem. But coupling is. You're now constrained that you cannot make changes to your application without simultaneously changing your build system. Although you have *fewer* dependencies, they've locked you in to a single course of action even more tightly than if you had more. At least that's the impression that you have given. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Mon May 26 23:54:05 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 26 May 2014 20:54:05 -0700 (PDT) Subject: Build tools, and Python 3 dependencies (was: How keep Python 3 moving forward) In-Reply-To: <5383ff81$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <5383ff81$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <12e6c98a-c703-4ae7-a69a-269747084280@googlegroups.com> On Tuesday, May 27, 2014 8:29:13 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 26 May 2014 08:44:51 -0400, Roy Smith wrote: > > > > >> That makes even less sense. The build system runs under whatever > > >> version of Python it needs, and your code runs under whatever version > > >> of Python you like. The two don't affect each other at run time, and > > >> don't affect each other's testing dependencies. > > > > > > The are tightly integrated, and share code. > > > > Well there's your problem, right there. Tight coupling is a *bad* thing, > > you're supposed to minimize it, not maximize it :-) > > > > I'm having trouble understanding why your build system should be > integrated with your production code. You should, in principle, be able > to replace your build system with one written in Perl or bash without > having to touch a single line of your application. If what you say is In theory, theory and practice are the same. In practice, they are not. s/theory/principle [Whether thats Einsten or Yogi Berra I am not sure. I guess they are the same in principle :D ] Somewhat more seriously, I see this as a problem with all the super-kewl languages. I know it most closely with python and haskell but I think its true across the board. It goes something like this: - Language L is super-kewl - Its so kewl it spawns its own ecosystem - The ecosystem grows - World domination is almost in sight -- everything to be done with language L - Unfortunately super-kewl ? omnipotent - Things start crumbling at the edges Case(s) in point: debian's apt is a mishmash of perl,shell etc However it is more powerful than python's pip or Haskell's cabal. From rustompmody at gmail.com Tue May 27 00:28:39 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 26 May 2014 21:28:39 -0700 (PDT) Subject: Verify JSON Data In-Reply-To: References: Message-ID: <1e5a57c8-d014-4c04-9bbf-a1bd7e3cd5f1@googlegroups.com> On Tuesday, May 27, 2014 12:05:58 AM UTC+5:30, Grant Edwards wrote: > On 2014-05-26, gaurang shah wrote: > > Would someone let me know how to verify JSON data in python. > Parse the file into a data structure with whatever parser you like, > then write a program to go thorugh the data structure and verify it. > > There are so many modules available to verify XML file, however i > > didn't find any good module to verify JSON Data. > XML has various "schema" languages which can be used to write a > definition of what is valid and what isn't valid. > There really is anything like that in widespread use for JSON. Google offers: https://pypi.python.org/pypi/jsonschema http://python-jsonschema.readthedocs.org/en/latest/validate/ From bob.martin at excite.com Tue May 27 07:43:07 2014 From: bob.martin at excite.com (Bob Martin) Date: Tue, 27 May 2014 07:43:07 BST Subject: Hello and sorry for disturbing ! References: <1401096474.34975.YahooMailNeo@web172605.mail.ir2.yahoo.com> Message-ID: in 722639 20140526 144904 Mark Lawrence wrote: >On 26/05/2014 10:27, Radu Ioan Barbos wrote: >> Greetings from Romania,sorry for my english,i just wanted to ask you if >> i need any other software/program beside the one software from the next >> pagehttps://www.python.org/downloads/ >> or is it enough the software on that >> page , download and install it ? This question goes for both windows 7 & >> ubuntu (ubuntu). Il be waiting for your answer , thank you verry much ! >> Barbos Rau >> Timisoara,Romania ! >> > >As you've had answers to your questions I'll just say please don't >apologise for your English, it's an extremely difficult language to >learn. Thank you. You could have added that his English is already very good. :-) From davea at davea.name Tue May 27 03:20:40 2014 From: davea at davea.name (Dave Angel) Date: Tue, 27 May 2014 03:20:40 -0400 (EDT) Subject: Command prompt not shown when running Python script with subprocess on Windows References: <29c26176-b573-4ac9-bf41-a18a53d7dfb9@googlegroups.com> Message-ID: ps16thypresenceisfullnessofjoy at gmail.com Wrote in message: > I have written a Python script with a wxPython GUI that uses subprocess.Popen to open a list of files that the user provides. One of my users would like to be able to run a Python script with my application. The Python script he is trying to run uses the command line and gets keyboard input from the user several times. > > The problem is that if the Python script is run on Windows with subprocess.Popen, no command prompt is shown (my GUI application is a .pyw file). The user's script runs silently but then does not quit because it is waiting for input, but there is no way for the input to be given, since there is no command prompt visible. > > I think this may be related to the fact that I am calling subprocess.Popen with shell=True. I tried calling it with shell=False (the default), but then I got an error that the file is not a valid Win32 application. > > I would appreciate any help with this problem. > > -- Timothy > If you want to use shell=False, you need to specify the executable correctly. Since you're on Windows, the executable is named python.exe, not myscript. py If you still get errors, you need to get a lot more explicit. Copy/paste, not paraphrase. -- DaveA From me+python at ixokai.io Tue May 27 02:38:28 2014 From: me+python at ixokai.io (Stephen Hansen) Date: Mon, 26 May 2014 23:38:28 -0700 Subject: Command prompt not shown when running Python script with subprocess on Windows In-Reply-To: <29c26176-b573-4ac9-bf41-a18a53d7dfb9@googlegroups.com> References: <29c26176-b573-4ac9-bf41-a18a53d7dfb9@googlegroups.com> Message-ID: You need to call python.exe path-to-script.py, I think, not just path-to-script.py. See sys.executable (though that depends on if you're a frozen app or not). I can't be sure though because there's no code. Show code when asking questions, it helps frame the discussion and get a better answer ;) On Mon, May 26, 2014 at 5:03 PM, wrote: > I have written a Python script with a wxPython GUI that uses > subprocess.Popen to open a list of files that the user provides. One of my > users would like to be able to run a Python script with my application. The > Python script he is trying to run uses the command line and gets keyboard > input from the user several times. > > The problem is that if the Python script is run on Windows with > subprocess.Popen, no command prompt is shown (my GUI application is a .pyw > file). The user's script runs silently but then does not quit because it is > waiting for input, but there is no way for the input to be given, since > there is no command prompt visible. > > I think this may be related to the fact that I am calling subprocess.Popen > with shell=True. I tried calling it with shell=False (the default), but > then I got an error that the file is not a valid Win32 application. > > I would appreciate any help with this problem. > > -- Timothy > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From animalize81 at gmail.com Tue May 27 03:33:42 2014 From: animalize81 at gmail.com (animalize81) Date: Tue, 27 May 2014 15:33:42 +0800 Subject: Python box (home-use smart router) Message-ID: <53843FD6.1040505@gmail.com> Home-use smart router is more and more popular. If embeds Python into such router, and develops a framework that has the following features: 1, allow power-down at any time 2, dynamic domain name 3, local storage support (SD cards or Hard Disk) 4, telnet server etc. Then we can create micro private server on it. Still can't see the full prospect, but it may be a great platform for people's imagination. I think Python is very suitable for such role. From kcrsparks at gmail.com Tue May 27 03:45:10 2014 From: kcrsparks at gmail.com (KC Sparks) Date: Tue, 27 May 2014 00:45:10 -0700 Subject: Check to see if the script has been previously used? Message-ID: Hi, I was wondering if there was an extension or way that would allow me to print instructions if it is the first the the user has used the script. Thanks, KC -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 27 04:25:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 May 2014 18:25:19 +1000 Subject: Check to see if the script has been previously used? In-Reply-To: References: Message-ID: On Tue, May 27, 2014 at 5:45 PM, KC Sparks wrote: > I was wondering if there was an extension or way that would allow me to > print instructions if it is the first the the user has used the script. The trickiest part is defining the 'user'. Generally, this sort of thing is done by creating a file; if the file's not there, it's the first time. Some versions of sudo will create a file called .sudo_as_admin_successful in the user's home directory; others create /var/lib/sudo/ as a directory, and storing information there. Either technique works well for recognizing a first-time user. ChrisA From amankashyap1223 at gmail.com Tue May 27 06:59:48 2014 From: amankashyap1223 at gmail.com (Aman Kashyap) Date: Tue, 27 May 2014 03:59:48 -0700 (PDT) Subject: Regular Expression for the special character "|" pipe Message-ID: <9c8e58be-9619-44c7-8098-961a0134c422@googlegroups.com> I would like to create a regular expression in which i can match the "|" special character too. e.g. start=|ID=ter54rt543d|SID=ter54rt543d|end=| I want to only |ID=ter54rt543d| from the above string but i am unable to write the pattern match containing "|" pipe too. By default python treat "|" as an OR operator. But in my case I want to use to as a part of search string. From davea at davea.name Tue May 27 07:05:21 2014 From: davea at davea.name (Dave Angel) Date: Tue, 27 May 2014 07:05:21 -0400 (EDT) Subject: Check to see if the script has been previously used? References: Message-ID: Chris Angelico Wrote in message: > On Tue, May 27, 2014 at 5:45 PM, KC Sparks wrote: >> I was wondering if there was an extension or way that would allow me to >> print instructions if it is the first the the user has used the script. > > The trickiest part is defining the 'user'. Generally, this sort of > thing is done by creating a file; if the file's not there, it's the > first time. Some versions of sudo will create a file called > .sudo_as_admin_successful in the user's home directory; others create > /var/lib/sudo/ as a directory, and storing information > there. Either technique works well for recognizing a first-time user. > > ChrisA > The problem can be simpler if you're assuming a machine with only one user, or more complicated if the obvious disk location is either read-only to the user, or volatile. You also might want to clear all such flags upon an upgrade. If so, it's not just a file needed, but a sortable version string. Preferred approach is usually to respond to one of the conventional argv switches. And let the user decide. -- DaveA From rosuav at gmail.com Tue May 27 07:08:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 May 2014 21:08:44 +1000 Subject: Check to see if the script has been previously used? In-Reply-To: References: Message-ID: On Tue, May 27, 2014 at 9:05 PM, Dave Angel wrote: > Preferred approach is usually to respond to one of the > conventional argv switches. And let the user decide. Yes, this is a technique I've used when doing up important (and dangerous) MUD commands. The command will be something like "unload foo" and it gives its first-time spam, or "unload confirm foo" to suppress it and go straight to the potentially-dangerous action. With shell commands, a -f or --force parameter would be common for that. ChrisA From vlastimil.brom at gmail.com Tue May 27 07:09:19 2014 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 27 May 2014 13:09:19 +0200 Subject: Regular Expression for the special character "|" pipe In-Reply-To: <9c8e58be-9619-44c7-8098-961a0134c422@googlegroups.com> References: <9c8e58be-9619-44c7-8098-961a0134c422@googlegroups.com> Message-ID: 2014-05-27 12:59 GMT+02:00 Aman Kashyap : > I would like to create a regular expression in which i can match the "|" special character too. > > e.g. > > start=|ID=ter54rt543d|SID=ter54rt543d|end=| > > I want to only |ID=ter54rt543d| from the above string but i am unable to write the pattern match containing "|" pipe too. > > By default python treat "|" as an OR operator. > > But in my case I want to use to as a part of search string. > -- Hi, you can just escpape the pipe with backlash like any other metacharacter: r"start=\|ID=ter54rt543d" be sure to use the raw string notation r"...", or you can double all backslashes in the string. hth, vbr From amankashyap1223 at gmail.com Tue May 27 07:20:06 2014 From: amankashyap1223 at gmail.com (Aman Kashyap) Date: Tue, 27 May 2014 04:20:06 -0700 (PDT) Subject: Regular Expression for the special character "|" pipe In-Reply-To: References: <9c8e58be-9619-44c7-8098-961a0134c422@googlegroups.com> Message-ID: On Tuesday, 27 May 2014 16:39:19 UTC+5:30, Vlastimil Brom wrote: > 2014-05-27 12:59 GMT+02:00 Aman Kashyap : > > > I would like to create a regular expression in which i can match the "|" special character too. > > > > > > e.g. > > > > > > start=|ID=ter54rt543d|SID=ter54rt543d|end=| > > > > > > I want to only |ID=ter54rt543d| from the above string but i am unable to write the pattern match containing "|" pipe too. > > > > > > By default python treat "|" as an OR operator. > > > > > > But in my case I want to use to as a part of search string. > > > -- > > > > Hi, > > you can just escpape the pipe with backlash like any other metacharacter: > > > > r"start=\|ID=ter54rt543d" > > > > be sure to use the raw string notation r"...", or you can double all > > backslashes in the string. > > > > hth, > > vbr Thanks vbr for the quick response. I have string = |SOH=|ID=re65dgt5dd|DS=fjkjf|SDID=fhkhkf|ID=fkjfkf|EOM=| and want to replace 2 sub-strings |ID=re65dgt5dd| with |ID=MAN| |ID=fkjfkf| with |MAN| I am using regular expression ID=[a-z]*[0-9]*[a-z]*[0-9]*[a-z]*|$ the output is |SOH=|ID=MAN|DS=fjkjf|SDID=MAN|ID=MAN|EOM=|ID=MAN expected value is = |SOH=|ID=MAN|DS=fjkjf|SDID=fhkhkf|ID=MAN|EOM=| could you please help me in this regard? From 5960761 at gmail.com Tue May 27 07:29:38 2014 From: 5960761 at gmail.com (Daniel) Date: Tue, 27 May 2014 14:29:38 +0300 Subject: Regular Expression for the special character "|" pipe In-Reply-To: References: <9c8e58be-9619-44c7-8098-961a0134c422@googlegroups.com> Message-ID: <53847722.5050902@gmail.com> What about skipping the re and try this: 'start=|ID=ter54rt543d|SID=ter54rt543d|end=|'.split('|')[1][3:] On 27.05.2014 14:09, Vlastimil Brom wrote: > 2014-05-27 12:59 GMT+02:00 Aman Kashyap : >> I would like to create a regular expression in which i can match the "|" special character too. >> >> e.g. >> >> start=|ID=ter54rt543d|SID=ter54rt543d|end=| >> >> I want to only |ID=ter54rt543d| from the above string but i am unable to write the pattern match containing "|" pipe too. >> >> By default python treat "|" as an OR operator. >> >> But in my case I want to use to as a part of search string. >> -- > Hi, > you can just escpape the pipe with backlash like any other metacharacter: > > r"start=\|ID=ter54rt543d" > > be sure to use the raw string notation r"...", or you can double all > backslashes in the string. > > hth, > vbr From amankashyap1223 at gmail.com Tue May 27 07:39:14 2014 From: amankashyap1223 at gmail.com (Aman Kashyap) Date: Tue, 27 May 2014 04:39:14 -0700 (PDT) Subject: Regular Expression for the special character "|" pipe In-Reply-To: References: <9c8e58be-9619-44c7-8098-961a0134c422@googlegroups.com> Message-ID: <3cc77455-39ed-4403-a46c-5dd8e640a483@googlegroups.com> On Tuesday, 27 May 2014 16:59:38 UTC+5:30, Daniel wrote: > What about skipping the re and try this: > > > > 'start=|ID=ter54rt543d|SID=ter54rt543d|end=|'.split('|')[1][3:] > > > > On 27.05.2014 14:09, Vlastimil Brom wrote: > > > 2014-05-27 12:59 GMT+02:00 Aman Kashyap : > > >> I would like to create a regular expression in which i can match the "|" special character too. > > >> > > >> e.g. > > >> > > >> start=|ID=ter54rt543d|SID=ter54rt543d|end=| > > >> > > >> I want to only |ID=ter54rt543d| from the above string but i am unable to write the pattern match containing "|" pipe too. > > >> > > >> By default python treat "|" as an OR operator. > > >> > > >> But in my case I want to use to as a part of search string. > > >> -- > > > Hi, > > > you can just escpape the pipe with backlash like any other metacharacter: > > > > > > r"start=\|ID=ter54rt543d" > > > > > > be sure to use the raw string notation r"...", or you can double all > > > backslashes in the string. > > > > > > hth, > > > vbr Thanks for the response. I got the answer finally. This is the regular expression to be used:\\|ID=[a-z]*[0-9]*[a-z]*[0-9]*[a-z]*\\| From wolfgang.maier at biologie.uni-freiburg.de Tue May 27 07:55:58 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Tue, 27 May 2014 13:55:58 +0200 Subject: Regular Expression for the special character "|" pipe In-Reply-To: <3cc77455-39ed-4403-a46c-5dd8e640a483@googlegroups.com> References: <9c8e58be-9619-44c7-8098-961a0134c422@googlegroups.com> <3cc77455-39ed-4403-a46c-5dd8e640a483@googlegroups.com> Message-ID: On 27.05.2014 13:39, Aman Kashyap wrote: >> On 27.05.2014 14:09, Vlastimil Brom wrote: >> >>> you can just escpape the pipe with backlash like any other metacharacter: >>> >>> r"start=\|ID=ter54rt543d" >>> >>> be sure to use the raw string notation r"...", or you can double all >> >>> backslashes in the string. >> > Thanks for the response. > > I got the answer finally. > > This is the regular expression to be used:\\|ID=[a-z]*[0-9]*[a-z]*[0-9]*[a-z]*\\| > or, and more readable: r'\|ID=[a-z]*[0-9]*[a-z]*[0-9]*[a-z]*\|' This is what Vlastimil was talking about. It saves you from having to escape the backslashes. From roy at panix.com Tue May 27 08:35:53 2014 From: roy at panix.com (Roy Smith) Date: Tue, 27 May 2014 08:35:53 -0400 Subject: Regular Expression for the special character "|" pipe References: <9c8e58be-9619-44c7-8098-961a0134c422@googlegroups.com> <3cc77455-39ed-4403-a46c-5dd8e640a483@googlegroups.com> Message-ID: In article , Wolfgang Maier wrote: > On 27.05.2014 13:39, Aman Kashyap wrote: > >> On 27.05.2014 14:09, Vlastimil Brom wrote: > >> > >>> you can just escpape the pipe with backlash like any other metacharacter: > >>> > >>> r"start=\|ID=ter54rt543d" > >>> > >>> be sure to use the raw string notation r"...", or you can double all > >> > >>> backslashes in the string. > >> > > Thanks for the response. > > > > I got the answer finally. > > > > This is the regular expression to be > > used:\\|ID=[a-z]*[0-9]*[a-z]*[0-9]*[a-z]*\\| > > > > or, and more readable: > > r'\|ID=[a-z]*[0-9]*[a-z]*[0-9]*[a-z]*\|' > > This is what Vlastimil was talking about. It saves you from having to > escape the backslashes. Sometimes what I do, instead of using backslashes, I put the problem character into a character class by itself. It's a matter of personal opinion which way is easier to read, but it certainly eliminates all the questions about "how many backslashes do I need?" > r'[|]ID=[a-z]*[0-9]*[a-z]*[0-9]*[a-z]*[|]' Another thing that can help make regexes easier to read is the VERBOSE flag. Basically, it ignores whitespace inside the regex (see https://docs.python.org/2/library/re.html#module-contents for details). So, you can write something like: pattern = re.compile(r'''[|] ID= [a-z]* [0-9]* [a-z]* [0-9]* [a-z]* [|]''', re.VERBOSE) Or, alternatively, take advantage of the fact that Python concatenates adjacent string literals, and write it like this: pattern = re.compile(r'[|]' r'ID=' r'[a-z]*' r'[0-9]*' r'[a-z]*' r'[0-9]*' r'[a-z]*' r'[|]' ) From breamoreboy at yahoo.co.uk Tue May 27 09:06:18 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 27 May 2014 14:06:18 +0100 Subject: Regular Expression for the special character "|" pipe In-Reply-To: <3cc77455-39ed-4403-a46c-5dd8e640a483@googlegroups.com> References: <9c8e58be-9619-44c7-8098-961a0134c422@googlegroups.com> <3cc77455-39ed-4403-a46c-5dd8e640a483@googlegroups.com> Message-ID: On 27/05/2014 12:39, Aman Kashyap wrote: > On Tuesday, 27 May 2014 16:59:38 UTC+5:30, Daniel wrote: >> What about skipping the re and try this: >> >> >> >> 'start=|ID=ter54rt543d|SID=ter54rt543d|end=|'.split('|')[1][3:] >> >> >> >> On 27.05.2014 14:09, Vlastimil Brom wrote: >> >>> 2014-05-27 12:59 GMT+02:00 Aman Kashyap : >> >>>> I would like to create a regular expression in which i can match the "|" special character too. >> >>>> >> >>>> e.g. >> >>>> >> >>>> start=|ID=ter54rt543d|SID=ter54rt543d|end=| >> >>>> >> >>>> I want to only |ID=ter54rt543d| from the above string but i am unable to write the pattern match containing "|" pipe too. >> >>>> >> >>>> By default python treat "|" as an OR operator. >> >>>> >> >>>> But in my case I want to use to as a part of search string. >> >>>> -- >> >>> Hi, >> >>> you can just escpape the pipe with backlash like any other metacharacter: >> >>> >> >>> r"start=\|ID=ter54rt543d" >> >>> >> >>> be sure to use the raw string notation r"...", or you can double all >> >>> backslashes in the string. >> >>> >> >>> hth, >> >>> vbr > > Thanks for the response. > > I got the answer finally. > > This is the regular expression to be used:\\|ID=[a-z]*[0-9]*[a-z]*[0-9]*[a-z]*\\| > I'm pleased to see that you have answers. In return would you please use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From invalid at invalid.invalid Tue May 27 10:12:40 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 27 May 2014 14:12:40 +0000 (UTC) Subject: Python is horribly slow compared to bash!! References: <8848706d-405b-482e-8fba-4470e903ba02@googlegroups.com> Message-ID: On 2014-05-26, Dennis Lee Bieber wrote: > On Mon, 26 May 2014 19:00:11 +0200, Johannes Bauer > declaimed the following: > >> >>Now let's all code Itanium assembler, yes? > > Naw... Let's beg Intel to bring back the iAPX-432, and beg AdaCore to > port GNAT to it. When the '432 datasheets came out, everybody thought it was pretty cool. Turns out it just didn't "go". So, Intel lowered its sights and concentrated on the 8086 family, and we all suffered for the next few decades as a result... -- Grant Edwards grant.b.edwards Yow! I smell like a wet at reducing clinic on Columbus gmail.com Day! From a24061 at ducksburg.com Tue May 27 11:13:46 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Tue, 27 May 2014 16:13:46 +0100 Subject: hashing strings to integers References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: On 2014-05-23, Chris Angelico wrote: > On Fri, May 23, 2014 at 8:27 PM, Adam Funk wrote: >> I've also used hashes of strings for other things involving >> deduplication or fast lookups (because integer equality is faster than >> string equality). I guess if it's just for deduplication, though, a >> set of byte arrays is as good as a set of int? > > Want a better way to do that? Use a set or dict and let Python do the > hashing. It'll be every bit as fast as explicit hashing, plus you get > the bonus of simplicity. Well, here's the way it works in my mind: I can store a set of a zillion strings (or a dict with a zillion string keys), but every time I test "if new_string in seen_strings", the computer hashes the new_string using some kind of "short hash", checks the set for matching buckets (I'm assuming this is how python tests set membership --- is that right?), then checks any hash-matches for string equality. Testing string equality is slower than integer equality, and strings (unless they are really short) take up a lot more memory than long integers. So for that kind of thing, I tend to store MD5 hashes or something similar. Is that wrong? -- With the breakdown of the medieval system, the gods of chaos, lunacy, and bad taste gained ascendancy. --- Ignatius J Reilly From a24061 at ducksburg.com Tue May 27 11:20:37 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Tue, 27 May 2014 16:20:37 +0100 Subject: hashing strings to integers References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: <53ne5bxen.ln2@news.ducksburg.com> On 2014-05-23, Terry Reedy wrote: > On 5/23/2014 6:27 AM, Adam Funk wrote: > >> that. The only thing that really bugs me in Python 3 is that execfile >> has been removed (I find it useful for testing things interactively). > > The spelling has been changed to exec(open(...).read(), ... . It you use > it a lot, add a customized def execfile(filename, ... to your site > module or local utils module. Are you talking about this? https://docs.python.org/3/library/site.html Is there a dummies/quick-start guide to using USER_SITE stuff? -- No sport is less organized than Calvinball! From himanshulkce at gmail.com Tue May 27 11:43:12 2014 From: himanshulkce at gmail.com (himanshulkce at gmail.com) Date: Tue, 27 May 2014 08:43:12 -0700 (PDT) Subject: python Message-ID: Need of python in embedded systems??? From steve+comp.lang.python at pearwood.info Tue May 27 13:02:50 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2014 17:02:50 GMT Subject: hashing strings to integers References: <05c15bxrpj.ln2@news.ducksburg.com> Message-ID: <5384c539$0$29978$c3e8da3$5496439d@news.astraweb.com> On Tue, 27 May 2014 16:13:46 +0100, Adam Funk wrote: > On 2014-05-23, Chris Angelico wrote: > >> On Fri, May 23, 2014 at 8:27 PM, Adam Funk >> wrote: >>> I've also used hashes of strings for other things involving >>> deduplication or fast lookups (because integer equality is faster than >>> string equality). I guess if it's just for deduplication, though, a >>> set of byte arrays is as good as a set of int? >> >> Want a better way to do that? Use a set or dict and let Python do the >> hashing. It'll be every bit as fast as explicit hashing, plus you get >> the bonus of simplicity. > > Well, here's the way it works in my mind: > > I can store a set of a zillion strings (or a dict with a zillion > string keys), but every time I test "if new_string in seen_strings", > the computer hashes the new_string using some kind of "short hash", > checks the set for matching buckets (I'm assuming this is how python > tests set membership --- is that right?), So far so good. That applies to all objects, not just strings. > then checks any > hash-matches for string equality. Testing string equality is slower > than integer equality, and strings (unless they are really short) > take up a lot more memory than long integers. But presumably you have to keep the string around anyway. It's going to be somewhere, you can't just throw the string away and garbage collect it. The dict doesn't store a copy of the string, it stores a reference to it, and extra references don't cost much. As for string equality, in pseudo-code it looks something like this: def __eq__(self, other): # Consider only the case where other is a string as well. if self is other: # object identity return True if len(self) != len(other): # checking the length is fast return False # iterate over both strings in lock-step for a in self, b in other: if a != b: return False return True only written in fast C code. So the equality test bails out as quickly as possible, and the only time you have to look at every character is if the two strings are equal but not the same object. MD5 hashing, on the other hand, *always* has to look at every character, and perform quite a complicated set of computations. It's expensive. > So for that kind of thing, I tend to store MD5 hashes or something > similar. Is that wrong? First rule of optimization: Don't do it. Second rule of optimization (for experts only): Don't do it yet. You're making the cardinal mistake of optimization, not what is slow, but what you *assume* will be slow. (Or, replace memory consumption for speed if you prefer.) Python is not C, and your intuitions for what's fast and slow (low and high memory consumption) are likely to be way off. Consider trying to store an MD5 hash instead of the string "Hello World!". If I try this in Python 2.7, I get this: py> import md5, sys py> s = "Hello World!" py> n = int(md5.md5(s).hexdigest(), 16) py> sys.getsizeof(s) 33 py> sys.getsizeof(n) 30 I save a lousy 3 bytes. But in order to save that 3 bytes, I have to generate an md5 object (32 bytes) and a hex string (53 bytes), both of which take time to create and then time to garbage collect. Actually, I don't even save those 3 bytes, since for nearly all reasonable applications, I'll need to keep the string around somewhere. So instead of saving three bytes, it's costing me thirty bytes for the hash, plus who-knows-what needed to manage the book keeping to link that hash to the actual string. Ah, but maybe we can save time hashing them? py> from timeit import Timer py> setup = "from __main__ import s, n" py> t1 = Timer("hash(s)", setup) py> t2 = Timer("hash(n)", setup) py> min(t1.repeat(5)) 0.14668607711791992 py> min(t2.repeat(5)) 0.15973114967346191 Times are in seconds for one million iterations of the code being timed. Or alternatively, it costs about 0.14 microseconds to hash the string, and about 0.15 microseconds to hash the MD5 hash. **Not** to calculate the MD5 hash in the first place, that takes *much* longer: py> t3 = Timer("md5.md5(s).hexdigest()", "import md5; s = 'Hello World!'") py> min(t3.repeat(5)) 2.3326950073242188 but merely to perform a lightweight hash on the long int so as to find which bucket of the dict it belongs to. So, yes, chances are **very** good that you're supposed optimizations in this area are actually pessimizations. If you have not measured where the bottlenecks in your code are, you have no idea which parts of the code need to be optimized. Now, it is conceivable that there may be some circumstances where your strategy makes sense. I'm guessing you would need something like this before you even come close to saving memory and/or time: - rather than short keys like "Hello World!", you are dealing with keys that are typically many tens of thousands of characters long; - most of the strings are the same length and have very similar prefixes (e.g. the first 3000 chars are the same); - rather than "zillions" of them, there are few enough of them that the chances of an MD5 collision is insignificant; (Any MD5 collision is going to play havoc with your strategy of using hashes as a proxy for the real string.) - and you can arrange matters so that you never need to MD5 hash a string twice. Is my guess closer to the actuality than yours? I don't know. I haven't measured it either. But I know that Python is a high-level language with lots of high-level data structures like dicts which trade-off time and memory for programmer convenience, and that I'd want to see some real benchmarks proving that my application was too slow before giving up that convenience with a complicated strategy like this. -- Steven D'Aprano http://import-that.dreamwidth.org/ From john_ladasky at sbcglobal.net Tue May 27 14:38:39 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Tue, 27 May 2014 11:38:39 -0700 (PDT) Subject: is there a list/group for beginners? In-Reply-To: References: Message-ID: Hi, Deb. Ten years ago (or eleven?), I was completely new to Python. I could not begin to understand over 90 percent of what I was reading here in comp.lang.python. Still, I asked my newbie questions here. For the most part, I got excellent responses. I think you're in the right place. From rosuav at gmail.com Tue May 27 15:16:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 May 2014 05:16:24 +1000 Subject: hashing strings to integers In-Reply-To: <5384c539$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <05c15bxrpj.ln2@news.ducksburg.com> <5384c539$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 28, 2014 at 3:02 AM, Steven D'Aprano wrote: > But I know that Python is a high-level language with > lots of high-level data structures like dicts which trade-off time and > memory for programmer convenience, and that I'd want to see some real > benchmarks proving that my application was too slow before giving up that > convenience with a complicated strategy like this. And they trade off that time and memory on the basis of X years of development expertise. A while ago (about ten years or so, now... wow, that's quite a while) I wrote a C++ program that needed an ever-growing array; for simplicity, I went with a very basic system of doubling the size every time, from a base of something like 1024 or 8192. (Note that it was storing and moving around only pointers, so it's comparable to Python's list.) That means it has an average 25% slack space at all times, more until its first allocation, and every now and then it has a huge job of copying a pile of pointers into a new array. (Imagine it's now at 16777216 and it needs to add the 16,777,217th string to the array. Bye-bye CPU caches.) These boundaries became *user-visible pauses*, fortunately at predictable points, but on a not-terrible computer it could cause a >1s pause just copying heaps of pointers. How do you think a Python list will perform, under the same workload (periodic appending of single strings or small groups of strings, very frequent retrieval based on index - probably about a 20:1 read:write ratio)? Not only would it be far more convenient, it's probably going to outperform my hand-rolled code - unless I'm so brilliant (or lucky) that I can stumble to something as good as can be achieved with years of dedicated development. Yeah, I don't think so. Same goes for hashing algorithms. I can at least boast that I've never written one of those... although I have several times written a binary tree of one form or another, in order to provide comparable features to a dict. And once again, now that I know how convenient and performant high level languages can be (which may or may not have been true 15 years ago, but I certainly didn't know it), I don't rewrite what can be done better by just tossing in a couple of curly braces and saying "here, map this to that". ChrisA From ndbecker2 at gmail.com Tue May 27 15:56:43 2014 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 27 May 2014 15:56:43 -0400 Subject: help with memory leak Message-ID: I'm trying to track down a memory leak in a fairly large code. It uses a lot of numpy, and a bit of c++-wrapped code. I don't yet know if the leak is purely python or is caused by the c++ modules. At each iteration of the main loop, I call gc.collect() If I then look at gc.garbage, it is empty. I've tried using objgraph. I don't know how to interpret the result. I don't know if this is the main leakage, but I see that each iteration there are more 'Burst' objects. If I look at backrefs to them using this code: for frame in count(1): ## main loop starts here gc.collect() objs = objgraph.by_type('Burst') print(objs) if len (objs) != 0: print(objs[0], gc.is_tracked (objs[0])) objgraph.show_backrefs(objs[0], max_depth=10, refcounts=True) I will get a graph like that attached A couple of strange things. The refcounts (9) of the Burst object don't match the number of arrows into it. There are 2 lists with 0 refs. Why weren't they collected? -------------- next part -------------- A non-text attachment was scrubbed... Name: objgraph-fCFPiC.png Type: image/png Size: 28804 bytes Desc: not available URL: From pecore at pascolo.net Tue May 27 15:56:00 2014 From: pecore at pascolo.net (giacomo boffi) Date: Tue, 27 May 2014 21:56:00 +0200 Subject: Hello and sorry for disturbing ! References: <3948d417-cac6-4730-9736-3c11233bbc04@googlegroups.com> Message-ID: <871tvff12n.fsf@pascolo.net> Rustom Mody writes: > For ubuntu you should need nothing for python. > In other words python should run on a basic ubuntu installation. > From the shell just type python and the interpreter should start. > > For more specialized work there are dozens (maybe hundreds?) of > packages in the apt repos. % apt-cache show python Display all 2776 possibilities? (y or n) From maksufff at gmail.com Tue May 27 16:02:03 2014 From: maksufff at gmail.com (maksufff at gmail.com) Date: Tue, 27 May 2014 13:02:03 -0700 (PDT) Subject: Hello and sorry for disturbing ! In-Reply-To: References: Message-ID: <0532998a-0215-4e44-a5d7-2c4545771ae5@googlegroups.com> I recommend to install PyCharm From maksufff at gmail.com Tue May 27 16:03:46 2014 From: maksufff at gmail.com (maksufff at gmail.com) Date: Tue, 27 May 2014 13:03:46 -0700 (PDT) Subject: Hello and sorry for disturbing ! In-Reply-To: References: Message-ID: <879153d3-b545-4fe9-b874-5886905305b6@googlegroups.com> I recommend you to install PyCharm From maksufff at gmail.com Tue May 27 16:05:48 2014 From: maksufff at gmail.com (maksufff at gmail.com) Date: Tue, 27 May 2014 13:05:48 -0700 (PDT) Subject: Hello and sorry for disturbing ! In-Reply-To: References: Message-ID: <7e75acff-a8ed-4ebc-9a93-a085368224b1@googlegroups.com> I recommend you to install PyCharm From rosuav at gmail.com Tue May 27 16:34:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 May 2014 06:34:49 +1000 Subject: Hello and sorry for disturbing ! In-Reply-To: <871tvff12n.fsf@pascolo.net> References: <3948d417-cac6-4730-9736-3c11233bbc04@googlegroups.com> <871tvff12n.fsf@pascolo.net> Message-ID: On Wed, May 28, 2014 at 5:56 AM, giacomo boffi wrote: > Rustom Mody writes: > >> For ubuntu you should need nothing for python. >> In other words python should run on a basic ubuntu installation. >> From the shell just type python and the interpreter should start. >> >> For more specialized work there are dozens (maybe hundreds?) of >> packages in the apt repos. > > % apt-cache show python > Display all 2776 possibilities? (y or n) Not quite fair, as some of those exist in multiple forms (python-* and python3-*, or -dbg and -dev as well as the base package, or the package-and-subpackage model of large stuff like python-django-*), and on Debian Wheezy I have only (only!) 1890. But yep, that is a lot of packages available in apt. ChrisA From rosuav at gmail.com Tue May 27 16:50:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 May 2014 06:50:36 +1000 Subject: help with memory leak In-Reply-To: References: Message-ID: On Wed, May 28, 2014 at 5:56 AM, Neal Becker wrote: > I'm trying to track down a memory leak in a fairly large code. It uses a lot of > numpy, and a bit of c++-wrapped code. I don't yet know if the leak is purely > python or is caused by the c++ modules. Something to try, which would separate the two types of leak: Run your program in a separate namespace of some sort (eg a function), make sure all your globals have been cleaned up, run a gc collection, and then see if you still have a whole lot more junk around. If that cleans everything up, it's some sort of refloop; if it doesn't, it's either a global you didn't find, or a C-level refleak. ChrisA From python.list at tim.thechases.com Tue May 27 11:02:02 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 27 May 2014 10:02:02 -0500 Subject: Python box (home-use smart router) In-Reply-To: <53843FD6.1040505@gmail.com> References: <53843FD6.1040505@gmail.com> Message-ID: <20140527100202.17726849@bigbox.christie.dr> On 2014-05-27 15:33, animalize81 wrote: > Home-use smart router is more and more popular. > > If embeds Python into such router, and > develops a framework that has the following features: > > 1, allow power-down at any time > 2, dynamic domain name > 3, local storage support (SD cards or Hard Disk) > 4, telnet server > etc. > > Then we can create micro private server on it. It certainly can. I've got a Buffalo router here that runs a stripped-down version of Linux and has Python installed on it. No need for the PSF to get involved because people are already creating these without them. I know that a lot of folks use an old router and put OpenWRT, DD-WRT, or Tomato firmware on them. This would give you a Linux platform on which you can install Python, usually telnet (or more likely, SSH) support, and can be integrated with a number of dynamic-DNS services. You could even grab a Raspberry Pi (model B with ethernet), add a USB ethernet adaptor, and you'd have a pretty nice machine with 512MB of RAM (the router platforms don't usually have more than ~64MB of RAM), two ethernet ports for routing, and would support SD or USB drives. -tkc From breamoreboy at yahoo.co.uk Tue May 27 17:09:52 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 27 May 2014 22:09:52 +0100 Subject: Hello and sorry for disturbing ! In-Reply-To: <0532998a-0215-4e44-a5d7-2c4545771ae5@googlegroups.com> References: <0532998a-0215-4e44-a5d7-2c4545771ae5@googlegroups.com> Message-ID: On 27/05/2014 21:02, maksufff at gmail.com wrote: > I recommend to install PyCharm > Three copies in three minutes of one line with no context, that's a record, congratulations :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From python.list at tim.thechases.com Tue May 27 17:17:57 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 27 May 2014 16:17:57 -0500 Subject: python In-Reply-To: References: Message-ID: <20140527161757.36766d63@bigbox.christie.dr> On 2014-05-27 08:43, himanshulkce at gmail.com wrote: > Need of python in embedded systems??? Define "embedded". I've got a couple small low-powered devices here (a Digi ConnectPort, a Raspberry Pi, a low-end 32-bit system with 32MB of RAM) all of which run Python. It might be trickier if you're talking about some super low-end hardware where you don't have a memory management unit, a full-fledged OS. -tkc From codemonkey at inbox.com Tue May 27 17:38:36 2014 From: codemonkey at inbox.com (Deb Wyatt) Date: Tue, 27 May 2014 13:38:36 -0800 Subject: is there a list/group for beginners? In-Reply-To: References: Message-ID: <7C8185E3C23.000005F1codemonkey@inbox.com> > -----Original Message----- > From: john_ladasky at sbcglobal.net > Sent: Tue, 27 May 2014 11:38:39 -0700 (PDT) > To: python-list at python.org > Subject: Re: is there a list/group for beginners? > > Hi, Deb. > > Ten years ago (or eleven?), I was completely new to Python. I could not > begin to understand over 90 percent of what I was reading here in > comp.lang.python. Still, I asked my newbie questions here. For the most > part, I got excellent responses. I think you're in the right place. > -- > https://mail.python.org/mailman/listinfo/python-list thanks,John. I guess I was/am afraid to embarrass myself on this list, but then I accidentally posted a question meant for the tutor list and ended up getting more for my money than I expected :). I really appreciate that the people on this list are so friendly and willing to help. ____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! Check it out at http://www.inbox.com/earth From rosuav at gmail.com Tue May 27 18:05:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 May 2014 08:05:02 +1000 Subject: is there a list/group for beginners? In-Reply-To: <7C8185E3C23.000005F1codemonkey@inbox.com> References: <7C8185E3C23.000005F1codemonkey@inbox.com> Message-ID: On Wed, May 28, 2014 at 7:38 AM, Deb Wyatt wrote: > thanks,John. I guess I was/am afraid to embarrass myself on this list, but then I accidentally posted a question meant for the tutor list and ended up getting more for my money than I expected :). I really appreciate that the people on this list are so friendly and willing to help. > Asking "newbie questions" isn't going to get you flamed here, we're pretty friendly :) Anyway, we're all newbies in whatever areas we haven't actually dug into. (I denewbified myself in Flask just last week, and there's plenty more of Python that I've never touched.) So go for it, ask those questions! Reveal your ignorance. Let us reveal ours, as we make errors in responses. And by the end of the thread, all the errors will have been corrected and the ignorance cured... and we'll all have learned. That, in my books, is a recipe for an awesome thread. Bring it on! ChrisA From ps16thypresenceisfullnessofjoy at gmail.com Tue May 27 19:01:34 2014 From: ps16thypresenceisfullnessofjoy at gmail.com (ps16thypresenceisfullnessofjoy at gmail.com) Date: Tue, 27 May 2014 16:01:34 -0700 (PDT) Subject: Command prompt not shown when running Python script with subprocess on Windows In-Reply-To: References: <29c26176-b573-4ac9-bf41-a18a53d7dfb9@googlegroups.com> Message-ID: Sorry for not being explicit enough. I am aware that this would work if I called python.exe path-to-script.py with shell=False. In my Python program, I parse an XML file like the one I have included below. Then I loop through the paths of the apps listed in it and run them by calling something like this: for app_path in app_paths: args = shlex.split(app_path.replace("\\", "\\\\")) args = [arg.replace("\\\\", "\\") for arg in args] args[0] = os.path.expandvars(args[0]) subprocess.Popen(args, shell='__WXMSW__' in wx.PlatformInfo) I want users to be able to enter paths in the XML file exactly the way they would be entered in a Windows shortcut. Since it is possible to make a Windows shortcut for path-to-script.py without the python.exe in front of it and have it open in its own command prompt, I want to be able to do the same thing in my XML file, but this is what I cannot figure out. By the way, is there a simpler way to use shlex.split and return valid Windows paths than the way I am doing (as shown above)? Thank you. -- Timothy *** Contents of app_list.xml below *** %ProgramFiles%\Mozilla Firefox\firefox.exe %ProgramFiles%\Mozilla Thunderbird\thunderbird.exe %ProgramFiles%\LibreOffice 4\program\swriter.exe "C:\Users\Timothy\Documents\myfile.odt" C:\Users\Timothy\Documents\Python\myscript.py From dan at tombstonezero.net Tue May 27 21:55:15 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 28 May 2014 01:55:15 +0000 (UTC) Subject: hashing strings to integers References: <05c15bxrpj.ln2@news.ducksburg.com> <5384c539$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 27 May 2014 17:02:50 +0000, Steven D'Aprano wrote: > - rather than "zillions" of them, there are few enough of them that > the chances of an MD5 collision is insignificant; > (Any MD5 collision is going to play havoc with your strategy of > using hashes as a proxy for the real string.) > - and you can arrange matters so that you never need to MD5 hash a > string twice. Hmmm... I'll use the MD5 hashes of the strings as a key, and the strinsgs as the value (to detect MD5 collisions) ... (But I'm sure that Steven was just waiting for someone to take that bait...) From mail at timgolden.me.uk Wed May 28 01:08:35 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 28 May 2014 06:08:35 +0100 Subject: Command prompt not shown when running Python script with subprocess on Windows In-Reply-To: References: <29c26176-b573-4ac9-bf41-a18a53d7dfb9@googlegroups.com> Message-ID: <53856F53.5010303@timgolden.me.uk> On 28/05/2014 00:01, ps16thypresenceisfullnessofjoy at gmail.com wrote: > I want users to be able to enter paths in the XML file exactly the > way they would be entered in a Windows shortcut. Since it is possible > to make a Windows shortcut for path-to-script.py without the > python.exe in front of it and have it open in its own command prompt, > I want to be able to do the same thing in my XML file, but this is > what I cannot figure out. Anything done through shortcuts is making use of the Windows Shell API. To mimic that behaviour, you could try using that; in this case, ShellExecute[Ex]. For simple purposes, this is exposed in Python as os.startfile. If you need more control, you'd have to use the API call directly, either via ctypes or via the pywin32 libraries under the win32com.shell package. To mimic the behaviour exactly (if that is a requirement), you could actually create a temporary shortcut with the desired information and invoke it via os.startfile. I haven't followed the thread (and I'm offline at the moment) so I'll wait until I've seen it before I comment on the shlex.split / \\ dance above. On the surface, though, I'm not sure what it's achieving. [All right, I didn't wait :)]. TJG From onlyvinish at gmail.com Wed May 28 03:44:30 2014 From: onlyvinish at gmail.com (onlyvinish at gmail.com) Date: Wed, 28 May 2014 00:44:30 -0700 (PDT) Subject: How to run script from interpreter? In-Reply-To: References: Message-ID: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> On Friday, January 19, 2001 1:22:23 AM UTC+5:30, Rolander, Dan wrote: > What is the best way to run a python script from within the interpreter? > What command should I use? > > Thanks, > Dan try using execfile(filename) From info at egenix.com Wed May 28 04:14:21 2014 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 28 May 2014 10:14:21 +0200 Subject: ANN: eGenix mxODBC Connect 2.1.0 - Python ODBC Database Interface Message-ID: <53859ADD.4070702@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Connect Python ODBC Database Interface Version 2.1.0 mxODBC Connect is our commercially supported client-server product for connecting Python applications to relational databases in a truly platform independent way. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Connect-2.1.0-GA.html ________________________________________________________________________ INTRODUCTION The mxODBC Connect Database Interface for Python allows users to easily connect Python applications to all major databases on the market today in a highly portable, convenient and secure way. Python Database Connectivity the Easy Way ----------------------------------------- Unlike our mxODBC Python extension, mxODBC Connect is designed as client-server application, so you no longer need to find production quality ODBC drivers for all the platforms you target with your Python application. Instead you use an easy to install royalty-free Python client library which connects directly to the mxODBC Connect database server over the network. This makes mxODBC Connect a great basis for writing cross-platform multi-tier database applications and utilities in Python, especially if you run applications that need to communicate with databases such as MS SQL Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more, that run on Windows or Linux machines. Ideal for Database Driven Client Applications --------------------------------------------- By removing the need to install and configure ODBC drivers on the client side and dealing with complicated network setups for each set of drivers, mxODBC Connect greatly simplifies deployment of database driven client applications, while at the same time making the network communication between client and database server more efficient and more secure. For more information, please have a look at the mxODBC Connect product page, in particular, the full list of available features. For more information, please see the product page: http://www.egenix.com/products/python/mxODBCConnect/ ________________________________________________________________________ NEWS mxODBC Connect 2.1.0 is a new minor release of our successful mxODBC Connect product. These are the changes compared to mxODBC Connect 2.0.5. Update to the mxODBC 3.3 API ---------------------------- mxODBC Connect 2.1 upgrades the mxODBC Connect Client to the new mxODBC 3.3. APIs and enhancements. Stored Procedures * mxODBC Connect now has full support for input, output and input/output parameters in stored procedures and stored functions, allowing easy integration with existing databases systems. User Customizable Row Objects * Added support for user customizable row objects by adding cursor/connection .rowfactory and .row constructor attributes. When set, these are used to wrap the normal row tuples returned by the .fetch*() methods into dynamically created row objects. * Added new RowFactory classes to support cursor.rowfactory and cursor.row. These allow dynamically creating row classes that provide sequence as well as mapping and attribute access to row fields - similar to what namedtuples implements, but more efficient and specific to result sets. Fast Cursor Types * Switched to forward-only cursor types for all database backends, since this provides a much better performance for MS SQL Server and IBM DB2 drivers. * Added a new .cursortype attribute to allow adjusting and inspecting the ODBC cursor type to be used for an mxODBC Connect cursor object. Default is to use forward-only cursors, but mxODBC also support several other useful cursor types such as static cursors with full support for result set scrolling. More new Features * Enhanced cursor.prepare() to allow querying cursor.description right after the prepare step and not only after calling a cursor.execute*() method. * Added iterator/generator support to .executemany(). The parameters list can now be an iterator/generator, if needed. * Added new connection.dbapi property to easily access module level symbols from the connection object. * Timestamp seconds fraction resolution is now determined from the scale of a datetime/timestamp SQL column, using the connection.timestampresolution as lower bound, when using SQL type binding. In Python type binding mode, the connection.timestampresolution determines the scale with which a variable is bound. This allows for greater flexibility when dealing with database backends that don't provide full nano-second second resolution, such as e.g. MS SQL Server. * mxODBC Connect accepts Unicode string values for date/time/datetime/timestamp column types in SQL type binding mode. Previous versions already did in Python type binding mode. * mxODBC Connect uses unicode(obj, encoding) semantics when binding Python objects to SQLWCHAR Unicode database parameters to provide better compatibility with Python objects. Additionally, it ignores the encoding in case obj is a number, to avoid conversion errors. * Added new cursor.encoding attribute. This gets its default values from the connection the cursor was created on and allows for per-cursor encoding settings. * Added cursor.bindmethod which inherits from connection.bindmethod when creating the cursor. This allows adjusting the variable bind method on a per-cursor basis, rather than only on a per connection basis as in previous mxODBC Connect versions. mxODBC Connect API Enhancements ------------------------------- * The SQL lookup object is cached on the client side to avoid frequent roundtrips when using symbols which are needed for stored procedures with input/output parameters. * The SQL lookup object received support for new ODBC 3.8 symbols and values, including driver specific symbols used by the MS SQL Server Native Client and IBM DB2 ODBC drivers. * Improved the server side object management to simplify client side garbage collection considerations. Even though we still encourage using explicit garbage collection of cursors, connections and server sessions on the client side, mxODBC Connect Server will now handle most situations even without these explicit calls. Asynchronous Processing ----------------------- * Tested with the latest gevent and greenlet packages. mxODBC Connect Client will happily work together with the asynchronous libraries gevent. All it takes is a single configuration entry in the client side config file. Security Enhancements --------------------- * Changed the way passwords are stored in the server's authorized-users.txt file in order to make password storage more secure. * User authentication now uses salted SHA-256 password hashes when transferring the login data from the client to the server. This provides better protection when using plain text client server setups and additional security over SSL network connections. ODBC Driver/Manager Compatibility Enhancements ---------------------------------------------- unixODBC * mxODBC Connect Server is now built against unixODBC 2.3.2 on Linux. DataDirect * Updated the DataDirect binding to version 7.1.2 of the DataDirect ODBC manager on Linux. Oracle * Added work-around for Oracle Instant Client to be able to use integer output parameters. * Added a work-around for Oracle Instant Client to have it return output parameters based on the input placeholder Python parameter types. It would otherwise return all parameters as strings. Disabled a test for Oracle Instant Client which tries to set a pre-connect connection option for timeouts, since the ODBC driver segfaults with this option. MS SQL Server * mxODBC Connect Server 2.1 defaults to 100ns connection.timestampresolution for MS SQL Server 2008 and later, and 1ms resolution for MS SQL server 2005 and earlier. This simplifies interfacing to SQL Server timestamp columns by preventing occasional precision errors. * Tested mxODBC Connect Server successfully with new MS SQL Server Native Client 11 for Linux. Unicode connection strings still don't work, but everything else does. * Added documentation on how to use Kerberos with mxODBC and SQL Server for authentication on both Windows and Linux to the mxODBC User Manual. * Added note about problems of the FreeTDS ODBC driver dealing with TIME and DATE columns. Sybase ASE * Added work-around for the Sybase ASE ODBC driver, which doesn't always pass back NULL correctly to mxODBC Connect Server on 64-bit Unix systems. * Changed the variable type binding mode default for the Sybase ASE ODBC driver from Python type binding to SQL type binding, which resolves issues with e.g. the Unicode support for that driver. * Added note about a segfault problem with the Sybase ASE 15.7 ODBC driver which is caused by the driver corrupting the heap. IBM DB2 * Added work-around for the IBM DB2 ODBC driver, which doesn't always pass back NULL correctly to mxODBC Connect Server on 64-bit Unix systems. PostgreSQL * Added work-around to force Python type binding for the PostgreSQL ODBC drivers. More recent versions of the driver report supporting SQL type binding, but they don't implement it. * Added work-around to have PostgreSQL ODBC drivers properly work with binary data for BYTEA columns. MySQL * mxODBC Connect Server now supports native Unicode with the recent MySQL ODBC drivers - provided you use the Unicode variants of the drivers. * Changed the default binding mode for MySQL ODBC drivers to Python type binding. This works around a problem with date/time values when talking to MySQL 5.6 servers. For the full set of changes, including those of the 2.0 series of mxODBC Connect, please check the mxODBC Connect change log. http://www.egenix.com/products/python/mxODBCConnect/changelog.html ________________________________________________________________________ UPGRADING You are encouraged to upgrade to this latest mxODBC Connect release. When upgrading, please always upgrade both the server and the client installations to the same version - even for patch level releases. We will give out 20% discount coupons for upgrade purchases going from mxODBC Connect Server 1.x to 2.1 and 50% coupons for upgrades from mxODBC 2.x to 2.1. Please contact the eGenix.com Sales Team (sales at egenix.com) with your existing license serials for details. Users of our stand-alone mxODBC product will have to purchase new licenses from our online shop in order to use mxODBC Connect. You can request free 30-day evaluation licenses by visiting our web-site or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. http://www.egenix.com/products/python/mxODBCConnect/#Evaluation ________________________________________________________________________ DOWNLOADS The download archives as well as instructions for installation and configuration of the product can be found on the product page: http://www.egenix.com/products/python/mxODBCConnect/ If you want to try the package, jump straight to the download instructions: https://cms.egenix.com/products/python/mxODBCConnect/#Download Fully functional evaluation licenses for the mxODBC Connect Server are available free of charge: http://www.egenix.com/products/python/mxODBCConnect/#Evaluation mxODBC Connect Client is always free of charge. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert project services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, May 28 2014) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From alister.nospam.ware at ntlworld.com Wed May 28 04:41:28 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 28 May 2014 08:41:28 GMT Subject: is there a list/group for beginners? References: Message-ID: On Tue, 27 May 2014 13:38:36 -0800, Deb Wyatt wrote: >> -----Original Message----- >> From: john_ladasky at sbcglobal.net Sent: Tue, 27 May 2014 11:38:39 -0700 >> (PDT) >> To: python-list at python.org Subject: Re: is there a list/group for >> beginners? >> >> Hi, Deb. >> >> Ten years ago (or eleven?), I was completely new to Python. I could >> not begin to understand over 90 percent of what I was reading here in >> comp.lang.python. Still, I asked my newbie questions here. For the >> most part, I got excellent responses. I think you're in the right >> place. >> -- >> https://mail.python.org/mailman/listinfo/python-list > > thanks,John. I guess I was/am afraid to embarrass myself on this list, > but then I accidentally posted a question meant for the tutor list and > ended up getting more for my money than I expected :). I really > appreciate that the people on this list are so friendly and willing to > help. > > ____________________________________________________________ > FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! > Check it out at http://www.inbox.com/earth To Avoid the biggest risk of upsetting people here it would help you to understand the failings of google groups which makes your posts hard to read for people using the Newsgroup or mailing list https://wiki.python.org/moin/GoogleGroupsPython -- There is no royal road to geometry. -- Euclid From himanshulkce at gmail.com Wed May 28 06:03:08 2014 From: himanshulkce at gmail.com (himanshulkce) Date: Wed, 28 May 2014 05:03:08 -0500 Subject: python #13 References: Message-ID: Thank you sir.... From lakshmipathi.g at gmail.com Wed May 28 06:22:42 2014 From: lakshmipathi.g at gmail.com (Lakshmipathi.G) Date: Wed, 28 May 2014 15:52:42 +0530 Subject: how avoid delay while returning from C-python api? Message-ID: Hi - I have C-Python api like below. It works fine, but the problem is while invoking this method from python script say #cat script.py offset=0 size=4 write_object(offset,size) This calls write_this_c() C api and returns quickly to next printf statement. But the return call (Py_RETURN_NONE) takes something like 4-6 seconds. ----- static PyMethodDef xyz_methods[] = { {"write_object", write_object, METH_VARARGS,"write some stuff "}, {NULL, NULL, 0, NULL} }; ---- static PyObject * write_object(PyObject *self, PyObject *args) { int offset, size; if (!PyArg_ParseTuple(args,"ii", &offset, &size)) Py_RETURN_NONE; printf("before call"); write_this_c(offset, size); printf("after call"); Py_RETURN_NONE; ##delay happens here } How to avoid this delay time? Thanks for any help/pointers! ---- ---- Cheers, Lakshmipathi.G FOSS Programmer. www.giis.co.in From sameer.rathoud at gmail.com Wed May 28 06:43:29 2014 From: sameer.rathoud at gmail.com (Sameer Rathoud) Date: Wed, 28 May 2014 03:43:29 -0700 (PDT) Subject: IDE for python Message-ID: Hello everyone, I am new to python. I am currently using python 3.3 With python I got IDLE, but I am not very comfortable with this. Please suggest, if we have any free ide for python development. From scrappedprince.li at gmail.com Wed May 28 06:51:44 2014 From: scrappedprince.li at gmail.com (cheng.li) Date: Wed, 28 May 2014 18:51:44 +0800 Subject: =?gb2312?B?tPC4tDogSURFIGZvciBweXRob24=?= In-Reply-To: References: Message-ID: <016901cf7a62$d4d18bc0$7e74a340$@gmail.com> IPython for interactive testing. Aptana or PyDev + eclipse as IDE -----????----- ???: Python-list [mailto:python-list-bounces+scrappedprince.li=gmail.com at python.org] ?? Sameer Rathoud ????: 2014?5?28? 18:43 ???: python-list at python.org ??: IDE for python Hello everyone, I am new to python. I am currently using python 3.3 With python I got IDLE, but I am not very comfortable with this. Please suggest, if we have any free ide for python development. -- https://mail.python.org/mailman/listinfo/python-list From marko at pacujo.net Wed May 28 06:50:16 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 28 May 2014 13:50:16 +0300 Subject: IDE for python References: Message-ID: <87iooqw51z.fsf@elektro.pacujo.net> Sameer Rathoud : > Please suggest, if we have any free ide for python development. emacs Marko From ned at nedbatchelder.com Wed May 28 06:57:09 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 28 May 2014 06:57:09 -0400 Subject: how avoid delay while returning from C-python api? In-Reply-To: References: Message-ID: On 5/28/14 6:22 AM, Lakshmipathi.G wrote: > Hi - > > I have C-Python api like below. It works fine, but the problem is > while invoking this method > from python script say > > #cat script.py > > offset=0 > size=4 > write_object(offset,size) > > > > This calls write_this_c() C api and returns quickly to next printf statement. > But the return call (Py_RETURN_NONE) takes something like 4-6 seconds. > > ----- > static > PyMethodDef xyz_methods[] = { > {"write_object", write_object, METH_VARARGS,"write some stuff "}, > {NULL, NULL, 0, NULL} > }; > > > ---- > static PyObject * > write_object(PyObject *self, PyObject *args) > { > int offset, size; > if (!PyArg_ParseTuple(args,"ii", &offset, &size)) > Py_RETURN_NONE; > > printf("before call"); > write_this_c(offset, size); > printf("after call"); > Py_RETURN_NONE; ##delay happens here > } > > How to avoid this delay time? Thanks for any help/pointers! It can't be as simple as the Py_RETURN_NONE taking 4-6 seconds: hundreds of built-in functions in Python are coded exactly this way, and they don't have a delay on return. Something else is going on. How did you determine that it was the return that was taking the time? > > > ---- > ---- > Cheers, > Lakshmipathi.G > FOSS Programmer. > www.giis.co.in > -- Ned Batchelder, http://nedbatchelder.com From alister.nospam.ware at ntlworld.com Wed May 28 07:03:32 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 28 May 2014 11:03:32 GMT Subject: IDE for python References: Message-ID: <8ojhv.185057$ub6.86481@fx32.am4> On Wed, 28 May 2014 03:43:29 -0700, Sameer Rathoud wrote: > Hello everyone, > > I am new to python. > > I am currently using python 3.3 > > With python I got IDLE, but I am not very comfortable with this. > > Please suggest, if we have any free ide for python development. there Are plenty I use Geany a lightweight cross platform editor but you will probably get as (at least as )many different answers as there are posters here :-) -- Time is the most valuable thing a man can spend. -- Theophrastus From mihamina.rakotomandimby at rktmb.org Wed May 28 06:51:22 2014 From: mihamina.rakotomandimby at rktmb.org (Mihamina Rakotomandimby) Date: Wed, 28 May 2014 13:51:22 +0300 Subject: IDE for python In-Reply-To: References: Message-ID: <5385BFAA.30705@rktmb.org> On 05/28/2014 01:43 PM, Sameer Rathoud wrote: > Please suggest, if we have any free ide for python development. I think major IDEs in the place have their Python integration. Did you make some search and tried each one? With just the information you provided, every existing IDE is OK. - What didnt you like in IDLE? - What IDE do you use for anything else thant Python? From lakshmipathi.g at gmail.com Wed May 28 07:18:35 2014 From: lakshmipathi.g at gmail.com (Lakshmipathi.G) Date: Wed, 28 May 2014 16:48:35 +0530 Subject: how avoid delay while returning from C-python api? In-Reply-To: References: Message-ID: The statement "after call" printed to stdout and the script waits there for few seconds. So I was assuming something delaying the return value. Just found out there is core-dump "segmentation fault (core dumped) python" ..Probably fixing core dump should resolve the issue. Thanks! ---- Cheers, Lakshmipathi.G FOSS Programmer. www.giis.co.in From rosuav at gmail.com Wed May 28 07:33:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 May 2014 21:33:00 +1000 Subject: IDE for python In-Reply-To: References: Message-ID: On Wed, May 28, 2014 at 8:43 PM, Sameer Rathoud wrote: > I am currently using python 3.3 > > With python I got IDLE, but I am not very comfortable with this. > > Please suggest, if we have any free ide for python development. You don't really need an IDE, generally. A good text editor - I use SciTE, but as alister said, there are as many viable answers as there are posters - is all you need. Back when I wrote code in Q-BASIC, VX-REXX, and then C and C++, I used IDEs, but even then the main features I used were just smart text editors. My preferred "IDE", these days, is Debian Linux with Xfce, which gives me a convenient workspace in which to run SciTE plus a few dozen terminal windows. One of them will be dedicated to source control (git, hg, or whatever the current project uses); some of those do have GUI interfaces or editor integration, but I find it easiest to use the command line. Another generally is for running the program, unless it's one that permanently stays running (or is being remotely manipulated via a TCP/IP link). Then, depending on what I'm doing, I might have a few more... maybe a music player (or maybe that's VLC, invoked via the Yosemite Project), maybe a few man pages, whatever else I need. It's highly unlikely that anyone's written an IDE that does everything I could possibly want, so I just use the computer's desktop as that IDE. It can do anything! :) ChrisA From sameer.rathoud at gmail.com Wed May 28 07:31:52 2014 From: sameer.rathoud at gmail.com (Sameer Rathoud) Date: Wed, 28 May 2014 04:31:52 -0700 (PDT) Subject: IDE for python In-Reply-To: References: Message-ID: <798134c1-3c0b-4ad2-99ef-d65b2101e3dc@googlegroups.com> On Wednesday, May 28, 2014 4:21:22 PM UTC+5:30, Mihamina Rakotomandimby wrote: > On 05/28/2014 01:43 PM, Sameer Rathoud wrote: > > > Please suggest, if we have any free ide for python development. > > > > I think major IDEs in the place have their Python integration. > > Did you make some search and tried each one? > > > > With just the information you provided, every existing IDE is OK. > > > > - What didnt you like in IDLE? > > - What IDE do you use for anything else thant Python? for C++ and C# development I prefer visual studio and for C++ try outs even codeblock is ok For Java I use eclipse. But first time I am trying python. I was trying some UI with python. I have installed wingide. But i didn't liked it because for licenses messages even in trial version. I was searching for spyder, but didn't got any helpful installable. From rosuav at gmail.com Wed May 28 08:00:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 May 2014 22:00:14 +1000 Subject: IDE for python In-Reply-To: <798134c1-3c0b-4ad2-99ef-d65b2101e3dc@googlegroups.com> References: <798134c1-3c0b-4ad2-99ef-d65b2101e3dc@googlegroups.com> Message-ID: On Wed, May 28, 2014 at 9:31 PM, Sameer Rathoud wrote: > for C++ and C# development I prefer visual studio and for C++ try outs even codeblock is ok > > For Java I use eclipse. > > But first time I am trying python. I was trying some UI with python. I have installed wingide. But i didn't liked it because for licenses messages even in trial version. > > I was searching for spyder, but didn't got any helpful installable. Yep, so you're accustomed to an IDE. But just try a good editor like SciTE or Geany or emacs (or ... or ... or ...), and see how you like it. As an added bonus, you can get to know one editor and use it for everything, rather than having separate IDEs for separate languages. ChrisA From prash.bg at gmail.com Wed May 28 08:11:05 2014 From: prash.bg at gmail.com (prashanth B.G) Date: Wed, 28 May 2014 17:41:05 +0530 Subject: IDE for python In-Reply-To: <798134c1-3c0b-4ad2-99ef-d65b2101e3dc@googlegroups.com> References: <798134c1-3c0b-4ad2-99ef-d65b2101e3dc@googlegroups.com> Message-ID: Hi Sameer, Try pycharm, ninja ide, wings ide .. These are light and will help you to get started. Later on you can switch to vim which has many plugins for python. Also feel free to take a look at this link on stackoverflow comparing different features . http://stackoverflow.com/questions/81584/what-ide-to-use-for-python Thanks. On Wed, May 28, 2014 at 5:01 PM, Sameer Rathoud wrote: > On Wednesday, May 28, 2014 4:21:22 PM UTC+5:30, Mihamina Rakotomandimby > wrote: > > On 05/28/2014 01:43 PM, Sameer Rathoud wrote: > > > > > Please suggest, if we have any free ide for python development. > > > > > > > > I think major IDEs in the place have their Python integration. > > > > Did you make some search and tried each one? > > > > > > > > With just the information you provided, every existing IDE is OK. > > > > > > > > - What didnt you like in IDLE? > > > > - What IDE do you use for anything else thant Python? > > for C++ and C# development I prefer visual studio and for C++ try outs > even codeblock is ok > > For Java I use eclipse. > > But first time I am trying python. I was trying some UI with python. I > have installed wingide. But i didn't liked it because for licenses messages > even in trial version. > > I was searching for spyder, but didn't got any helpful installable. > -- > https://mail.python.org/mailman/listinfo/python-list > -- *****HAVE A NICE DAY ***** Prashanth -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed May 28 08:35:08 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 28 May 2014 13:35:08 +0100 Subject: IDE for python In-Reply-To: <798134c1-3c0b-4ad2-99ef-d65b2101e3dc@googlegroups.com> References: <798134c1-3c0b-4ad2-99ef-d65b2101e3dc@googlegroups.com> Message-ID: On 28/05/2014 12:31, Sameer Rathoud wrote: > On Wednesday, May 28, 2014 4:21:22 PM UTC+5:30, Mihamina Rakotomandimby wrote: >> On 05/28/2014 01:43 PM, Sameer Rathoud wrote: >> >>> Please suggest, if we have any free ide for python development. >> >> >> >> I think major IDEs in the place have their Python integration. >> >> Did you make some search and tried each one? >> >> >> >> With just the information you provided, every existing IDE is OK. >> >> >> >> - What didnt you like in IDLE? >> >> - What IDE do you use for anything else thant Python? > > for C++ and C# development I prefer visual studio and for C++ try outs even codeblock is ok > > For Java I use eclipse. Get the pydev plugin for eclipse. Pydev uses pylint to flag up errors or warnings as you type, saves hours of work. > > But first time I am trying python. I was trying some UI with python. I have installed wingide. But i didn't liked it because for licenses messages even in trial version. > > I was searching for spyder, but didn't got any helpful installable. > Also would you please use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From gmschroeder at gmail.com Wed May 28 07:46:41 2014 From: gmschroeder at gmail.com (Greg Schroeder) Date: Wed, 28 May 2014 18:46:41 +0700 Subject: IDE for python In-Reply-To: <87iooqw51z.fsf@elektro.pacujo.net> References: <87iooqw51z.fsf@elektro.pacujo.net> Message-ID: <1401277601.6327.9.camel@greg-Lenovo-G480> > > Please suggest, if we have any free ide for python development. Anything that writes text is fine. I recommend the standard text editor for your OS (Notepad if you use Windows, Textedit on Mac, whatever is on your GNU/Linux distro by default) unless you know exactly what you don't like about it. Greg From varun7rs at gmail.com Wed May 28 08:41:23 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Wed, 28 May 2014 05:41:23 -0700 (PDT) Subject: Unable to figure out ' invalid matrix input type -- ', u'1' Message-ID: <103633e5-26be-4b53-a8c4-e2ca8c41b103@googlegroups.com> Hello Everyone, I am currently working on Cplex using Python API. I have a problem when I run the code. I keep getting this error about the invalid matrix input but I'm not able to figure out what it is. I would be grateful if any of you could help. My function is as below def add_constraint(self, variables, coefficients, sense, rhs, name): self.prob.linear_constraints.add( lin_expr = [[ variables, coefficients ]], senses = [sense], rhs = [rhs], names = [name] ) Traceback (most recent call last): File "RW10.py", line 569, in main(sys.argv[1:]) File "RW10.py", line 562, in main solveVNEProblem( phy_network, demands, args.output) File "RW10.py", line 116, in solveVNEProblem solver.add_constraint( varNames, varCoeffs, "E", 1.0, "Location_Constraints1{}".format( demand.demandID ) ) File "RW10.py", line 26, in add_constraint names = [name] ) File "/opt/ibm/ILOG/CPLEX_Studio125/cplex/python/x86-64_sles10_4.1/cplex/_internal/_subinterfaces.py", line 1187, in add rmat = _C_HBMatrix(lin_expr, self._cplex._env_lp_ptr, 0, self._env.parameters.read.apiencoding.get()) File "/opt/ibm/ILOG/CPLEX_Studio125/cplex/python/x86-64_sles10_4.1/cplex/_internal/_matrices.py", line 74, in __init__ raise TypeError(" invalid matrix input type -- ", self._mat[0]) TypeError: (' invalid matrix input type -- ', u'1') Thank You From rosuav at gmail.com Wed May 28 08:55:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 May 2014 22:55:35 +1000 Subject: IDE for python In-Reply-To: <1401277601.6327.9.camel@greg-Lenovo-G480> References: <87iooqw51z.fsf@elektro.pacujo.net> <1401277601.6327.9.camel@greg-Lenovo-G480> Message-ID: On Wed, May 28, 2014 at 9:46 PM, Greg Schroeder wrote: >> > Please suggest, if we have any free ide for python development. > > Anything that writes text is fine. > I recommend the standard text editor for your OS (Notepad if you use > Windows, Textedit on Mac, whatever is on your GNU/Linux distro by > default) unless you know exactly what you don't like about it. No. Don't use Notepad for anything! It's easy enough to get a better editor. Among its other faults, Notepad: 1) Has problems with LF line endings (they vanish, and you have hugely long lines) 2) Puts three junk bytes onto the beginning of a file that it considers saved as UTF-8 3) Doesn't understand coding cookies, and will happily save something in a different encoding like CP-1252 (which it calls "ANSI") 4) Guesses encodings on load, giving rise to the famous "Bush hid the facts" trick - although this is unlikely to be a problem with something of decent size 5) Has issues with large files - or at least, it did last time I tried; this may no longer be true with Windows 7/8 Default text editors on the Linux distros I've used have been far better, but still less than ideal. With Debian Squeeze, I got a gedit that bugged me in several ways, which is what pushed me onto SciTE. You can certainly start coding with gedit, though. The issues that I had with it were relating to heavy-duty usage that I do, where I'm basically spending an entire day delving into code and moving stuff around. These days, though, I'd rather have one editor on both the platforms I use (Windows and Linux, each in multiple variants), as it allows me to share configs and comfortable keystrokes. There are plenty of cross-platform editors to choose from. So, I agree with your analysis, as regards gedit ("know exactly what you don't like about it"). If it doesn't bug you, use it. But if Notepad doesn't bug you, *still don't use it*, because it's like driving a car that isn't structurally sound. It might not be you that gets hurt by it... or it might not be for quite a while that you see the problems... but the pain will happen. ChrisA From sameer.rathoud at gmail.com Wed May 28 08:56:46 2014 From: sameer.rathoud at gmail.com (Sameer Rathoud) Date: Wed, 28 May 2014 05:56:46 -0700 (PDT) Subject: IDE for python In-Reply-To: References: <87iooqw51z.fsf@elektro.pacujo.net> Message-ID: <026d97e2-14f8-485f-b1a5-00dff63af8e1@googlegroups.com> On Wednesday, May 28, 2014 5:16:41 PM UTC+5:30, Greg Schroeder wrote: > > > Please suggest, if we have any free ide for python development. > > > > Anything that writes text is fine. > > I recommend the standard text editor for your OS (Notepad if you use > > Windows, Textedit on Mac, whatever is on your GNU/Linux distro by > > default) unless you know exactly what you don't like about it. > > > > Greg Right now I am looking for ide on windows 7 platform. Actually, I shouldn't say this, But I am bit use to intellisense and on go warnings and error and my text editor (Notepad) doesn't provide me that feature . From sameer.rathoud at gmail.com Wed May 28 09:01:55 2014 From: sameer.rathoud at gmail.com (Sameer Rathoud) Date: Wed, 28 May 2014 06:01:55 -0700 (PDT) Subject: IDE for python In-Reply-To: <026d97e2-14f8-485f-b1a5-00dff63af8e1@googlegroups.com> References: <87iooqw51z.fsf@elektro.pacujo.net> <026d97e2-14f8-485f-b1a5-00dff63af8e1@googlegroups.com> Message-ID: <4f2e31da-5b4f-4f67-b82f-bfb413b87708@googlegroups.com> On Wednesday, May 28, 2014 6:26:46 PM UTC+5:30, Sameer Rathoud wrote: > On Wednesday, May 28, 2014 5:16:41 PM UTC+5:30, Greg Schroeder wrote: > > > > > Please suggest, if we have any free ide for python development. > > > > > > > > > > > > Anything that writes text is fine. > > > > > > I recommend the standard text editor for your OS (Notepad if you use > > > > > > Windows, Textedit on Mac, whatever is on your GNU/Linux distro by > > > > > > default) unless you know exactly what you don't like about it. > > > > > > > > > > > > Greg > > > > Right now I am looking for ide on windows 7 platform. > > > > Actually, I shouldn't say this, But I am bit use to intellisense and on go warnings and error and my text editor (Notepad) doesn't provide me that feature . one more query, do we have any add-in available for python on visual studio 2010 From steve+comp.lang.python at pearwood.info Wed May 28 09:04:55 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 May 2014 13:04:55 GMT Subject: IDE for python References: Message-ID: <5385def6$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 May 2014 03:43:29 -0700, Sameer Rathoud wrote: > Hello everyone, > > I am new to python. > > I am currently using python 3.3 > > With python I got IDLE, but I am not very comfortable with this. > > Please suggest, if we have any free ide for python development. What operating system are you using? The best IDE for Python is Unix or Linux: http://blog.sanctum.geek.nz/series/unix-as-ide/ My IDE is to have three GUI windows open: * A web browser for searching the Internet. Any browser will do, but I prefer Firefox. * A tabbed editor. I prefer kate (KDE 3 version, not KDE 4), but geany is also good. At a pinch gedit will do. kwrite is another good editor, but not tabbed, and it lacks some of the features of kate. * An xterm or console app, again with tabs. I like KDE 3's konsole, but any modern, configurable, tabbed console will do. If I'm working collaboratively with others, I'll also have an IRC client open, for chatting. Or being distracted, more likely. I'll often also have a Unicode character selector open, such as KCharSelect or Gnome Charmap. I open a few tabs in the console: * At least one tab running in a Python interactive interpreter, for testing small snippets of code, running the Python interactive help() system, and so forth. * At least one tab for running my code, or my unit tests. * Another tab for managing files, including source control (hg or git). Some people like to do all of this from a single tab, using the screen command to manage virtual tabs. I am not one of those people. For the same reason, I prefer GUI editors over emacs or vim. -- Steven D'Aprano http://import-that.dreamwidth.org/ From sameer.rathoud at gmail.com Wed May 28 09:27:05 2014 From: sameer.rathoud at gmail.com (Sameer Rathoud) Date: Wed, 28 May 2014 06:27:05 -0700 (PDT) Subject: IDE for python In-Reply-To: References: <798134c1-3c0b-4ad2-99ef-d65b2101e3dc@googlegroups.com> Message-ID: On Wednesday, May 28, 2014 6:05:08 PM UTC+5:30, Mark Lawrence wrote: > On 28/05/2014 12:31, Sameer Rathoud wrote: > > > On Wednesday, May 28, 2014 4:21:22 PM UTC+5:30, Mihamina Rakotomandimby wrote: > > >> On 05/28/2014 01:43 PM, Sameer Rathoud wrote: > > >> > > >>> Please suggest, if we have any free ide for python development. > > >> > > >> > > >> > > >> I think major IDEs in the place have their Python integration. > > >> > > >> Did you make some search and tried each one? > > >> > > >> > > >> > > >> With just the information you provided, every existing IDE is OK. > > >> > > >> > > >> > > >> - What didnt you like in IDLE? > > >> > > >> - What IDE do you use for anything else thant Python? > > > > > > for C++ and C# development I prefer visual studio and for C++ try outs even codeblock is ok > > > > > > For Java I use eclipse. > > > > Get the pydev plugin for eclipse. Pydev uses pylint to flag up errors > > or warnings as you type, saves hours of work. > > > > > > > > But first time I am trying python. I was trying some UI with python. I have installed wingide. But i didn't liked it because for licenses messages even in trial version. > > > > > > I was searching for spyder, but didn't got any helpful installable. > > > > > > > Also would you please use the mailing list > > https://mail.python.org/mailman/listinfo/python-list or read and action > > this https://wiki.python.org/moin/GoogleGroupsPython to prevent us > > seeing double line spacing and single line paragraphs, thanks. > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > > Mark Lawrence > > > > --- > > This email is free from viruses and malware because avast! Antivirus protection is active. > > http://www.avast.com Hi, Thanks a lot everyone, for your valuable suggestion. I have successfully plugged-in PyDev and it is working great for me. Once again thanks a lot From wrw at mac.com Wed May 28 08:47:52 2014 From: wrw at mac.com (William Ray Wing) Date: Wed, 28 May 2014 08:47:52 -0400 Subject: IDE for python In-Reply-To: References: Message-ID: <337DEF02-2470-488D-8EE1-290A81CCF023@mac.com> On May 28, 2014, at 6:43 AM, Sameer Rathoud wrote: > Hello everyone, > > I am new to python. > > I am currently using python 3.3 > > With python I got IDLE, but I am not very comfortable with this. > > Please suggest, if we have any free ide for python development. > -- > https://mail.python.org/mailman/listinfo/python-list There are several comparison tables and reviews of Python IDEs on the web. You should check the following and see what suits you best: http://en.wikipedia.org/wiki/Comparison_of_integrated_development_environments#Python http://www.pythoncentral.io/comparison-of-python-ides-development/ https://wiki.python.org/moin/IntegratedDevelopmentEnvironments http://stackoverflow.com/questions/81584/what-ide-to-use-for-python http://pedrokroger.net/choosing-best-python-ide/ http://spyced.blogspot.com/2005/09/review-of-6-python-ides.html Good Luck, -Bill PS: As it happens, I use (and like) Wing IDE, but have NO relation to the development company, other than as a satisfied user. From harrismh777 at gmail.com Wed May 28 10:25:11 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 28 May 2014 09:25:11 -0500 Subject: IDE for python References: Message-ID: On 5/28/14 5:43 AM, Sameer Rathoud wrote: > I am currently using python 3.3 > With python I got IDLE, but I am not very comfortable with this. > Please suggest, if we have any free ide for python development. I tend to agree with Chris & Steven on this... a good gnu/linux desktop is the best IDE (debian, xfce, terminals galore) Early in my unix career I learned VI (now VIM) and find that for most editing jobs (even from remote) --- can't be beat. OTOH, I would highly recommend getting comfortable with IDLE; especially if you're using 3.3+ / the modern IDLE works, is stable, and has many advantages over just a tabbed editor. It is highly configurable, simple and elegant, not to mention that its written against tkinter with pure python. Today I'm using IDLE for python development almost exclusively. You no doubt are getting comfortable with python's indentation code blocking delimiting anomaly. IDLE helps with that. Yes, you can use tabs, but you shouldn't (for several reasons, I spare you). Typically the indentation is 4 spaces; IDLE handles this for you automatically (mostly) and allows the 4 spaces to be reconfigured. The only really irritating aspect of IDLE which I had to get used to was that the interactive REPL provides no way to clear the screen. Its debugging capabilities (and undo levels) more than make up for that tiny small snag. You will come to appreciate the class path browser, recent files, &c. The default highlight colors are well chosen (they may be changed) and the window size and fonts may be changed. I think IDLE looks good. Its clean, clear, and functional. I guess what I'm encouraging you to do is be patient with IDLE until you get a grip on it. There's more to it than meets the eye, at first. marcus From breamoreboy at yahoo.co.uk Wed May 28 10:30:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 28 May 2014 15:30:40 +0100 Subject: Unable to figure out ' invalid matrix input type -- ', u'1' In-Reply-To: <103633e5-26be-4b53-a8c4-e2ca8c41b103@googlegroups.com> References: <103633e5-26be-4b53-a8c4-e2ca8c41b103@googlegroups.com> Message-ID: On 28/05/2014 13:41, varun7rs at gmail.com wrote: > Hello Everyone, > > I am currently working on Cplex using Python API. I have a problem when I run the code. I keep getting this error about the invalid matrix input but I'm not able to figure out what it is. I would be grateful if any of you could help. My function is as below > > def add_constraint(self, variables, coefficients, sense, rhs, name): > self.prob.linear_constraints.add( > lin_expr = [[ variables, coefficients ]], > senses = [sense], > rhs = [rhs], > names = [name] ) > > > > Traceback (most recent call last): > File "RW10.py", line 569, in > main(sys.argv[1:]) > File "RW10.py", line 562, in main > solveVNEProblem( phy_network, demands, args.output) > File "RW10.py", line 116, in solveVNEProblem > solver.add_constraint( varNames, varCoeffs, "E", 1.0, "Location_Constraints1{}".format( demand.demandID ) ) > File "RW10.py", line 26, in add_constraint > names = [name] ) > File "/opt/ibm/ILOG/CPLEX_Studio125/cplex/python/x86-64_sles10_4.1/cplex/_internal/_subinterfaces.py", line 1187, in add > rmat = _C_HBMatrix(lin_expr, self._cplex._env_lp_ptr, 0, self._env.parameters.read.apiencoding.get()) > File "/opt/ibm/ILOG/CPLEX_Studio125/cplex/python/x86-64_sles10_4.1/cplex/_internal/_matrices.py", line 74, in __init__ > raise TypeError(" invalid matrix input type -- ", self._mat[0]) > TypeError: (' invalid matrix input type -- ', u'1') > > > Thank You > I don't know but I'll guess that should be a letter l and not the number 1. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Wed May 28 10:36:32 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 28 May 2014 15:36:32 +0100 Subject: IDE for python In-Reply-To: <4f2e31da-5b4f-4f67-b82f-bfb413b87708@googlegroups.com> References: <87iooqw51z.fsf@elektro.pacujo.net> <026d97e2-14f8-485f-b1a5-00dff63af8e1@googlegroups.com> <4f2e31da-5b4f-4f67-b82f-bfb413b87708@googlegroups.com> Message-ID: On 28/05/2014 14:01, Sameer Rathoud wrote: I've had to snip umpteen lines that gg has added so *please* use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. > one more query, do we have any add-in available for python on visual studio 2010 > Python Tools for Visual Studio here http://pytools.codeplex.com/ but I don't think it supports the express edition. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From tjreedy at udel.edu Wed May 28 11:32:13 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 May 2014 11:32:13 -0400 Subject: How to run script from interpreter? In-Reply-To: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> Message-ID: On 5/28/2014 3:44 AM, onlyvinish at gmail.com wrote: > On Friday, January 19, 2001 1:22:23 AM UTC+5:30, Rolander, Dan wrote: >> What is the best way to run a python script from within the interpreter? >> What command should I use? >> >> Thanks, >> Dan > > try using execfile(filename) or in 3.x with open(filename) as f: exec f These both assume that you want to run the script in the same process as the interpreter and within the module containing the statement. This is rare. People usually either want to import into a separate module or run in a separate process. For the latter, use the subprocess module and the same command line that you would use in a console. -- Terry Jan Reedy From wxjmfauth at gmail.com Wed May 28 11:38:51 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 28 May 2014 08:38:51 -0700 (PDT) Subject: IDE for python In-Reply-To: References: <87iooqw51z.fsf@elektro.pacujo.net> <1401277601.6327.9.camel@greg-Lenovo-G480> Message-ID: Le mercredi 28 mai 2014 14:55:35 UTC+2, Chris Angelico a ?crit?: > On Wed, May 28, 2014 at 9:46 PM, Greg Schroeder wrote: > > >> > Please suggest, if we have any free ide for python development. > > > > > > Anything that writes text is fine. > > > I recommend the standard text editor for your OS (Notepad if you use > > > Windows, Textedit on Mac, whatever is on your GNU/Linux distro by > > > default) unless you know exactly what you don't like about it. > > > > No. Don't use Notepad for anything! It's easy enough to get a better > > editor. Among its other faults, Notepad: > > > > 1) Has problems with LF line endings (they vanish, and you have hugely > > long lines) > > 2) Puts three junk bytes onto the beginning of a file that it > > considers saved as UTF-8 > > 3) Doesn't understand coding cookies, and will happily save something > > in a different encoding like CP-1252 (which it calls "ANSI") > > 4) Guesses encodings on load, giving rise to the famous "Bush hid the > > facts" trick - although this is unlikely to be a problem with > > something of decent size > > 5) Has issues with large files - or at least, it did last time I > > tried; this may no longer be true with Windows 7/8 > > > > Default text editors on the Linux distros I've used have been far > > better, but still less than ideal. With Debian Squeeze, I got a gedit > > that bugged me in several ways, which is what pushed me onto SciTE. > > You can certainly start coding with gedit, though. The issues that I > > had with it were relating to heavy-duty usage that I do, where I'm > > basically spending an entire day delving into code and moving stuff > > around. These days, though, I'd rather have one editor on both the > > platforms I use (Windows and Linux, each in multiple variants), as it > > allows me to share configs and comfortable keystrokes. There are > > plenty of cross-platform editors to choose from. > > > > So, I agree with your analysis, as regards gedit ("know exactly what > > you don't like about it"). If it doesn't bug you, use it. But if > > Notepad doesn't bug you, *still don't use it*, because it's like > > driving a car that isn't structurally sound. It might not be you that > > gets hurt by it... or it might not be for quite a while that you see > > the problems... but the pain will happen. > > > > ChrisA ======== Amen. Ite missa est. From feliphil at gmx.net Wed May 28 12:24:05 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Wed, 28 May 2014 18:24:05 +0200 Subject: IDE for python References: Message-ID: <20140528182405.42ecfcb57c0352a0f11b6a00@gmx.net> > With python I got IDLE, but I am not very comfortable with this. > > Please suggest, if we have any free ide for python development. There are a lot of IDEs for Python. One classic is WingIDE. Available for free is a "101" edition. Runs on all major operating systems. Implemented itself in Python. An editor that's completely implemented in Python is Editra. With plugins you can turn it into an "almost IDE" as well. Sincerely, Wolfgang From harrismh777 at gmail.com Wed May 28 12:39:23 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 28 May 2014 11:39:23 -0500 Subject: How to run script from interpreter? References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> Message-ID: On 5/28/14 2:44 AM, onlyvinish at gmail.com wrote: > On Friday, January 19, 2001 1:22:23 AM UTC+5:30, Rolander, Dan wrote: >> What is the best way to run a python script from within the interpreter? >> What command should I use? >> > > try using execfile(filename) > What type of script? python? bash? tcl? other? If you want to use python as a shell-glue you can try using system. >>> from os import system >>> def ([parms]) >>> .... blah blah >>> .... rc = system(">> When you call function_name within the python interpreter your_script_name will be called using system. OTOH, if you are wanting to run a python script within the interpreter then just import the names you want from your_script.py file and then call the name... like main, forinstance. >>> from my_script import main >>> main([parms]) Within your_script.py define a main function: def main([parms]): blah blah return rc ----- OTOH, just write the script.py file (top down procedural) and then import it: >>> import my_script.py marcus From ernest.bonat at gmail.com Wed May 28 13:24:16 2014 From: ernest.bonat at gmail.com (Ernest Bonat, Ph.D.) Date: Wed, 28 May 2014 10:24:16 -0700 Subject: IDE for python In-Reply-To: <20140528182405.42ecfcb57c0352a0f11b6a00@gmx.net> References: <20140528182405.42ecfcb57c0352a0f11b6a00@gmx.net> Message-ID: I believe in IDE with a complete project structure development and debugging tool. I have to time for a lot of typing. Mi option is Eclipse IDE with PyDev plugin. Thanks On Wed, May 28, 2014 at 9:24 AM, Wolfgang Keller wrote: > > With python I got IDLE, but I am not very comfortable with this. > > > > Please suggest, if we have any free ide for python development. > > There are a lot of IDEs for Python. > > One classic is WingIDE. Available for free is a "101" edition. Runs on > all major operating systems. Implemented itself in Python. > > An editor that's completely implemented in Python is Editra. With > plugins you can turn it into an "almost IDE" as well. > > Sincerely, > > Wolfgang > -- > https://mail.python.org/mailman/listinfo/python-list > -- Thanks Ernest Bonat, Ph.D. Senior Software Engineer Senior Business Statistics Analyst Mobile: 503.730.4556 Email: ernest.bonat at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjaminhernacki at gmail.com Wed May 28 13:32:49 2014 From: benjaminhernacki at gmail.com (funky) Date: Wed, 28 May 2014 10:32:49 -0700 (PDT) Subject: need help with this code please fix it or at least tell me what im doing wrong Message-ID: <8bc01036-ee9e-4de9-b569-7039dcc05d9c@googlegroups.com> import pygame import random import time import sys black = (0, 0, 0) white = (255, 255, 255) red = (255, 0, 0) class Block(pygame.sprite.Sprite): def __init__(self, color, width, height): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([width, height]) self.image.fill(color) self.rect = self.image.get_rect() def reset_pos(self): self.rect.y = -20 self.rect.x = random.randrange(700) def update(self): self.rect.y +=1 if self.rect.y > 410: self.rect.y = -20 self.rect.x = random.randrange(700) pygame.init() screen_width = 700 screen_height = 400 screen = pygame.display.set_mode([screen_width, screen_height]) block_list = pygame.sprite.Group() wall_list = pygame.sprite.Group() all_sprites_list = pygame.sprite.Group() for i in range(50): color = (random.randint(40, 255), random.randint(40, 255), random.randint(40, 255)) block = Block(color, 20, 15) block.rect.x = random.randrange(screen_width) block.rect.y = random.randrange(screen_height) block_list.add(block) all_sprites_list.add(block) player = Block(red, 20, 15) all_sprites_list.add(player) done = False clock = pygame.time.Clock() score = 0 minutes = 0 seconds = 0 time_start = 0 while done == False: for event in pygame.event.get(): if event.type == pygame.QUIT: done == True while True: sys.stdout.write("\r{minutes} Minutes {seconds} Seconds".format(minutes=minutes, seconds=seconds)) sys.stdout.flush() time.sleep(1) seconds = int(time.time() - time_start) - minutes * 60 for x in range(1, 1000): screen.fill(white) blocks_hit_list = pygame.sprite.spritecollide(player, block_list, False) for block in blocks_hit_list: if block > 0: score += 1 print score block.reset_pos() font = pygame.font.Font(None, 25) text2 = font.render("time left: " + str(seconds), True, black) text = font.render("Score: " + str(score), True, black) screen.blit(text, [20, 20]) screen.blit(text2,[0, 20]) pos = pygame.mouse.get_pos() player.rect.x=pos[0] player.rect.y=pos[1] block_list.update() all_sprites_list.draw(screen) clock.tick(120) pygame.display.flip() if seconds == 60: pygame.quit() From codemonkey at inbox.com Wed May 28 13:39:04 2014 From: codemonkey at inbox.com (Deb Wyatt) Date: Wed, 28 May 2014 09:39:04 -0800 Subject: IDE for python In-Reply-To: <798134c1-3c0b-4ad2-99ef-d65b2101e3dc@googlegroups.com> References: Message-ID: <86FCC7F1EF5.00000F77codemonkey@inbox.com> >> On 05/28/2014 01:43 PM, Sameer Rathoud wrote: >> >>> Please suggest, if we have any free ide for python development. >> > But first time I am trying python. I was trying some UI with python. I > have installed wingide. But i didn't liked it because for licenses > messages even in trial version. > . > -- > https://mail.python.org/mailman/listinfo/python-list I'm using http://wingware.com/downloads/wingide-101. no irritating messages. It's not the full version, but it works well for me. I was using Geany before that and can't remember what Geany did to irritate me lol. Everybody has their favorites. I hope you find an ide that you love. Deb in WA, USA ____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! Check it out at http://www.inbox.com/marineaquarium From gary.herron at islandtraining.com Wed May 28 13:53:16 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Wed, 28 May 2014 10:53:16 -0700 Subject: need help with this code please fix it or at least tell me what im doing wrong In-Reply-To: <8bc01036-ee9e-4de9-b569-7039dcc05d9c@googlegroups.com> References: <8bc01036-ee9e-4de9-b569-7039dcc05d9c@googlegroups.com> Message-ID: <5386228C.8050003@islandtraining.com> On 05/28/2014 10:32 AM, funky wrote: <100+ lines of code removed.> No way. This is not a paid service, but rather a community of Python users. You can get lots of help here, but you have to put in some work. Please take the time to tell us: What this code should do. What it actually does. Why you think it's wrong. You should also tell us what version of Python you are using, and on what platform you are running it. Moreover, please reduce down to a bare minimum, the amount of code needed to show us the part that fails. Gary Herron From gordon at panix.com Wed May 28 14:33:02 2014 From: gordon at panix.com (John Gordon) Date: Wed, 28 May 2014 18:33:02 +0000 (UTC) Subject: need help with this code please fix it or at least tell me what im doing wrong References: <8bc01036-ee9e-4de9-b569-7039dcc05d9c@googlegroups.com> Message-ID: In <8bc01036-ee9e-4de9-b569-7039dcc05d9c at googlegroups.com> funky writes: What do you want the program to do? What is it doing instead? Do you get any error messages? Don't just throw code at us and ask us to fix it... -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From stefan_ml at behnel.de Wed May 28 15:00:54 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 28 May 2014 21:00:54 +0200 Subject: how avoid delay while returning from C-python api? In-Reply-To: References: Message-ID: Lakshmipathi.G, 28.05.2014 12:22: > I have C-Python api like below. It works fine, but the problem is > while invoking this method > from python script say > > #cat script.py > > offset=0 > size=4 > write_object(offset,size) > > > > This calls write_this_c() C api and returns quickly to next printf statement. > But the return call (Py_RETURN_NONE) takes something like 4-6 seconds. > > ----- > static > PyMethodDef xyz_methods[] = { > {"write_object", write_object, METH_VARARGS,"write some stuff "}, > {NULL, NULL, 0, NULL} > }; > > > ---- > static PyObject * > write_object(PyObject *self, PyObject *args) > { > int offset, size; > if (!PyArg_ParseTuple(args,"ii", &offset, &size)) > Py_RETURN_NONE; > > printf("before call"); > write_this_c(offset, size); > printf("after call"); > Py_RETURN_NONE; ##delay happens here > } > > How to avoid this delay time? Thanks for any help/pointers! You already found the problem yourself, so let me just give you a general advice that you can avoid a lot of the hassle of writing code like the above and struggling to get it right by writing it in Cython instead of plain C. Here's a complete example of the above code in Cython, including the module setup code etc., but without the bugs: # external declarations: cdef extern from "someheader.h": void write_this_c(int offset, int size) # your module function: def write_object(int offset, int size): """write some stuff""" print("before call") write_this_c(offset, size) print("after call") That's it. Stefan From invalid at invalid.invalid Wed May 28 15:08:47 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 28 May 2014 19:08:47 +0000 (UTC) Subject: need help with this code please fix it or at least tell me what im doing wrong References: <8bc01036-ee9e-4de9-b569-7039dcc05d9c@googlegroups.com> Message-ID: On 2014-05-28, funky wrote: [program that apparently doesn't work] I'll fix it for you. My rates are $150/hour with a 4-hour minimum paid up-front. -- Grant Edwards grant.b.edwards Yow! PUNK ROCK!! DISCO at DUCK!! BIRTH CONTROL!! gmail.com From rustompmody at gmail.com Wed May 28 15:10:59 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 28 May 2014 12:10:59 -0700 (PDT) Subject: IDE for python In-Reply-To: References: Message-ID: <433fb2bc-f733-492c-a340-cbcdf4a9b08c@googlegroups.com> On Wednesday, May 28, 2014 4:13:29 PM UTC+5:30, Sameer Rathoud wrote: > Hello everyone, > I am new to python. > I am currently using python 3.3 > With python I got IDLE, but I am not very comfortable with this. > Please suggest, if we have any free ide for python development. Im not going to add to the answers. I do suggest you read http://blog.osteele.com/posts/2004/11/ides and decide - where you think you fall in the spectrum - where you would like to be From larry.martell at gmail.com Wed May 28 15:23:17 2014 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 28 May 2014 14:23:17 -0500 Subject: Python 3 is killing Python Message-ID: Somthing I came across in my travels through the ether: https://medium.com/@deliciousrobots/5d2ad703365d/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dfnsonfsduifb at gmx.de Wed May 28 15:39:08 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 28 May 2014 21:39:08 +0200 Subject: Python 3 is killing Python In-Reply-To: References: Message-ID: On 28.05.2014 21:23, Larry Martell wrote: > Somthing I came across in my travels through the ether: > > https://medium.com/@deliciousrobots/5d2ad703365d/ Sub-headline "The Python community should fork Python 2". Which could also read "Someone else should REALLY fork Py2 because I'm mad about Py3 yet too lazy to fork Py2 myself". I wish all these ridiculous dumb whiners would finally shut up and fork Python away. That would be win-win: They could use their fork of 2.4 forever and ever, maybe fork 1.4 too while they're at it. Then maintain it. Above all: They would complain to each other and stay away from the mailing lists of people who actually *embrace* progress and who appreciate the wonderful features Py3 has given us. What a wonderful world it would be. So, I agree with the above blogpost. Some lazy blogwriting bum should fork Py2! Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From marko at pacujo.net Wed May 28 15:41:22 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 28 May 2014 22:41:22 +0300 Subject: Python 3 is killing Python References: Message-ID: <871tvdelnh.fsf@elektro.pacujo.net> I agree that Py3 made a grave error in breaking backward-compatibility. However, that's the reality and the transition will take place over time, possibly even before IPv6 overtakes IPv4 in popularity. But then, I was never really beholden to third-party libraries and frameworks. Instead, the batteries-included philosophy still has a great appeal to me. Marko From mail at timgolden.me.uk Wed May 28 15:46:25 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 28 May 2014 20:46:25 +0100 Subject: Command prompt not shown when running Python script with subprocess on Windows In-Reply-To: <53856F53.5010303@timgolden.me.uk> References: <29c26176-b573-4ac9-bf41-a18a53d7dfb9@googlegroups.com> <53856F53.5010303@timgolden.me.uk> Message-ID: <53863D11.3060009@timgolden.me.uk> On 28/05/2014 06:08, Tim Golden wrote: > On 28/05/2014 00:01, ps16thypresenceisfullnessofjoy at gmail.com wrote: > >> I want users to be able to enter paths in the XML file exactly the >> way they would be entered in a Windows shortcut. Since it is possible >> to make a Windows shortcut for path-to-script.py without the >> python.exe in front of it and have it open in its own command prompt, >> I want to be able to do the same thing in my XML file, but this is >> what I cannot figure out. > > Anything done through shortcuts is making use of the Windows Shell API. > To mimic that behaviour, you could try using that; in this case, > ShellExecute[Ex]. For simple purposes, this is exposed in Python as > os.startfile. If you need more control, you'd have to use the API call > directly, either via ctypes or via the pywin32 libraries under the > win32com.shell package. > > To mimic the behaviour exactly (if that is a requirement), you could > actually create a temporary shortcut with the desired information and > invoke it via os.startfile. > > I haven't followed the thread (and I'm offline at the moment) so I'll > wait until I've seen it before I comment on the shlex.split / \\ dance > above. On the surface, though, I'm not sure what it's achieving. [All > right, I didn't wait :)]. I've just read the original post. My answer above isn't quite on the nail (although it might still be useful). If you're prepared to use the pywin32 libraries, then you could use win32api.FindExecutable to provide a first argument to the Popen constructor, followed by the others in your data. Something like this: import subprocess import win32api # ... for app_path in app_paths: args = ... split ... _, exe = win32api.FindExecutable(args[0]) if exe != os.path.abspath(args[0]): args = [exe] + args subprocess.call(args) As to the shlex dance, I *think* you're trying to break the command line up, expand any env vars, and then pass it along to Popen as above? If your data were formatted as though for a Windows command-line, ie with the paths double-quoted if they contain spaces, then shlex should do the right thing by it without any further messing around. So, if this example: %ProgramFiles%\LibreOffice 4\program\swriter.exe "C:\Users\Timothy\Documents\myfile.odt" were instead: "%ProgramFiles%\LibreOffice 4\program\swriter.exe" "C:\Users\Timothy\Documents\myfile.odt" then the shlex dance would just be: args = [os.path.expandvars(i) for i in shlex.split(app_path)] Although, assuming associations were set up in the usual way, the code I outlined above to use FindExecutable would cope with this without the need to specify the swriter.exe. As would the os.startfile approach I suggested earlier. TJG From no.email at nospam.invalid Wed May 28 15:49:59 2014 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 28 May 2014 12:49:59 -0700 Subject: Python 3 is killing Python References: Message-ID: <7xha49wumw.fsf@ruckus.brouhaha.com> Larry Martell writes: > Somthing I came across in my travels through the ether: > [1]https://medium.com/@deliciousrobots/5d2ad703365d/ "Python 3 can revive Python" https://medium.com/p/2a7af4788b10 long HN comment thread: https://news.ycombinator.com/item?id=7801834 "Python 3 is fine" http://sealedabstract.com/rants/python-3-is-fine/ OT: wow that medium site is obnoxious. From larry.martell at gmail.com Wed May 28 15:58:05 2014 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 28 May 2014 14:58:05 -0500 Subject: Python 3 is killing Python In-Reply-To: <7xha49wumw.fsf@ruckus.brouhaha.com> References: <7xha49wumw.fsf@ruckus.brouhaha.com> Message-ID: On Wed, May 28, 2014 at 2:49 PM, Paul Rubin wrote: > Larry Martell writes: > > Somthing I came across in my travels through the ether: > > [1]https://medium.com/@deliciousrobots/5d2ad703365d/ > > "Python 3 can revive Python" https://medium.com/p/2a7af4788b10 > long HN comment thread: https://news.ycombinator.com/item?id=7801834 > > "Python 3 is fine" http://sealedabstract.com/rants/python-3-is-fine/ > > OT: wow that medium site is obnoxious. > No company that I work for is using python 3 - they just have too much of an investment in a python 2 code base to switch. I'm just saying. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed May 28 16:15:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 May 2014 06:15:45 +1000 Subject: Python 3 is killing Python In-Reply-To: References: <7xha49wumw.fsf@ruckus.brouhaha.com> Message-ID: On Thu, May 29, 2014 at 5:58 AM, Larry Martell wrote: > No company that I work for is using python 3 - they just have too much of an > investment in a python 2 code base to switch. I'm just saying. And that's not a problem. Every whinging blog author seems to forget that Python 2.7 support is going to continue for a long time! Yes, you won't get new features. But the recommendation is "new and unfettered projects should take advantage of Python 3", not "every Python 2 project needs to be ported". There've been some recent discussions about exactly what security fixes and improvements can be backported; the underlying guiding principle is "it's acceptable and expected that there will be large, net-facing Python 2 applications for the foreseeable future". Or maybe the complaint is that there are fancy new features in Python 3.x that aren't in 2.7? Oh wait, that directly contradicts the whine. So if Python 3 has added nothing, what's the rush to move onto it? Whiners gonna whine. ChrisA From breamoreboy at yahoo.co.uk Wed May 28 16:24:15 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 28 May 2014 21:24:15 +0100 Subject: Python 3 is killing Python In-Reply-To: References: <7xha49wumw.fsf@ruckus.brouhaha.com> Message-ID: On 28/05/2014 20:58, Larry Martell wrote: > On Wed, May 28, 2014 at 2:49 PM, Paul Rubin > wrote: > > Larry Martell > writes: > > Somthing I came across in my travels through the ether: > > [1]https://medium.com/@deliciousrobots/5d2ad703365d/ > > "Python 3 can revive Python" https://medium.com/p/2a7af4788b10 > long HN comment thread: https://news.ycombinator.com/item?id=7801834 > > "Python 3 is fine" http://sealedabstract.com/rants/python-3-is-fine/ > > OT: wow that medium site is obnoxious. > > > No company that I work for is using python 3 - they just have too much > of an investment in a python 2 code base to switch. I'm just saying. > So you're happy because you've support until at least 2020, and the people using Python 3 are happy, mainly because of the vastly improved unicode handling via the FSR and asyncio in 3.4. Presumably the only unhappy people are those who keep bleating on about forking Python to produce a 2.8, or has work on this already started without my knowledge? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ps16thypresenceisfullnessofjoy at gmail.com Wed May 28 16:22:02 2014 From: ps16thypresenceisfullnessofjoy at gmail.com (ps16thypresenceisfullnessofjoy at gmail.com) Date: Wed, 28 May 2014 13:22:02 -0700 (PDT) Subject: Command prompt not shown when running Python script with subprocess on Windows In-Reply-To: References: <29c26176-b573-4ac9-bf41-a18a53d7dfb9@googlegroups.com> Message-ID: <93934f08-78ef-47c3-90e8-08e96b64ed9b@googlegroups.com> Thank you for your reply. I think I'll use PyWin32 if it's available on the user's system, and otherwise fall back to using subprocess.Popen, since I want my script to be cross-platform. os.startfile won't work for me because you can't pass arguments to the file being started. (When I first asked my question, I was thinking I might just need to pass a certain STARTUPINFO flag to subprocess.Popen, but it looks like that's not the solution.) A few examples from the interactive interpreter should help to explain why I am doing the "\ \\ dance" (I used raw strings in these examples so that I wouldn't need to escape the backslashes): >>> import shlex >>> shlex.split(r'C:\Users\Timothy\Documents\Python\myscript.py') ['C:UsersTimothyDocumentsPythonmyscript.py'] >>> shlex.split(r'C:\\Users\\Timothy\\Documents\\Python\\myscript.py') ['C:\\Users\\Timothy\\Documents\\Python\\myscript.py'] >>> shlex.split(r'C:\Users\Timothy\Documents\Python\myscript.py', posix=False) ['C:\\Users\\Timothy\\Documents\\Python\\myscript.py'] The first example shows that single backslashes get removed. The second example shows that double backslashes are preserved intact. The third example shows that if posix=False, single backslashes are converted to double backslashes. None of these three behaviors are acceptable to correctly parse a Windows path, which is why I am doing what I am to work around the issue. -- Timothy From ian.g.kelly at gmail.com Wed May 28 16:49:09 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 28 May 2014 14:49:09 -0600 Subject: need help with this code please fix it or at least tell me what im doing wrong In-Reply-To: <8bc01036-ee9e-4de9-b569-7039dcc05d9c@googlegroups.com> References: <8bc01036-ee9e-4de9-b569-7039dcc05d9c@googlegroups.com> Message-ID: On Wed, May 28, 2014 at 11:32 AM, funky wrote: > while done == False: > for event in pygame.event.get(): > if event.type == pygame.QUIT: > done == True Here is one fairly obvious bug; you used "==" where you presumably intended to do an assignment. As it stands it will just compare done to True and then discard the result. That's not necessarily the only issue, but if you want more detailed help then as others have stated you're going to have to tell us in what way the code isn't working as expected. From ps16thypresenceisfullnessofjoy at gmail.com Wed May 28 16:46:40 2014 From: ps16thypresenceisfullnessofjoy at gmail.com (ps16thypresenceisfullnessofjoy at gmail.com) Date: Wed, 28 May 2014 13:46:40 -0700 (PDT) Subject: Command prompt not shown when running Python script with subprocess on Windows In-Reply-To: References: <29c26176-b573-4ac9-bf41-a18a53d7dfb9@googlegroups.com> <53856F53.5010303@timgolden.me.uk> Message-ID: Thank you for your replies. I tried what you suggested in your second post and it worked. That was actually a mistake in the app_list.xml file. As you said: %ProgramFiles%\LibreOffice 4\program\swriter.exe "C:\Users\Timothy\Documents\myfile.odt" should instead be: "%ProgramFiles%\LibreOffice 4\program\swriter.exe" "C:\Users\Timothy\Documents\myfile.odt" I just made that file as a sample, and didn't actually test it. My "shlex dance" has nothing to do with that, though. A few examples from the interactive interpreter should explain why I am doing it (I used raw strings in these examples so that I wouldn't need to escape the backslashes): >>> import shlex >>> shlex.split(r'C:\Users\Timothy\Documents\Python\myscript.py') ['C:UsersTimothyDocumentsPythonmyscript.py'] >>> shlex.split(r'C:\\Users\\Timothy\\Documents\\Python\\myscript.py') ['C:\\Users\\Timothy\\Documents\\Python\\myscript.py'] >>> shlex.split(r'C:\Users\Timothy\Documents\Python\myscript.py', posix=False) ['C:\\Users\\Timothy\\Documents\\Python\\myscript.py'] The first example shows that single backslashes get removed. The second example shows that double backslashes are preserved intact. The third example shows that if posix=False, single backslashes are converted to double backslashes. None of these three behaviors are acceptable to correctly parse a Windows path, which is why I am doing what I am to work around the issue. I think I'll use PyWin32 as you suggested if it's available on the user's system. If it's not, the user will just be required to prefix path-to-script.py with python.exe. (When I first asked my question, I was thinking I might just need to pass a certain STARTUPINFO flag to subprocess.Popen, but it looks like that's not the solution.) -- Timothy From satish.muthali at gmail.com Wed May 28 16:16:00 2014 From: satish.muthali at gmail.com (Satish Muthali) Date: Wed, 28 May 2014 13:16:00 -0700 Subject: passing Python assignment value to shell Message-ID: Hello Experts, I am trying to extract the available userspace+swap memory and then want to feed this value as an argument to a tool that is executed in the shell. so, this is what I have so far: reecalc = [s.split() for s in os.Popen("free -ht").read().splitlines()] freecalc_total = freecalc[4] freecalc_total = freecalc_total[3] freecalc_total = freecalc_total.translate(None, 'M?) Now I want to feed the value for ?freecalc_total? as an argument to a command executed by the shell. For example: devnull = open(os.devnull, ?w?) runCommand = subprocess.call([?stressapptest?, ??, ?20?],stdout=devnull,stderr=subprocess.STDOUT) devnull.close() How do I go about doing this? Many thanks in advance -Satish -------------- next part -------------- An HTML attachment was scrubbed... URL: From phil at riverbankcomputing.com Wed May 28 17:05:31 2014 From: phil at riverbankcomputing.com (Phil Thompson) Date: Wed, 28 May 2014 22:05:31 +0100 Subject: ANN: PyQt v5.3 Released Message-ID: <82bd51d59790303daea6e6fd3777ddec@www.riverbankcomputing.com> PyQt5 v5.3 has been released and is available from http://www.riverbankcomputing.com/software/pyqt/download5. PyQt5 is a comprehensive set of bindings for v5 of Digia's Qt cross-platform application framework. It supports Python v3, v2.7 and v2.6. The highlights of this release include support for Qt v5.3 including the new QtQuickWidgets and QtWebSockets modules. PyQt5 supports cross-compiling to iOS and Android. Windows installers are provided which contain everything needed for PyQt5 development (including Qt, Qt Designer, QScintilla, and MySQL, PostgreSQL, SQLite and ODBC drivers) except Python itself. Installers are provided for the 32 and 64 bit versions of Python v3.4. PyQt5 is implemented as a set of 29 extension modules including support for: - non-GUI infrastructure including event loops, threads, i18n, user and application settings, mapped files and shared memory - GUI infrastructure including window system integration, event handling, 2D graphics, basic imaging, fonts, OpenGL - a comprehensive set of desktop widgets - WebKit - full integration with Quick2 and QML allowing new Quick items to be implemented in Python and created in QML - event driven network programming - multimedia including cameras, audio and radios - Bluetooth - global positioning using satellite, Wi-Fi or text file sources - sensors including accelerometers, altimeters, compasses, gyroscopes, magnetometers, and light, pressure, proximity, rotation and temperature sensors - serial ports - SQL - printing - DBus - XPath, XQuery, XSLT and XML Schema validation - a help system for creating and viewing searchable documentation - unit testing of GUI applications. From harrismh777 at gmail.com Wed May 28 17:37:15 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 28 May 2014 16:37:15 -0500 Subject: need help with this code please fix it or at least tell me what im doing wrong References: <8bc01036-ee9e-4de9-b569-7039dcc05d9c@googlegroups.com> Message-ID: On 5/28/14 12:32 PM, funky wrote: > import pygame <========== a very good place to start > import random > import time > import sys http://www.pygame.org/wiki/tutorials My hourly rate is $295.00 /hour, w/2hour minimum, happy to send you a contract of engagement and a copy of my document of understanding. Sign both and arrange payment through paypal and I'll give you a call --- the first 30 minutes consultation is free. marcus From gordon at panix.com Wed May 28 17:40:14 2014 From: gordon at panix.com (John Gordon) Date: Wed, 28 May 2014 21:40:14 +0000 (UTC) Subject: passing Python assignment value to shell References: Message-ID: In Satish Muthali writes: > Now I want to feed the value for 'freecalc_total' as an argument to > a command executed by the shell. > For example: > devnull = open(os.devnull, 'w') > runCommand = subprocess.call(['stressapptest', ' the value of freecalc_total here>'], stdout=devnull,stderr=subprocess.STDOUT) > devnull.close() I think you can just include freecalc_total directly as part of the argument list, like this: runCommand = subprocess.call(['stressapptest', freecalc_total], stdout=devnull, stderr=subprocess.STDOUT) -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From slc at publicus.net Wed May 28 17:54:00 2014 From: slc at publicus.net (Steven Clift) Date: Wed, 28 May 2014 16:54:00 -0500 Subject: Python alternative to Google Groups Message-ID: If you are looking for an open source alternative between Google Groups and Mailman, I wanted to share: http://groupserver.org It has recent release and new design. Key is the assumption that any user can publish/reply via email or the web, not just receive email alerts for posting via the web. Our non-profit is a big user and just released our mobile responsive design - http://forums.e-democracy.org We are looking to collaborate with other orgs and developers. Note: http://e-democracy.org/groupserver Cheers, Steven Clift E-Democracy.org ? From ben at benfinney.id.au Wed May 28 18:13:46 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 29 May 2014 08:13:46 +1000 Subject: IDE for python References: Message-ID: <85ha494kmd.fsf@benfinney.id.au> Sameer Rathoud writes: > I am new to python. > I am currently using python 3.3 Welcome! You're off to a good start, using Python 3 :-) > With python I got IDLE, but I am not very comfortable with this. > Please suggest, if we have any free ide for python development. What other programming languages are you familiar with? Learning a programming language is difficult enough. It should *not* entail all the effort of evaluating and learning a language-specific IDE; you should already be using an IDE that supports the new language. I strongly recommend learning *one* IDE which is free software, has good cross-platform and cross-language support, is mature and flexible. My IDE is Bash, Screen, and Emacs: * a terminal, running a GNU Screen session; Screen windows include: * Bash in various Screen windows * Emacs * an automated test runner * a database client You should invest the effort to learn either of Vim or Emacs. They both: * are free software, ensuring there are no barriers to their continued maintenance into the indefinite future; * mature, ensuring they have survived numerous IDE fads and already incorporate a lot of accumulated wisdom; * cross-platform, working the same on every development operating system today; * cross-language, supporting every important programming language and hundreds of minor ones. Learn either one of them, *once*, and you will be able to use the same toolset for any other languages you need. -- \ ?A free press is one where it's okay to state the conclusion | `\ you're led to by the evidence.? ?Bill Moyers | _o__) | Ben Finney From aberg010 at my.hennepintech.edu Wed May 28 18:30:11 2014 From: aberg010 at my.hennepintech.edu (Andrew Berg) Date: Wed, 28 May 2014 17:30:11 -0500 Subject: Python alternative to Google Groups In-Reply-To: References: Message-ID: <53866373.5070902@my.hennepintech.edu> On 2014.05.28 16:54, Steven Clift wrote: > If you are looking for an open source alternative between Google > Groups and Mailman, I wanted to share: > > http://groupserver.org > > It has recent release and new design. > > Key is the assumption that any user can publish/reply via email or the > web, not just receive email alerts for posting via the web. This list doesn't use Google Groups directly; Google provides an interface to comp.lang.python on Usenet, so something like this would have to be *in addition to* the mailer and Usenet. -- CPython 3.4 | Windows NT 6.2.9200 / FreeBSD 10.0 From ben at benfinney.id.au Wed May 28 18:38:22 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 29 May 2014 08:38:22 +1000 Subject: Python 3 is killing Python References: <7xha49wumw.fsf@ruckus.brouhaha.com> Message-ID: <85d2ex4jhd.fsf@benfinney.id.au> Larry Martell writes: > No company that I work for is using python 3 - they just have too much > of an investment in a python 2 code base to switch. There are many large companies still using FORTRAN and COBOL because of a large investment in those languages, which are far more outdated than Python 2. What's your point? > I'm just saying. Ah, so no point that you're willing to defend, then. -- \ ?Books and opinions, no matter from whom they came, if they are | `\ in opposition to human rights, are nothing but dead letters.? | _o__) ?Ernestine Rose | Ben Finney From rhodri at wildebst.org.uk Wed May 28 19:03:39 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Thu, 29 May 2014 00:03:39 +0100 Subject: Python box (home-use smart router) References: Message-ID: On Tue, 27 May 2014 08:33:42 +0100, animalize81 wrote: > Home-use smart router is more and more popular. > > If embeds Python into such router, and > develops a framework that has the following features: > > 1, allow power-down at any time > 2, dynamic domain name > 3, local storage support (SD cards or Hard Disk) > 4, telnet server > etc. > > Then we can create micro private server on it. > > Still can't see the full prospect, but it may be a great platform for > people's imagination. > > I think Python is very suitable for such role. Have you met the Raspberry Pi? Seriously, since many such "smart routers" are Linux boxes, there's a good chance there is already a Python interpreter installed and your list of other demands is already met. It's certainly the case in the boxes I work on, and we do use Python for bits of system scripting. We *don't* use Python for application writing because speed and space constraints are usually quite tight, which generally means coding in C for preference (despite my boss's attempts to force me to use C++). -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.org.uk Wed May 28 19:12:06 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Thu, 29 May 2014 00:12:06 +0100 Subject: IDE for python References: <5385def6$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 28 May 2014 14:04:55 +0100, Steven D'Aprano wrote: > My IDE is to have three GUI windows open: > > * A web browser for searching the Internet. Any browser will do, but I > prefer Firefox. > > * A tabbed editor. I prefer kate (KDE 3 version, not KDE 4), but geany is > also good. At a pinch gedit will do. kwrite is another good editor, but > not tabbed, and it lacks some of the features of kate. > > * An xterm or console app, again with tabs. I like KDE 3's konsole, but > any modern, configurable, tabbed console will do. Interesting. I'm entirely the other way; while I'm perfectly happy to use a tabbed browser, I find tabbed editors and tabbed consoles awful to use. I want to have three different sections of code side by side on the screen for comparison. I want to have half a dozen consoles all running different things, all positioned so I can take in the state of those things at a glance. I do not want to be wasting time flicking between this and that, and relying on my relatively poor memory to cache all that information :-) Then again, I'm not as bad as one former colleague of mine. He reckons that the main advantage of higher resolution screens is that he can tile more 80x40 console windows on them. -- Rhodri James *-* Wildebeest Herder to the Masses From no.email at nospam.invalid Wed May 28 19:22:29 2014 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 28 May 2014 16:22:29 -0700 Subject: Python 3 is killing Python References: <7xha49wumw.fsf@ruckus.brouhaha.com> Message-ID: <7xmwe18p56.fsf@ruckus.brouhaha.com> Ben Finney writes: > There are many large companies still using FORTRAN and COBOL because of > a large investment in those languages, which are far more outdated than > Python 2. What's your point? I think some of us see Python 2 as perfectly fine--we've looked into Python 3 and found some minor improvements along with some minor breakage, and figure it's not worth the cognitive burden of switching from something that already works, even if Python 3 is slightly better in the scheme of things. While I'm sure it will change over time, I currently don't actually know anyone using Python 3 even for new projects. I know *of* people using Python 3 including here on this newsgroup, but I'm currently not personally acquainted with any of them. From ben at benfinney.id.au Wed May 28 19:45:02 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 29 May 2014 09:45:02 +1000 Subject: passing Python assignment value to shell References: Message-ID: <857g554ge9.fsf@benfinney.id.au> Satish Muthali writes: > so, this is what I have so far: Thank you for presenting your code. Please ensure that you post in text only, without transforming the characters from what you typed. Something in your message composition process is currently converting some ?"? (U+0022 QUOTATION MARK) characters into ??? and ??? (U+201C LEFT DOUBLE QUOTATION MARK and U+201D RIGHT DOUBLE QUOTATION MARK) characters, which changes the meaning of your code. Best to turn off all such automated conversions when you compose a message. > reecalc = [s.split() for s in os.Popen("free -ht").read().splitlines()] > freecalc_total = freecalc[4] > freecalc_total = freecalc_total[3] > freecalc_total = freecalc_total.translate(None, 'M?) > > Now I want to feed the value for ?freecalc_total? as an argument to a > command executed by the shell. It will need to be a text string representation of that number, since the command line will be a sequence of text string arguments. To create a text string representation of an integer, use ?str(freecalc_total)?. (In Python 2, use ?unicode(freecalc_total)?.) If the number is not an integer, you should format it explicitly with a format string :: >>> freecalc_total = 80752.16 >>> freecalc_arg = format(freecalc_total, "14.3f") >>> freecalc_arg ' 80752.160' > For example: > > devnull = open(os.devnull, ?w?) > runCommand = subprocess.call([?stressapptest?, ??, ?20?],stdout=devnull,stderr=subprocess.STDOUT) > devnull.close() (You should follow PEP 8 for your Python code, which recommends against camelCaseNames and recommends spaces after commas for readability.) So I'd suggest:: freecalc_total = your_computations_as_above() foo_arg = 20 # You don't tell us what this argument is, but it should have a name. command_args = [ "stressapptest", str(freecalc_total), str(foo_arg)] process = subprocess.call( command_args, stdout=devnull, stderr=subprocess.STDOUT) > Many thanks in advance I hope that helps. -- \ ?Homer, where are your clothes?? ?Uh... dunno.? ?You mean Mom | `\ dresses you every day?!? ?I guess; or one of her friends.? | _o__) ?Lisa & Homer, _The Simpsons_ | Ben Finney From ben at benfinney.id.au Wed May 28 19:56:12 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 29 May 2014 09:56:12 +1000 Subject: Python alternative to Google Groups References: Message-ID: <8538ft4fvn.fsf@benfinney.id.au> Steven Clift writes: > If you are looking for an open source alternative between Google > Groups and Mailman, I wanted to share: > > http://groupserver.org > > It has recent release and new design. Thanks. For many of us, an important service is NNTP, offered by GMane and others. I think I'm unlikely to try GroupServer unless it also offers an NNTP interface to forums, allowing me to integrate them into my existing interface (intead of needing to visit yet another web site). You can implement an NNTP interface to the GroupServer groups, by following RFC 3977 . The Papercut project produces an NNTP server in Python, released as free software. > Our non-profit is a big user and just released our mobile responsive > design - http://forums.e-democracy.org We are looking to collaborate > with other orgs and developers. Note: > http://e-democracy.org/groupserver Great! Thanks for letting us know. -- \ ?Anything that we scientists can do to weaken the hold of | `\ religion should be done and may in the end be our greatest | _o__) contribution to civilization.? ?Steven Weinberg | Ben Finney From look at signature.invalid Wed May 28 20:31:56 2014 From: look at signature.invalid (Wiktor) Date: Thu, 29 May 2014 02:31:56 +0200 Subject: Forking PyPI package Message-ID: <1fgpxn70wxrg0.1rv21r79ohz7z$.dlg@40tude.net> Hello. There's script pwdhash https://pypi.python.org/pypi/pwdhash.py/0.1.1, which I always* wanted to port to Python 3. (* - well, i.e. 6 months ;-)) I'm using this hashing algorithm quite often for years in my browser (Opera plugin), so I thought that it would be cool to have it as python script. It took me some time to make it work under Python 3, because I knew nothing about str <-> bytes encoding, and this was biggest issue why original script wasn't Py3 compatible. So now my version works, it even supports Unicode characters (original JS script does that, but pwdhash.py script doesn't), and now I'm planning to do simple GUI version, because copying from console isn't very comfortable (and I couldn't find good [os and other packages independent] solution to copy string to clipboard. Best answer from here http://goo.gl/8V9Ba6 isn't working). So, my point is, I think maybe it would be useful also to others. I'm newbie not only to Python, but to programming in general, so I don't know, what is best practice in OS programming community. How forking works. How py2->py3 porting (by 3rd person) is realized in Pythonians community. Can you suggest me something? I see few scenarios: 1) I'm trying to contact with original script's author, and send him my propositions of changes in code. (Oh, one more thing: my code isn't backward compatible, and I don't know Py2 that much to include all those try/except, so it could be Py2+Py3 compatible). He decides, if he wants to release it as Py3 only version, or combine it with his script and release Py2+Py3 common version. 2) I'm not contacting with him, and I'm forking his project on GitHub a) under the same name? - probably bad idea b) under new name (e.g. py3pwdhash)? Of course all credits about original author stay in code / setup.py. 2.1) After forking on GitHub, I'm creating new package on PyPI a) under old name, but different version number, and new description? b) under new name, to not confuse users? So, what should I do? I know, that maybe I shouldn't touch that script in first place and just mail to author "Hey, would you please port it to Py3?", but I also treated it as programming exercise, and I didn't think about consequences. ;-) TIA -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') From tjreedy at udel.edu Wed May 28 20:41:53 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 May 2014 20:41:53 -0400 Subject: Python 3 is killing Python In-Reply-To: References: Message-ID: On 5/28/2014 3:23 PM, Larry Martell wrote: > Somthing I came across in my travels through the ether: > > https://medium.com/@deliciousrobots/5d2ad703365d/ Claim: "Python 3 languishes in disuse." Fact: in 2013, there were around 14 million downloads of windows installers for each of 2.7.x and 3.3.x. 3.3 is over twice as popular as 3.2 (to be expected). http://article.gmane.org/gmane.comp.python.devel/147822 In a year, we will see about 3.4. Regardless of comparisons with 2.7, 3.3 is a success in absolute numbers. Claim: Another great strength of Python 2 was that programs written in it would almost always run on the next version of Python without much alteration. True. Changes and removals of deprecated features (like old style classes) were put off until 3.0 (at the request of some of the noiser users). Some improvements were relegated to future imports. By 2.7, the load of accumulated 'technological debt' was as much as the developers wanted to deal with, over and over. -- Terry Jan Reedy From gmschroeder at gmail.com Wed May 28 21:13:42 2014 From: gmschroeder at gmail.com (Greg Schroeder) Date: Thu, 29 May 2014 08:13:42 +0700 Subject: IDE for python In-Reply-To: References: <87iooqw51z.fsf@elektro.pacujo.net> <1401277601.6327.9.camel@greg-Lenovo-G480> Message-ID: <1401326022.6327.11.camel@greg-Lenovo-G480> On Wed, 2014-05-28 at 22:55 +1000, Chris Angelico wrote: > On Wed, May 28, 2014 at 9:46 PM, Greg Schroeder wrote: > >> > Please suggest, if we have any free ide for python development. > > > > Anything that writes text is fine. > > I recommend the standard text editor for your OS (Notepad if you use > > Windows, Textedit on Mac, whatever is on your GNU/Linux distro by > > default) unless you know exactly what you don't like about it. > > No. Don't use Notepad for anything! It's easy enough to get a better > editor. Among its other faults, Notepad: > > 1) Has problems with LF line endings (they vanish, and you have hugely > long lines) > 2) Puts three junk bytes onto the beginning of a file that it > considers saved as UTF-8 > 3) Doesn't understand coding cookies, and will happily save something > in a different encoding like CP-1252 (which it calls "ANSI") > 4) Guesses encodings on load, giving rise to the famous "Bush hid the > facts" trick - although this is unlikely to be a problem with > something of decent size > 5) Has issues with large files - or at least, it did last time I > tried; this may no longer be true with Windows 7/8 > > Default text editors on the Linux distros I've used have been far > better, but still less than ideal. With Debian Squeeze, I got a gedit > that bugged me in several ways, which is what pushed me onto SciTE. > You can certainly start coding with gedit, though. The issues that I > had with it were relating to heavy-duty usage that I do, where I'm > basically spending an entire day delving into code and moving stuff > around. These days, though, I'd rather have one editor on both the > platforms I use (Windows and Linux, each in multiple variants), as it > allows me to share configs and comfortable keystrokes. There are > plenty of cross-platform editors to choose from. > > So, I agree with your analysis, as regards gedit ("know exactly what > you don't like about it"). If it doesn't bug you, use it. But if > Notepad doesn't bug you, *still don't use it*, because it's like > driving a car that isn't structurally sound. It might not be you that > gets hurt by it... or it might not be for quite a while that you see > the problems... but the pain will happen. > > ChrisA Well, learn something new every day. Any gripes against vim with some tweaks? Greg From pavlovevidence at gmail.com Wed May 28 21:20:05 2014 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 28 May 2014 18:20:05 -0700 (PDT) Subject: daemon thread cleanup approach Message-ID: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> Ok, so I have an issue with cleaning up threads upon a unexpected exit. I came up with a solution but I wanted to ask if anyone has any advice or warnings. Basically I am writing a Python library to run certain tasks. All of the calls in the library start worker threads to do the actual work, and some of the worker threads are persistent, others not. Most threads have cleanup work to do (such as deleting temporary directories and killing spawned processes). For better or worse, one of the requirements is that the library can't cause the program to hang no matter what, even if it means you have to forego cleanup in the event of an unexpected exit. Therefore all worker threads run as daemons. Nevertheless, I feel like the worker threads should at least be given a fair opportunity to clean up; all threads can be communicated with and asked to exit. One obvious solution is to ask users to put all library calls inside a with-statement that cleans up on exit, but I don't like it for various reasons. Using atexit doesn't work because it's called after the daemon threads are killed. Here's the solution I came up with: in the library's init function, it will start a non-daemon thread that simply joins the main thread, and then asks all existing worker threads to exit gracefully before timing out and leaving them to be killed. So if an exception ends the main thread, there is still a chance to clean up properly. Does anyone see a potential problem with this approach? It it possible that this will cause the program to hang in any case? We can assume that all calls to the library will occur from the main thread, or at least from the same thread. (If that isn't the case, then the caller has taken responsibility to ensure the program doesn't hang.) This is Python 2.7, and it's only ever going to run on Windows. Thanks for any advice/warnings. Carl Banks From tjreedy at udel.edu Wed May 28 21:57:16 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 May 2014 21:57:16 -0400 Subject: Python 3 is killing Python In-Reply-To: <7xha49wumw.fsf@ruckus.brouhaha.com> References: <7xha49wumw.fsf@ruckus.brouhaha.com> Message-ID: On 5/28/2014 3:49 PM, Paul Rubin wrote: > Larry Martell writes: >> Somthing I came across in my travels through the ether: >> [1]https://medium.com/@deliciousrobots/5d2ad703365d/ > > "Python 3 can revive Python" https://medium.com/p/2a7af4788b10 This makes the same false claim "It?s not like anyone is using Python 3 anyway, (so go ahead and bread existing Py3 code". At least some of the 20+ million windows downloads must be in use. > long HN comment thread: https://news.ycombinator.com/item?id=7801834 One legitimate request is better installation of dependencies, which is in progress. This is not a 2 versus 3 issue, unless there are 3-only improvement. Some want concurrency primitives like go has. Guido went for a new module instead. I don't know what the importand differences are. Some want a better REPL, including color. The Idle shell already has the syntax colorizing. I don't know what else might have been meant. > "Python 3 is fine" http://sealedabstract.com/rants/python-3-is-fine/ In my opinion, about the best non-developer blog on Python 3 -- by a sensible, satisfied user. "in March 2014 Python 3 downloads overtook Python 2 downloads by a healthy margin 54% vs 46%." OK, that was boosted by the release of 3.4. But the point still stands. -- Terry Jan Reedy From tjreedy at udel.edu Wed May 28 22:06:08 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 May 2014 22:06:08 -0400 Subject: Forking PyPI package In-Reply-To: <1fgpxn70wxrg0.1rv21r79ohz7z$.dlg@40tude.net> References: <1fgpxn70wxrg0.1rv21r79ohz7z$.dlg@40tude.net> Message-ID: On 5/28/2014 8:31 PM, Wiktor wrote: > Hello. > > There's script pwdhash https://pypi.python.org/pypi/pwdhash.py/0.1.1, > which I always* wanted to port to Python 3. (* - well, i.e. 6 months ;-)) > I'm using this hashing algorithm quite often for years in my browser > (Opera plugin), so I thought that it would be cool to have it as python > script. > > It took me some time to make it work under Python 3, because I knew > nothing about str <-> bytes encoding, and this was biggest issue why > original script wasn't Py3 compatible. So now my version works, it even > supports Unicode characters (original JS script does that, but pwdhash.py > script doesn't), and now I'm planning to do simple GUI version, because > copying from console isn't very comfortable (and I couldn't find good [os > and other packages independent] solution to copy string to clipboard. Best > answer from here http://goo.gl/8V9Ba6 isn't working). > So, my point is, I think maybe it would be useful also to others. > > I'm newbie not only to Python, but to programming in general, so I don't > know, what is best practice in OS programming community. How forking works. > How py2->py3 porting (by 3rd person) is realized in Pythonians community. > Can you suggest me something? I see few scenarios: > > 1) I'm trying to contact with original script's author, and send him my > propositions of changes in code. (Oh, one more thing: my code isn't > backward compatible, and I don't know Py2 that much to include all those > try/except, so it could be Py2+Py3 compatible). He decides, if he wants to > release it as Py3 only version, or combine it with his script and release > Py2+Py3 common version. > > 2) I'm not contacting with him, and I'm forking his project on GitHub > a) under the same name? - probably bad idea > b) under new name (e.g. py3pwdhash)? > Of course all credits about original author stay in code / setup.py. > > 2.1) After forking on GitHub, I'm creating new package on PyPI > a) under old name, but different version number, and new description? > b) under new name, to not confuse users? > > > So, what should I do? > I know, that maybe I shouldn't touch that script in first place and just > mail to author "Hey, would you please port it to Py3?", but I also treated > it as programming exercise, and I didn't think about consequences. ;-) Check the license of the code *and* contact the author if possible. -- Terry Jan Reedy From ben at benfinney.id.au Wed May 28 22:51:42 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 29 May 2014 12:51:42 +1000 Subject: Programmer's text editor, for Python and everything else (was: IDE for python) References: <87iooqw51z.fsf@elektro.pacujo.net> <1401277601.6327.9.camel@greg-Lenovo-G480> <1401326022.6327.11.camel@greg-Lenovo-G480> Message-ID: <85y4xl2t6p.fsf_-_@benfinney.id.au> Greg Schroeder writes: > Any gripes against vim with some tweaks? None from me; Vim is a fine programming (and programmable) editor. It is free software, like Python. This is vital for any tool in which one expects to sink an amount of effort. It means no party has privileged access to change it, which ensures that (unlike proprietary software) it will never be held hostage to one party's disinterest or whim. It works the same way on all important operating systems today that programmers will use to write programs. This is, of course, a result of it being free software; anyone motivated to improve the software on a particular platform has full freedom to do so, and return the improvements to the community. It is mature and highly flexible, both of which mean it can handle any important programming task once someone puts in the effort to configure it. And it has a thriving community, which means most of what you want customised has already been done by others. It supports a massive range of text editing tasks, most of which you don't need to know but will be there when your programming tasks expand as they inevitably do. You won't need to re-learn another tool, but only a plug-in for your existing text editor. All of the above are true for Vim and Emacs, which is why I strongly recommend learning one of them well and using it for all the editing you do while programming. -- \ ?When a well-packaged web of lies has been sold to the masses | `\ over generations, the truth will seem utterly preposterous and | _o__) its speaker a raving lunatic.? ?Dresden James | Ben Finney From steve at pearwood.info Wed May 28 23:22:10 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 29 May 2014 03:22:10 GMT Subject: How to run script from interpreter? References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> Message-ID: <5386a7e2$0$11109$c3e8da3@news.astraweb.com> On Wed, 28 May 2014 11:39:23 -0500, Mark H Harris wrote: > On 5/28/14 2:44 AM, onlyvinish at gmail.com wrote: >> On Friday, January 19, 2001 1:22:23 AM UTC+5:30, Rolander, Dan wrote: >>> What is the best way to run a python script from within the .................................^^^^^^^^ >>> interpreter? What command should I use? >>> >>> >> try using execfile(filename) >> >> > What type of script? python? bash? tcl? other? Most Python scripts are Python. The remainder are usually Python. > If you want to use python as a shell-glue you can try using system. > > >>> from os import system > >>> def ([parms]) > >>> .... blah blah > >>> .... rc = system(" <7xha49wumw.fsf@ruckus.brouhaha.com> Message-ID: <5386ae5d$0$11109$c3e8da3@news.astraweb.com> On Wed, 28 May 2014 14:58:05 -0500, Larry Martell wrote: > On Wed, May 28, 2014 at 2:49 PM, Paul Rubin > wrote: > >> Larry Martell writes: >> > Somthing I came across in my travels through the ether: >> > [1]https://medium.com/@deliciousrobots/5d2ad703365d/ >> >> "Python 3 can revive Python" https://medium.com/p/2a7af4788b10 >> long HN comment thread: https://news.ycombinator.com/item?id=7801834 >> >> "Python 3 is fine" http://sealedabstract.com/rants/python-3-is-fine/ >> >> OT: wow that medium site is obnoxious. >> >> > No company that I work for is using python 3 - they just have too much > of an investment in a python 2 code base to switch. I'm just saying. Is that Python 2 code base aimed at Python 2.7 or 2.6? Or 2.5? Or 2.4? Or even 2.3? Or all of the above? One of the most pernicious myths about this is that there is one single Python 2 ecosystem. There isn't. The company I work for is stuck with 2.6 for the foreseeable future, because that's the version of Python provided by the OS of choice. I recently migrated a client's code base from 2.3 to 2.6, and they will likely stay with 2.6 forever. And I know of at least one company who is using Python 1.5 (yes, 1.5) and have no plans to migrate. 1.5 works for them, and they apparently don't need or don't care about security updates, so why should they migrate? This is all good. If 2.x works for your application, and you don't care about all the awesome new features in 3.3+, don't care about bug fixes and security updates, and don't mind being stuck with a version of Python that will slowly but surely become more and more obsolete, more power to you. The Python core developers have recent committed to providing security updates for 2.7 until 2020. And Redhat have paid support for 2.7 until 2023. So there's no rush. But anyone who makes that decision to stay with 2.x forever is in the same position as those who stay with 1.5 forever. Eventually, you'll have no OS support, no vendor support, no security updates, no bug fixes, it will become harder and harder to find programmers who know that particular version of the language, and even harder to find third party libraries that support it, training new staff in the obsolete version will be hard because all the books and tutorials will be written for more recent versions... My prediction is: - over the next three or four years, there will be a steady trickle of people complaining about Python 3, slowly fading as more people move to Python 3; - when the main Linux distros start using Python 3 as their system Python, there will be a sudden rush of people to Python 3; - about six months before Python 2 drops out of free support, there will be a sudden flood of panicky cries for help from people who didn't bother making a *single* step towards migration over the previous ten years, and suddenly realise that they need to migrate yesterday. -- Steven From stefan_ml at behnel.de Wed May 28 23:51:16 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 29 May 2014 05:51:16 +0200 Subject: Python 3 is killing Python In-Reply-To: References: Message-ID: Terry Reedy, 29.05.2014 02:41: > On 5/28/2014 3:23 PM, Larry Martell wrote: >> Somthing I came across in my travels through the ether: >> >> https://medium.com/@deliciousrobots/5d2ad703365d/ > > Claim: "Python 3 languishes in disuse." > > Fact: in 2013, there were around 14 million downloads of windows installers > for each of 2.7.x and 3.3.x. That can be explained. All those Python 3 downloads can clearly only come from automatic "get me the latest version" downloaders, and when the users realise that they got the totally wrong Python, they'll end up downloading Py2.7 additionally. Thus, the download numbers for Py2 can obviously never drop substantially below those of Py3, minus those users who give up after the first try already (which explains the exception around the time Py3.4 came out). I propose to rename Python 3.x to 1.7.x to prevent users from falling into that evil trap. That will also make it clear again which Python is expected to prevail in the long run. Stefan :o) From steve at pearwood.info Thu May 29 00:03:40 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 29 May 2014 04:03:40 GMT Subject: Python 3 is killing Python References: Message-ID: <5386b19c$0$11109$c3e8da3@news.astraweb.com> On Wed, 28 May 2014 20:41:53 -0400, Terry Reedy wrote: > Claim: Another great strength of Python 2 was that programs written in > it would almost always run on the next version of Python without much > alteration. > > True. True, but only because of the weasel-words "almost always", and "without much alteration". And for the record, for many (although not all) programs written in Python 2.7, it is still true that they will often run in Python 3 with little or no modification. > Changes and removals of deprecated features (like old style > classes) were put off until 3.0 (at the request of some of the noiser > users). That's a little unfair. Noisy users or not, Python Dev has always taken backwards compatibility seriously. Nevertheless, there have been some big changes to Python 2.x that *didn't* wait for 3.x to break backwards compatibility. A few examples that come to mind: - removing string exceptions for good in 2.6; - changes to the treatment in hex() of negative numbers; - the repr() of floats; - changes to the sequence of random numbers generated by the random number module (e.g. while random.random() is guaranteed to return the same sequence of values, random.choice is not); - removal of obsolete modules like bastion and rotor. Any and all of these things can break code that relies on them. -- Steven From no.email at nospam.invalid Thu May 29 00:23:31 2014 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 28 May 2014 21:23:31 -0700 Subject: Python 3 is killing Python References: <7xha49wumw.fsf@ruckus.brouhaha.com> <5386ae5d$0$11109$c3e8da3@news.astraweb.com> Message-ID: <7xlhtl2oxo.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > The Python core developers have recent committed to providing security > updates for 2.7 until 2020. And Redhat have paid support for 2.7 until > 2023. So there's no rush. Perhaps Python 4 will be out by then and the Python 2 holdouts can skip over Python 3. > - over the next three or four years, there will be a steady trickle of > people complaining about Python 3, slowly fading as more people move to > Python 3; > - when the main Linux distros start using Python 3 as their system > Python, there will be a sudden rush of people to Python 3; This is more realistic--people don't explicitly switch but rather the stuff that comes with the OS changes. From satish.muthali at gmail.com Thu May 29 00:48:24 2014 From: satish.muthali at gmail.com (Satish Muthali) Date: Wed, 28 May 2014 21:48:24 -0700 Subject: passing Python assignment value to shell In-Reply-To: References: Message-ID: <92C18466-C23B-4AB9-9863-540A8FB6E3E3@gmail.com> Hello Experts, I was able to figure this out after spending time reading the Python help docs. This is what I went about doing: > reecalc = [s.split() for s in os.Popen("free -ht").read().splitlines()] > freecalc_total = freecalc[4] > freecalc_total = freecalc_total[3] > freecalc_total = freecalc_total.translate(None, 'M?) tmp = "%s" % freecalc_total command = "stressapptest -M %s -s 20" % tmp p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] ? ? ... Please let me know if this is the optimal method to achieve in order to pass the assignment value to shell. I am open to suggestions or a better way of implementation/logic. Thanks again Satish On May 28, 2014, at 1:16 PM, Satish Muthali wrote: > Hello Experts, > > I am trying to extract the available userspace+swap memory and then want to feed this value as an argument to a tool that is executed in the shell. > > so, this is what I have so far: > > reecalc = [s.split() for s in os.Popen("free -ht").read().splitlines()] > freecalc_total = freecalc[4] > freecalc_total = freecalc_total[3] > freecalc_total = freecalc_total.translate(None, 'M?) > > Now I want to feed the value for ?freecalc_total? as an argument to a command executed by the shell. > > For example: > > devnull = open(os.devnull, ?w?) > runCommand = subprocess.call([?stressapptest?, ??, ?20?],stdout=devnull,stderr=subprocess.STDOUT) > devnull.close() > > How do I go about doing this? > > Many thanks in advance > > -Satish -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Thu May 29 01:06:41 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 29 May 2014 06:06:41 +0100 Subject: Python alternative to Google Groups In-Reply-To: References: Message-ID: <5386C061.9030307@timgolden.me.uk> On 28/05/2014 22:54, Steven Clift wrote: > If you are looking for an open source alternative between Google > Groups and Mailman, I wanted to share: > > http://groupserver.org > > It has recent release and new design. Aargh. I hate it when someone does that: posts something so interesting that I want to dive in and start investigating, when I *know* I'm already overcommitted to everything else I'm already doing! On a more serious note, it does look interesting and it would be great to have a credible alternative to promote for people who tend towards GG. Needs to someone to do the setup / config / management though. (Hence my frustrated comment above). TJG From cs at zip.com.au Thu May 29 01:10:24 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 29 May 2014 15:10:24 +1000 Subject: passing Python assignment value to shell In-Reply-To: <92C18466-C23B-4AB9-9863-540A8FB6E3E3@gmail.com> References: <92C18466-C23B-4AB9-9863-540A8FB6E3E3@gmail.com> Message-ID: <20140529051024.GA70864@cskk.homeip.net> On 28May2014 21:48, Satish Muthali wrote: >This is what I went about doing: > > reecalc = [s.split() for s in os.Popen("free -ht").read().splitlines()] I think you dropped an "f" in your cut/paste. Try to be precise. > freecalc_total = freecalc[4] > freecalc_total = freecalc_total[3] > freecalc_total = freecalc_total.translate(None, 'M ) This is syntacticly invalid. Did this really come from working code? Also, .translate does not accept None as its first argument. > tmp = "%s" % freecalc_total If freecalc_total is a string (as it seems from the above) then this line does nothing. If freecalc_total were a number, it would probably be better to use "%d" instead of "%s"; %d will emit an error if freecalc_total is not a number, a useful sanity check. > command = "stressapptest -M %s -s 20" % tmp > p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr= >subprocess.PIPE).communicate()[0] > >Please let me know if this is the optimal method to achieve in order to pass >the assignment value to shell. I am open to suggestions or a better way of >implementation/logic. It is better to avoid shell=True unless you really need to run a shell command (shell syntax or control structures, etc). This is because by plonking "%s" in the middle of your shell string, you leave yourself open to "injection" accidents (or attacks, of you can be tricked in the values you substitute). Since you are running a command with known arguments and no shell syntax, you do not need the shell. So just construct the arguments directly: [ "stressapptest", "-M", str(freecalc_total), "-s", "20" ] and set shell=False. Cheers, Cameron Simpson From miki.tebeka at gmail.com Thu May 29 01:51:02 2014 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 28 May 2014 22:51:02 -0700 (PDT) Subject: daemon thread cleanup approach In-Reply-To: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> References: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> Message-ID: <5a09e351-ab44-43ac-ad3f-10a73e01f092@googlegroups.com> Greetings, > Ok, so I have an issue with cleaning up threads upon a unexpected exit. What do you mean by "unexpected exit"? Uncaught exception? SIGTERM? ... > Using atexit doesn't work because it's called after the daemon threads are killed. I don't follow. Who is killing the daemon threads? > ... > It it possible that this will cause the program to hang in any case? If due to a bug in the cleanup thread it hangs - the program will hang as well. All the best, -- Miki From cs at zip.com.au Thu May 29 02:07:37 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 29 May 2014 16:07:37 +1000 Subject: daemon thread cleanup approach In-Reply-To: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> References: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> Message-ID: <20140529060737.GA73643@cskk.homeip.net> On 28May2014 18:20, Carl Banks wrote: >Here's the solution I came up with: in the library's init function, it will start a non-daemon thread that simply joins the main thread, and then asks all existing worker threads to exit gracefully before timing out and leaving them to be killed. So if an exception ends the main thread, there is still a chance to clean up properly. > >Does anyone see a potential problem with this approach? It it possible that this will cause the program to hang in any case? We can assume that all calls to the library will occur from the main thread, or at least from the same thread. (If that isn't the case, then the caller has taken responsibility to ensure the program doesn't hang.) That sounds safe to me, unless any of the subthreads call some C-level library routine that hangs even in a daemon thread. Which I assume either isn't the case or isn't a bug addressable this way anyway. That's probably the best you can do from the sound of it, given that you may not hang (for longer than your timeout choice) and the calls are all at the whim of an external caller. BTW, what were your dislikes of the with statement? Disclaimer: I'm not a Windows guy. Cheers, Cameron Simpson From wxjmfauth at gmail.com Thu May 29 02:14:46 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 28 May 2014 23:14:46 -0700 (PDT) Subject: Python 3 is killing Python In-Reply-To: References: <7xha49wumw.fsf@ruckus.brouhaha.com> Message-ID: <06a5fce6-90f3-46c7-9b6f-101fadc9fc4e@googlegroups.com> Le mercredi 28 mai 2014 22:24:15 UTC+2, Mark Lawrence a ?crit?: > On 28/05/2014 20:58, Larry Martell wrote: > > > On Wed, May 28, 2014 at 2:49 PM, Paul Rubin > > > wrote: > > > > > > Larry Martell > > > writes: > > > > Somthing I came across in my travels through the ether: > > > > [1]https://medium.com/@deliciousrobots/5d2ad703365d/ > > > > > > "Python 3 can revive Python" https://medium.com/p/2a7af4788b10 > > > long HN comment thread: https://news.ycombinator.com/item?id=7801834 > > > > > > "Python 3 is fine" http://sealedabstract.com/rants/python-3-is-fine/ > > > > > > OT: wow that medium site is obnoxious. > > > > > > > > > No company that I work for is using python 3 - they just have too much > > > of an investment in a python 2 code base to switch. I'm just saying. > > > > > > > So you're happy because you've support until at least 2020, and the > > people using Python 3 are happy, mainly because of the vastly improved > > unicode handling via the FSR and asyncio in 3.4. Presumably the only > > unhappy people are those who keep bleating on about forking Python to > > produce a 2.8, or has work on this already started without my knowledge? > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > > Mark Lawrence > =========== Unicode: a reason to not use Python. jmf From tjreedy at udel.edu Thu May 29 02:57:57 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 May 2014 02:57:57 -0400 Subject: Python 3 is killing Python In-Reply-To: <5386b19c$0$11109$c3e8da3@news.astraweb.com> References: <5386b19c$0$11109$c3e8da3@news.astraweb.com> Message-ID: On 5/29/2014 12:03 AM, Steven D'Aprano wrote: > On Wed, 28 May 2014 20:41:53 -0400, Terry Reedy wrote: > >> Claim: Another great strength of Python 2 was that programs written in >> it would almost always run on the next version of Python without much >> alteration. >> >> True. > > True, but only because of the weasel-words "almost always", and "without > much alteration". > > And for the record, for many (although not all) programs written in > Python 2.7, it is still true that they will often run in Python 3 with > little or no modification. > > >> Changes and removals of deprecated features (like old style >> classes) were put off until 3.0 (at the request of some of the noiser >> users). I am specifically thinking of int / int -> float, which Guido initially proposed for 2.5 after warnings in 2.3, 2.4. The idea of 3.0 with more breakage and 2to3 emerged during that discussion. > That's a little unfair. Noisy users or not, Python Dev has always taken > backwards compatibility seriously. > > Nevertheless, there have been some big changes to Python 2.x that > *didn't* wait for 3.x to break backwards compatibility. A few examples > that come to mind: > > - removing string exceptions for good in 2.6; > - changes to the treatment in hex() of negative numbers; > - the repr() of floats; > - changes to the sequence of random numbers generated by the > random number module (e.g. while random.random() is > guaranteed to return the same sequence of values, > random.choice is not); > - removal of obsolete modules like bastion and rotor. > > Any and all of these things can break code that relies on them. -- Terry Jan Reedy From rosuav at gmail.com Thu May 29 03:40:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 May 2014 17:40:13 +1000 Subject: Forking PyPI package In-Reply-To: <1fgpxn70wxrg0.1rv21r79ohz7z$.dlg@40tude.net> References: <1fgpxn70wxrg0.1rv21r79ohz7z$.dlg@40tude.net> Message-ID: On Thu, May 29, 2014 at 10:31 AM, Wiktor wrote: > I see few scenarios: > > 1) I'm trying to contact with original script's author, and send him my > propositions of changes in code. (Oh, one more thing: my code isn't > backward compatible, and I don't know Py2 that much to include all those > try/except, so it could be Py2+Py3 compatible). He decides, if he wants to > release it as Py3 only version, or combine it with his script and release > Py2+Py3 common version. > > 2) I'm not contacting with him, and I'm forking his project on GitHub > a) under the same name? - probably bad idea > b) under new name (e.g. py3pwdhash)? > Of course all credits about original author stay in code / setup.py. > > 2.1) After forking on GitHub, I'm creating new package on PyPI > a) under old name, but different version number, and new description? > b) under new name, to not confuse users? Unfortunately, you're not legally allowed to just fork it and make your own derivative work, because the original author hasn't put license terms on the project. As it's been posted on github, we can guess that the intention was probably for it to be open source, but your first action has to be to contact the author and ask about license. If you absolutely can't get in touch with him, the only option is to go back to the original protocol and manually reimplement it, completely ignoring this code. It's sad but true; some code dies because of a trivial thing like "Oops, I forgot to actually say that this is MIT-licensed". (At least, I can't see a license anywhere on github there. If you can find another copy of the same code somewhere else, posted by its author, and including a license, then your job is easier.) ChrisA From duncan.booth at invalid.invalid Thu May 29 03:56:17 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 29 May 2014 07:56:17 GMT Subject: Forking PyPI package References: <1fgpxn70wxrg0.1rv21r79ohz7z$.dlg@40tude.net> Message-ID: Chris Angelico wrote: > If you absolutely can't get in touch with him, the only option is to > go back to the original protocol and manually reimplement it, > completely ignoring this code. It's sad but true; some code dies > because of a trivial thing like "Oops, I forgot to actually say that > this is MIT-licensed". > > (At least, I can't see a license anywhere on github there. If you can > find another copy of the same code somewhere else, posted by its > author, and including a license, then your job is easier.) Deep in the code (pwdhash / pwdhash.py.egg-info / PKG-INFO): Author: Lev Shamardin Author-email: shamardin at gmail.com License: BSD Still better to get in touch with the author, but he has actually stated the license albeit in the most minimal way possible. -- Duncan Booth http://kupuguy.blogspot.com From rosuav at gmail.com Thu May 29 04:02:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 May 2014 18:02:36 +1000 Subject: IDE for python In-Reply-To: References: <5385def6$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 29, 2014 at 9:12 AM, Rhodri James wrote: > On Wed, 28 May 2014 14:04:55 +0100, Steven D'Aprano > wrote: > >> My IDE is to have three GUI windows open: >> >> * A web browser for searching the Internet. Any browser will do, but I >> prefer Firefox. >> >> * A tabbed editor. I prefer kate (KDE 3 version, not KDE 4), but geany is >> also good. At a pinch gedit will do. kwrite is another good editor, but >> not tabbed, and it lacks some of the features of kate. >> >> * An xterm or console app, again with tabs. I like KDE 3's konsole, but >> any modern, configurable, tabbed console will do. > > > Interesting. I'm entirely the other way; while I'm perfectly happy to use a > tabbed browser, I find tabbed editors and tabbed consoles awful to use. I > want to have three different sections of code side by side on the screen for > comparison. I want to have half a dozen consoles all running different > things, all positioned so I can take in the state of those things at a > glance. I do not want to be wasting time flicking between this and that, > and relying on my relatively poor memory to cache all that information :-) > > Then again, I'm not as bad as one former colleague of mine. He reckons that > the main advantage of higher resolution screens is that he can tile more > 80x40 console windows on them. I'm half way in between. Tabbed web browser, tabbed editor, but all my terminals/consoles are untabbed. I don't use screen/tmux to have multiple consoles in one window, I use them to share a console between two systems (eg ssh to someone else's computer and let him/her watch what I'm doing). When I switch from terminal to terminal, I use their position and size to identify them (most of my terminal windows are 80x24; some are full screen; and if I'm working with avconv, I widen the window to about 110 or 120). Oh, and I use a tabbed MUD client, which (along with my editor) is pinned to all Xfce workspaces. But the web browser is Workspace 3 only. Not sure why I do that. ChrisA From rosuav at gmail.com Thu May 29 04:06:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 May 2014 18:06:25 +1000 Subject: Forking PyPI package In-Reply-To: References: <1fgpxn70wxrg0.1rv21r79ohz7z$.dlg@40tude.net> Message-ID: On Thu, May 29, 2014 at 5:56 PM, Duncan Booth wrote: > Chris Angelico wrote: > >> If you absolutely can't get in touch with him, the only option is to >> go back to the original protocol and manually reimplement it, >> completely ignoring this code. It's sad but true; some code dies >> because of a trivial thing like "Oops, I forgot to actually say that >> this is MIT-licensed". >> >> (At least, I can't see a license anywhere on github there. If you can >> find another copy of the same code somewhere else, posted by its >> author, and including a license, then your job is easier.) > > Deep in the code (pwdhash / pwdhash.py.egg-info / PKG-INFO): > > Author: Lev Shamardin > Author-email: shamardin at gmail.com > License: BSD > > Still better to get in touch with the author, but he has actually stated > the license albeit in the most minimal way possible. Ah! There you go then. Excellent. In that case, the options I see are (in priority order): 1) Contact the author with your proposed changes, possibly with the actual code or possibly leaving that for later, for inclusion in the original project. 2) Ask the author if he's okay with you maintaining the Python 3 equivalent version as a separate project, under the same name. 3) If you can't get in touch with the author, just maintain that Py3 version, but maybe under a different name to avoid accidental confusion. ChrisA From duncan.booth at invalid.invalid Thu May 29 04:09:03 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 29 May 2014 08:09:03 GMT Subject: IDE for python References: <87iooqw51z.fsf@elektro.pacujo.net> <026d97e2-14f8-485f-b1a5-00dff63af8e1@googlegroups.com> Message-ID: Sameer Rathoud wrote: > On Wednesday, May 28, 2014 5:16:41 PM UTC+5:30, Greg Schroeder wrote: >> > > Please suggest, if we have any free ide for python development. >> >> >> >> Anything that writes text is fine. >> >> I recommend the standard text editor for your OS (Notepad if you use >> >> Windows, Textedit on Mac, whatever is on your GNU/Linux distro by >> >> default) unless you know exactly what you don't like about it. >> >> >> >> Greg > > Right now I am looking for ide on windows 7 platform. > > Actually, I shouldn't say this, But I am bit use to intellisense and > on go warnings and error and my text editor (Notepad) doesn't provide > me that feature . If you are used to Visual Studio then you could try PTVS. I have no experience of it, but http://pytools.codeplex.com/ > PTVS is a free, open source plugin that turns Visual Studio into a > Python IDE. > > PTVS supports CPython, IronPython, editing, browsing, Intellisense, > mixed Python/C++ debugging, remote linux/MacOS debugging, profiling, > IPython, Django, and cloud computing with client libraries for > Windows, Linux and MacOS. > > Designed, developed, and supported by Microsoft and the community. -- Duncan Booth From rosuav at gmail.com Thu May 29 04:15:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 May 2014 18:15:35 +1000 Subject: daemon thread cleanup approach In-Reply-To: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> References: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> Message-ID: On Thu, May 29, 2014 at 11:20 AM, Carl Banks wrote: > Most threads have cleanup work to do (such as deleting temporary directories and killing spawned processes). > > For better or worse, one of the requirements is that the library can't cause the program to hang no matter what... This ma y be a fundamental problem. I don't know how Windows goes with killing processes (can that ever hang?), but certainly you can get unexpected delays deleting a temp dir, although it would probably require some deliberate intervention, like putting your %temp% on a remote drive and then bringing that server down. But believe you me, if there is a stupid way to do something, someone WILL have done it. (Have you ever thought what it'd be like to have your swapfile/pagefile on a network drive? I mean, there's acres of room on the server, why waste some of your precious local space?) So you may want to organize this as a separate spin-off process that does the cleaning up. That way, the main process has completely ended, but the cleanup daemon is still busy. And if you're going to do that, then the easiest way, IMO, would be to have your worker threads be themselves in a separate process; your library passes work across to this other process via a pipe or socket (this being Windows, that would have to be a TCP socket, not a Unix domain socket, but a named pipe would also work), and when the pipe/socket connection is broken, the other end knows that it should clean up. That way, you get to clean up perfectly even if the process terminates abruptly (segfault, system kill, whatever), although possibly delayed until the system notices that the other end is gone. ChrisA (sometimes I feel I suggest TCP/IP sockets the way Grant Imahara suggests building a robot... enthusiastically and maaaaaybe too often) From duncan.booth at invalid.invalid Thu May 29 04:32:40 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 29 May 2014 08:32:40 GMT Subject: IDE for python References: <87iooqw51z.fsf@elektro.pacujo.net> <026d97e2-14f8-485f-b1a5-00dff63af8e1@googlegroups.com> Message-ID: Duncan Booth wrote: > Sameer Rathoud wrote: > >> On Wednesday, May 28, 2014 5:16:41 PM UTC+5:30, Greg Schroeder wrote: >>> > > Please suggest, if we have any free ide for python development. >>> >>> >>> >>> Anything that writes text is fine. >>> >>> I recommend the standard text editor for your OS (Notepad if you use >>> >>> Windows, Textedit on Mac, whatever is on your GNU/Linux distro by >>> >>> default) unless you know exactly what you don't like about it. >>> >>> >>> >>> Greg >> >> Right now I am looking for ide on windows 7 platform. >> >> Actually, I shouldn't say this, But I am bit use to intellisense and >> on go warnings and error and my text editor (Notepad) doesn't provide >> me that feature . > > If you are used to Visual Studio then you could try PTVS. I have no > experience of it, but http://pytools.codeplex.com/ > >> PTVS is a free, open source plugin that turns Visual Studio into a >> Python IDE. >> >> PTVS supports CPython, IronPython, editing, browsing, Intellisense, >> mixed Python/C++ debugging, remote linux/MacOS debugging, profiling, >> IPython, Django, and cloud computing with client libraries for >> Windows, Linux and MacOS. >> >> Designed, developed, and supported by Microsoft and the community. > > I'm just watching the video from that page. It is impressive just how much of intellisense they have working with PTVS: for example inside a function doing 'find all references' on a local variable that happens to be a method passed in to the function shows you all def lines for methods that are passed as parameters. There's a heck of a lot of type inferencing going on. -- Duncan Booth From look at signature.invalid Thu May 29 04:49:21 2014 From: look at signature.invalid (Wiktor) Date: Thu, 29 May 2014 10:49:21 +0200 Subject: Forking PyPI package References: <1fgpxn70wxrg0.1rv21r79ohz7z$.dlg@40tude.net> Message-ID: <13p0c2jf751re$.474x0oify0rv.dlg@40tude.net> On Thu, 29 May 2014 02:31:56 +0200, Wiktor wrote: > So, what should I do? Thanks guys, you're right. I'll contact the Lion. ;-) Yes, I forgot to mention that pwdhash.py was published under BSD licence. Without knowing that I wouldn't even consider forking it. -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') From wolfgang.maier at biologie.uni-freiburg.de Thu May 29 05:41:32 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 29 May 2014 11:41:32 +0200 Subject: IDE for python In-Reply-To: References: Message-ID: On 28.05.2014 12:43, Sameer Rathoud wrote: > Hello everyone, > > I am new to python. > > I am currently using python 3.3 > > With python I got IDLE, but I am not very comfortable with this. > > Please suggest, if we have any free ide for python development. > Seems like not too many other people on this list share my opinion, but let me just say that IDLE is a nice and sufficient (for my purposes) IDE. If you're used to eclipse, then stick with it, but I prefer IDLE over any text editor although admittedly some of its keyboard shortcuts are unusual choices. Cheers, Wolfgang From breamoreboy at yahoo.co.uk Thu May 29 06:57:56 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 29 May 2014 11:57:56 +0100 Subject: Python alternative to Google Groups In-Reply-To: <5386C061.9030307@timgolden.me.uk> References: <5386C061.9030307@timgolden.me.uk> Message-ID: On 29/05/2014 06:06, Tim Golden wrote: > On 28/05/2014 22:54, Steven Clift wrote: >> If you are looking for an open source alternative between Google >> Groups and Mailman, I wanted to share: >> >> http://groupserver.org >> >> It has recent release and new design. > > Aargh. I hate it when someone does that: posts something so interesting > that I want to dive in and start investigating, when I *know* I'm > already overcommitted to everything else I'm already doing! QOTW > > On a more serious note, it does look interesting and it would be great > to have a credible alternative to promote for people who tend towards > GG. Needs to someone to do the setup / config / management though. > (Hence my frustrated comment above). > It would certainly save me, and I'm sure others, a great deal of frustration. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From larry.martell at gmail.com Thu May 29 07:38:33 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 29 May 2014 06:38:33 -0500 Subject: Python 3 is killing Python In-Reply-To: <5386ae5d$0$11109$c3e8da3@news.astraweb.com> References: <7xha49wumw.fsf@ruckus.brouhaha.com> <5386ae5d$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Wed, May 28, 2014 at 10:49 PM, Steven D'Aprano wrote: > On Wed, 28 May 2014 14:58:05 -0500, Larry Martell wrote: > > > On Wed, May 28, 2014 at 2:49 PM, Paul Rubin > > wrote: > > > >> Larry Martell writes: > >> > Somthing I came across in my travels through the ether: > >> > [1]https://medium.com/@deliciousrobots/5d2ad703365d/ > >> > >> "Python 3 can revive Python" https://medium.com/p/2a7af4788b10 > >> long HN comment thread: https://news.ycombinator.com/item?id=7801834 > >> > >> "Python 3 is fine" http://sealedabstract.com/rants/python-3-is-fine/ > >> > >> OT: wow that medium site is obnoxious. > >> > >> > > No company that I work for is using python 3 - they just have too much > > of an investment in a python 2 code base to switch. I'm just saying. > > Is that Python 2 code base aimed at Python 2.7 or 2.6? Or 2.5? Or 2.4? Or > even 2.3? Or all of the above? > One company is using 2.5. Another has been using 2.6 but they are moving to 2.7 because it's required by a package they need. I think that will be the driving force for companies to upgrade. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Thu May 29 07:38:36 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 29 May 2014 12:38:36 +0100 Subject: Python alternative to Google Groups In-Reply-To: References: <5386C061.9030307@timgolden.me.uk> Message-ID: <53871C3C.9060501@timgolden.me.uk> On 29/05/2014 11:57, Mark Lawrence wrote: > On 29/05/2014 06:06, Tim Golden wrote: >> On a more serious note, it does look interesting and it would be great >> to have a credible alternative to promote for people who tend towards >> GG. Needs to someone to do the setup / config / management though. >> (Hence my frustrated comment above). >> > > It would certainly save me, and I'm sure others, a great deal of > frustration. After a quick skim of the feature list etc. it's not actually clear to me that it can operate as a proxy for, eg, a Mailman list. As a standalone group list manager it's clearly worth looking at. But as a means of allowing current GG users a similary way of accessing the existing mail.python.org lists... I'm not so clear. TJG From mail at timgolden.me.uk Thu May 29 07:41:02 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 29 May 2014 12:41:02 +0100 Subject: Command prompt not shown when running Python script with subprocess on Windows In-Reply-To: References: <29c26176-b573-4ac9-bf41-a18a53d7dfb9@googlegroups.com> <53856F53.5010303@timgolden.me.uk> Message-ID: <53871CCE.2080704@timgolden.me.uk> On 28/05/2014 21:46, ps16thypresenceisfullnessofjoy at gmail.com wrote: > > Thank you for your replies. I tried what you suggested in your second > post and it worked. > > That was actually a mistake in the app_list.xml file. As you said: > > %ProgramFiles%\LibreOffice > 4\program\swriter.exe "C:\Users\Timothy\Documents\myfile.odt" > > should instead be: > > "%ProgramFiles%\LibreOffice > 4\program\swriter.exe" "C:\Users\Timothy\Documents\myfile.odt" > > I just made that file as a sample, and didn't actually test it. > > My "shlex dance" has nothing to do with that, though. A few examples > from the interactive interpreter should explain why I am doing it (I > used raw strings in these examples so that I wouldn't need to escape > the backslashes): > >>>> import shlex >>>> shlex.split(r'C:\Users\Timothy\Documents\Python\myscript.py') > ['C:UsersTimothyDocumentsPythonmyscript.py'] >>>> shlex.split(r'C:\\Users\\Timothy\\Documents\\Python\\myscript.py') > >>>> ['C:\\Users\\Timothy\\Documents\\Python\\myscript.py'] >>>> shlex.split(r'C:\Users\Timothy\Documents\Python\myscript.py', >>>> posix=False) > ['C:\\Users\\Timothy\\Documents\\Python\\myscript.py'] > > The first example shows that single backslashes get removed. The > second example shows that double backslashes are preserved intact. > The third example shows that if posix=False, single backslashes are > converted to double backslashes. None of these three behaviors are > acceptable to correctly parse a Windows path, which is why I am doing > what I am to work around the issue. Well I certainly learnt something there! An additional test, which you don't show is this: >>> import shlex >>> shlex.split(r'"c:\users\timothy\documents"') ['c:\\users\\timothy\\documents'] >>> In other words, given the double-quoted data in your XML file, I think it will do the right thing by Windows backslashes. YMMV, I suppose. TJG From slc at publicus.net Thu May 29 08:40:22 2014 From: slc at publicus.net (Steven Clift) Date: Thu, 29 May 2014 07:40:22 -0500 Subject: Python alternative to Google Groups In-Reply-To: <53871C3C.9060501@timgolden.me.uk> References: <5386C061.9030307@timgolden.me.uk> <53871C3C.9060501@timgolden.me.uk> Message-ID: Ah, I wasn't referring to Google Groups newsgroup/usenet connection, but if one wanted to host open source based online groups themselves that are similar to the web experience with Google Groups overall. While folks who just want a mailing list are well served by Mailman, Sympa, and others ... for our organization we need to compete with user expectations from Facebook Groups more and more. We'll we can't compete on features, but we can make our web experience simple and more visually pleasing so the web-centric users stick with us. This is an example neighborhood forum we host - http://e-democracy.org/se - our reality is that if someone creates a Facebook Group in the same local community, we see sharing types migrate there due to the visual experience and baked in mobile sharing options. So our investments in this open source tool could benefit those who see the need to host online communities on their own site where they can innovate further. Thanks! Steve ? On Thu, May 29, 2014 at 6:38 AM, Tim Golden wrote: > On 29/05/2014 11:57, Mark Lawrence wrote: >> On 29/05/2014 06:06, Tim Golden wrote: >>> On a more serious note, it does look interesting and it would be great >>> to have a credible alternative to promote for people who tend towards >>> GG. Needs to someone to do the setup / config / management though. >>> (Hence my frustrated comment above). >>> >> >> It would certainly save me, and I'm sure others, a great deal of >> frustration. > > After a quick skim of the feature list etc. it's not actually clear to > me that it can operate as a proxy for, eg, a Mailman list. As a > standalone group list manager it's clearly worth looking at. But as a > means of allowing current GG users a similary way of accessing the > existing mail.python.org lists... I'm not so clear. > > TJG > > -- > https://mail.python.org/mailman/listinfo/python-list From albert at spenarnc.xs4all.nl Thu May 29 10:06:47 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 29 May 2014 14:06:47 GMT Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> Message-ID: <53873ef7$0$4935$e4fe514c@dreader35.news.xs4all.nl> In article , Mark H Harris wrote: >On 5/11/14 1:59 PM, Chris Angelico wrote: >>>> julia> prec=524288 >>>> 524288 >>> >>>> julia> with_bigfloat_precision(prec) do >>>> println(atan(BigFloat(1)/5)*16 - atan(BigFloat(1)/239)*4) >>>> end >> >> Would it be quicker (and no less accurate) to represent pi as >> atan(BigFloat(1))*4 instead? That's how I originally met a >> pi-calculation (as opposed to "PI = 3.14" extended to however much >> accuracy someone cared to do). > > No. Simple experiment will show you. The atan(x<=1) will converge >faster. For 524288 bits atan(1) formula converged in 3 seconds, and >Machin's formula atan(x<1) converged in 2 seconds. Where it becomes very >apparent is 10K and 100K or above. Also, the difference is much more >noticeable in Python than in Julia, but it is there no-the-less. > > But here is the cool part: what if your ?? function could be broken >down into three very fast converging atan(x<1) functions like this one: > > > pi = 24*atan(1/8) + 8*atan(1/57) + 4*atan(1/239) (Shanks used this) > > >... and then, you have julia send each piece to a separate >processor|core (it does this at its center) and they converge together, >then julia pieces them together at the end. Then things get incredibly >faster. I know now how to interpret your posts. Using "incredible" for a mere factor of at most 3. Balanced views are more convincing. Groetjes Albert > -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From albert at spenarnc.xs4all.nl Thu May 29 10:26:07 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 29 May 2014 14:26:07 GMT Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> Message-ID: <5387437f$0$4935$e4fe514c@dreader35.news.xs4all.nl> In article <8761l9pi3n.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > >Producing an effective JIT for Python seems like a formidable challenge >but not impossible in principle. After all, the developer *could* >provide that static typing information in, like, 99.9% of the code. That >would be feat worthy of a Millennium Technology Prize. It would be like >having the cake and eating it, too. I'm totally flabbergasted by comments like this. I always thought that the real point of JIT was that it can take advantage of type information that is not available until runtime. If it can infer that something is an integer, just before entering a loop to be executed millions of times, that should be a big win, not? > > >Marko -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From marko at pacujo.net Thu May 29 10:50:00 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 29 May 2014 17:50:00 +0300 Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> <5387437f$0$4935$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <87mwe0zlk7.fsf@elektro.pacujo.net> albert at spenarnc.xs4all.nl (Albert van der Horst): > I always thought that the real point of JIT was that it can take > advantage of type information that is not available until runtime. If > it can infer that something is an integer, just before entering a loop > to be executed millions of times, that should be a big win, not? JIT most generally refers to on-the-fly optimization of the code. In the case of Java, the code to be executed is bytecode that is independent of the CPU instruction set and thus needs to be interpreted. You could perform the optimization before the execution and save the executable binary, but the Java gods are reluctant to do that for ideological reasons ("compile once, run everywhere"). Python code, too, is compiled into interpreted bytecode. Again, you could compile it into machine code ahead of execution or perform the compilation on the fly with JIT techniques. However, Python is so ridiculously dynamic that such compilers have an extremely difficult time making effective optimizations. Marko From rosuav at gmail.com Thu May 29 10:58:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 00:58:36 +1000 Subject: Fortran In-Reply-To: <87mwe0zlk7.fsf@elektro.pacujo.net> References: <87tx91warf.fsf@elektro.pacujo.net> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> <5387437f$0$4935$e4fe514c@dreader35.news.xs4all.nl> <87mwe0zlk7.fsf@elektro.pacujo.net> Message-ID: On Fri, May 30, 2014 at 12:50 AM, Marko Rauhamaa wrote: > Python code, too, is compiled into interpreted bytecode. Again, you > could compile it into machine code ahead of execution or perform the > compilation on the fly with JIT techniques. However, Python is so > ridiculously dynamic that such compilers have an extremely difficult > time making effective optimizations. I'd avoid the word "ridiculously" there. Python's dynamism is a feature, not a flaw. It's a feature with consequences (but then, what isn't), and if you don't want it, use a different language, but it's not ridiculous. ChrisA From marko at pacujo.net Thu May 29 11:09:55 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 29 May 2014 18:09:55 +0300 Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> <5387437f$0$4935$e4fe514c@dreader35.news.xs4all.nl> <87mwe0zlk7.fsf@elektro.pacujo.net> Message-ID: <87iooozkn0.fsf@elektro.pacujo.net> Chris Angelico : > On Fri, May 30, 2014 at 12:50 AM, Marko Rauhamaa wrote: >> Python code, too, is compiled into interpreted bytecode. Again, you >> could compile it into machine code ahead of execution or perform the >> compilation on the fly with JIT techniques. However, Python is so >> ridiculously dynamic that such compilers have an extremely difficult >> time making effective optimizations. > > I'd avoid the word "ridiculously" there. Python's dynamism is a > feature, not a flaw. It's a feature with consequences (but then, what > isn't), and if you don't want it, use a different language, but it's > not ridiculous. The ridiculous dynamism is the main selling point of high-level programming languages. I wouldn't have it any other way. But from the point of view of the JIT developer, it must feel like Alice in Wonderland. Marko From tjreedy at udel.edu Thu May 29 12:39:18 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 May 2014 12:39:18 -0400 Subject: IDE for python In-Reply-To: References: Message-ID: On 5/29/2014 5:41 AM, Wolfgang Maier wrote: > On 28.05.2014 12:43, Sameer Rathoud wrote: >> Hello everyone, >> >> I am new to python. >> >> I am currently using python 3.3 >> >> With python I got IDLE, but I am not very comfortable with this. What bothers you the most. > Seems like not too many other people on this list share my opinion, but > let me just say that IDLE is a nice and sufficient (for my purposes) IDE. > If you're used to eclipse, then stick with it, but I prefer IDLE over > any text editor although admittedly some of its keyboard shortcuts are > unusual choices. I am curious how many of the editors people have been recommending have all of the following Idle features, that I use constantly. 1. Run code in the editor with a single keypress. 2. Display output and traceback in a window that lets you jump from the any line in the traceback to the corresponding file and line, opening the file if necessary. 3. Search unopened files (grep) for a string or re. 4. Display grep output in a window that lets you jump from any 'hit' to the corresponding file and line, opening the file if necessary. -- Terry Jan Reedy From paul.nospam at rudin.co.uk Thu May 29 12:44:35 2014 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 29 May 2014 17:44:35 +0100 Subject: IDE for python References: Message-ID: <8761kozg98.fsf@rudin.co.uk> Terry Reedy writes: > On 5/29/2014 5:41 AM, Wolfgang Maier wrote: >> On 28.05.2014 12:43, Sameer Rathoud wrote: >>> Hello everyone, >>> >>> I am new to python. >>> >>> I am currently using python 3.3 >>> >>> With python I got IDLE, but I am not very comfortable with this. > > What bothers you the most. > >> Seems like not too many other people on this list share my opinion, but >> let me just say that IDLE is a nice and sufficient (for my purposes) IDE. >> If you're used to eclipse, then stick with it, but I prefer IDLE over >> any text editor although admittedly some of its keyboard shortcuts are >> unusual choices. > > I am curious how many of the editors people have been recommending have all of > the following Idle features, that I use constantly. > > 1. Run code in the editor with a single keypress. > > 2. Display output and traceback in a window that lets you jump from the any > line in the traceback to the corresponding file and line, opening the file if > necessary. > > 3. Search unopened files (grep) for a string or re. > > 4. Display grep output in a window that lets you jump from any 'hit' to > the corresponding file and line, opening the file if necessary. Emacs. From rosuav at gmail.com Thu May 29 12:51:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 02:51:57 +1000 Subject: IDE for python In-Reply-To: References: Message-ID: On Fri, May 30, 2014 at 2:39 AM, Terry Reedy wrote: > I am curious how many of the editors people have been recommending have all > of the following Idle features, that I use constantly. Regarding SciTE: > 1. Run code in the editor with a single keypress. Yes, although for most of what I like to do, it's not appropriate. But if you're developing a script that runs and then terminates, yes, you certainly can. > 2. Display output and traceback in a window that lets you jump from the any > line in the traceback to the corresponding file and line, opening the file > if necessary. Yes; it recognizes the most common formats used by C compilers, as well as Python's traceback. Pressing F4 repeatedly will cycle you through the output pane, effectively taking you from one step to another in the traceback. (Obviously if you have more than one traceback, it'll go straight from one to another, which won't always be useful.) You can also double-click a line to go straight there. > 3. Search unopened files (grep) for a string or re. Yes, either using grep itself (fourth point) or using an internal search that's more akin to an old DOS or OS/2 style of search. Either way, the results come up in the output pane, and F4 will cycle through them. > 4. Display grep output in a window that lets you jump from any 'hit' to > the corresponding file and line, opening the file if necessary. As above. These three are all one feature, really. You can type commands in the output pane and they'll be executed; any program output that matches one of its parseable "this file, this line" formats (which is true of 'grep -n') will be picked up. ChrisA From ppearson at nowhere.invalid Thu May 29 13:53:16 2014 From: ppearson at nowhere.invalid (Peter Pearson) Date: 29 May 2014 17:53:16 GMT Subject: Fortran (Was: The "does Python have variables?" debate) References: <87tx91warf.fsf@elektro.pacujo.net> <53873ef7$0$4935$e4fe514c@dreader35.news.xs4all.nl> Message-ID: On 29 May 2014 14:06:47 GMT, Albert van der Horst wrote: > In article , > Mark H Harris wrote: >>On 5/11/14 1:59 PM, Chris Angelico wrote: >>>>> julia> prec=524288 >>>>> 524288 >>>> >>>>> julia> with_bigfloat_precision(prec) do >>>>> println(atan(BigFloat(1)/5)*16 - atan(BigFloat(1)/239)*4) >>>>> end >>> >>> Would it be quicker (and no less accurate) to represent pi as >>> atan(BigFloat(1))*4 instead? That's how I originally met a >>> pi-calculation (as opposed to "PI = 3.14" extended to however much >>> accuracy someone cared to do). >> >> No. Simple experiment will show you. The atan(x<=1) will converge >>faster. For 524288 bits atan(1) formula converged in 3 seconds, and >>Machin's formula atan(x<1) converged in 2 seconds. Where it becomes very >>apparent is 10K and 100K or above. Also, the difference is much more >>noticeable in Python than in Julia, but it is there no-the-less. >> >> But here is the cool part: what if your ? function could be broken >>down into three very fast converging atan(x<1) functions like this one: >> >> > pi = 24*atan(1/8) + 8*atan(1/57) + 4*atan(1/239) (Shanks used this) >> >> >>... and then, you have julia send each piece to a separate >>processor|core (it does this at its center) and they converge together, >>then julia pieces them together at the end. Then things get incredibly >>faster. > > I know now how to interpret your posts. Using "incredible" for a mere > factor of at most 3. Balanced views are more convincing. Won't there be an additional speedup resulting from the computation of atan(x) converging faster for x=1/8 than for x=1? -- To email me, substitute nowhere->spamcop, invalid->net. From steve+comp.lang.python at pearwood.info Thu May 29 13:57:26 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2014 17:57:26 GMT Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> <5387437f$0$4935$e4fe514c@dreader35.news.xs4all.nl> <87mwe0zlk7.fsf@elektro.pacujo.net> Message-ID: <53877506$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 May 2014 17:50:00 +0300, Marko Rauhamaa wrote: > albert at spenarnc.xs4all.nl (Albert van der Horst): > >> I always thought that the real point of JIT was that it can take >> advantage of type information that is not available until runtime. If >> it can infer that something is an integer, just before entering a loop >> to be executed millions of times, that should be a big win, not? > > JIT most generally refers to on-the-fly optimization of the code. Using information available at run-time, which was Albert's point. Why would you delay compilation to run-time if you're only going to use information available at edit-time? You pay all the cost of delayed compilation and get none of the benefits. > In the > case of Java, the code to be executed is bytecode that is independent of > the CPU instruction set and thus needs to be interpreted. Not so. There are Java compilers which compile to machine code. http://www.excelsiorjet.com/ http://gcc.gnu.org/java/ Both are AOT (Ahead Of Time) compilers, but that's not important for this discussion. If an AOT compiler can emit machine code, so can a JIT compiler, and that's exactly what PyPy does: http://morepypy.blogspot.com.au/2011/08/visualization-of-jitted-code.html > You could > perform the optimization before the execution and save the executable > binary, but the Java gods are reluctant to do that for ideological > reasons ("compile once, run everywhere"). Who are these Java gods of which you speak? > Python code, too, is compiled into interpreted bytecode. An unjustified assertion. The Python infrastructure is incredibly rich, and compilers include many different strategies: - compile to byte-code for some virtual machine (e.g. JVM, .Net, Parrot) - static compilation to machine-code; - JIT compilation to machine-code; - translation to some other language (e.g. Haskell, Javascript) followed by compilation of that code to machine code. I've already mentioned that PyPy compiles to machine code. So did its predecessor, Psyco. Both are JIT compilers, as are Numba and Parakeet and Pyston and Unladen Swallow[1]. Then there's at least one AOT compiler, Nuitka, which produces machine code. It's not optimized yet, but there's only one guy working on this project, and it's still young. http://nuitka.net/posts/static-compilation-that-is-the-point.html > Again, you > could compile it into machine code ahead of execution or perform the > compilation on the fly with JIT techniques. You're talking as if this were only theoretical. It is not. The state of the art in compiler techniques has advanced a lot since the old days of the Pascal P-Machine. Parakeet, for example[2], compiles numeric functions to optimized machine code on the fly using decorators, using Static Single Assignment, which some wag described as being "covered in Fisher Price's My First Compiler"[3]. > However, Python is so > ridiculously dynamic that such compilers have an extremely difficult > time making effective optimizations. Anyone who used Psyco ten years ago would laugh at that statement, and Psyco isn't even close to cutting edge. [1] Unladen Swallow was not a failure. It's just that expectations were so high ("OMG OMG Google is making a Python compiler this will be more powerful than the Death Star and faster than time travel!!!1!") that it couldn't help but be a disappointment. [2] http://www.phi-node.com/2013/01/a-transformative-journey-from-python-to.html [3] http://blog.cdleary.com/2011/06/mapping-the-monkeysphere/ -- Steven D'Aprano http://import-that.dreamwidth.org/ From marko at pacujo.net Thu May 29 14:55:34 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 29 May 2014 21:55:34 +0300 Subject: Fortran References: <87tx91warf.fsf@elektro.pacujo.net> <871tvxtwgj.fsf@dpt-info.u-strasbg.fr> <8761l9pi3n.fsf@elektro.pacujo.net> <5387437f$0$4935$e4fe514c@dreader35.news.xs4all.nl> <87mwe0zlk7.fsf@elektro.pacujo.net> <53877506$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k394ct3t.fsf@elektro.pacujo.net> Steven D'Aprano : > You're talking as if this were only theoretical. It is not. The state > of the art in compiler techniques has advanced a lot since the old > days of the Pascal P-Machine. Parakeet, for example[2], compiles > numeric functions to optimized machine code on the fly using > decorators, using Static Single Assignment, which some wag described > as being "covered in Fisher Price's My First Compiler"[3]. >From your Parakeet link: An eager reader may be thinking: I can just stick that decorator atop any Python function and it will magically run faster? Great! I'll paste @jit all over my code and my Python performance problems will be solved! Easy with those decorators! Parakeet is not a general-purpose compiler for all of Python. Parakeet only supports a handful of Python's data types: numbers, tuples, slices, and NumPy arrays. Thus, by its own admission, it is not the Holy Grail I've been talking about: a Python optimizer that makes Java redundant. For example, I have never really had to deal with numeric computations; I have implemented numerous communication protocols in C, C++, Java and Python. I would love to stick to Python, but I haven't seen the performance numbers posted that would support that decision. Also, I know people who are using Java in large-scale online game servers. Could they be using Python instead? > [1] Unladen Swallow was not a failure. It's just that expectations > were so high ("OMG OMG Google is making a Python compiler this will be > more powerful than the Death Star and faster than time travel!!!1!") > that it couldn't help but be a disappointment. That would be *my* expectation. Until then, I'm quite happy with CPython performance in the numerous niches where it is enough. Marko From ps16thypresenceisfullnessofjoy at gmail.com Thu May 29 15:21:00 2014 From: ps16thypresenceisfullnessofjoy at gmail.com (ps16thypresenceisfullnessofjoy at gmail.com) Date: Thu, 29 May 2014 12:21:00 -0700 (PDT) Subject: Command prompt not shown when running Python script with subprocess on Windows In-Reply-To: References: <29c26176-b573-4ac9-bf41-a18a53d7dfb9@googlegroups.com> <53856F53.5010303@timgolden.me.uk> Message-ID: That's interesting, now I learned something else too. As I said before, though, I want users to be able to enter paths in the XML file exactly the way they would be entered in a Windows shortcut. (Actually, my program currently only has one Windows user, for whom I develop it [I don't even use it myself :-0].) Since in a Windows shortcut you don't need to put quotes around a path that doesn't contain spaces, I want to follow that behavior in my program as well. So actually, I see that the line: "%ProgramFiles%\LibreOffice 4\program\swriter.exe" "C:\Users\Timothy\Documents\myfile.odt" should instead be: "%ProgramFiles%\LibreOffice 4\program\swriter.exe" C:\Users\Timothy\Documents\myfile.odt because there are no spaces in the second path, but there is a space in the first one. So I guess I'll still have to do my "shlex dance" (which for some reason I keep on mistyping as "shlex dane" :-)) unless I can learn a better way to do it. Also, is my calling os.path.expandvars only on the first argument a good idea? I want to accept environment variables in my program, but I don't want to call os.path.expandvars on all the arguments, because I want to let other programs take care of parsing their own arguments. I'm just wondering if I should relook at the whole way that I am doing things here. Maybe it would be better to just use shlex.split and subprocess.Popen and not try to follow the behavior of Windows shortcuts so closely? (But then it might be hard for some Windows users to understand how to use the program if I didn't.) What do you think? From pavlovevidence at gmail.com Thu May 29 15:40:37 2014 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 29 May 2014 12:40:37 -0700 (PDT) Subject: daemon thread cleanup approach In-Reply-To: References: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> Message-ID: On Thursday, May 29, 2014 1:15:35 AM UTC-7, Chris Angelico wrote: > On Thu, May 29, 2014 at 11:20 AM, Carl Banks wrote: > > > Most threads have cleanup work to do (such as deleting temporary directories and killing spawned processes). > > > > > > For better or worse, one of the requirements is that the library can't cause the program to hang no matter what... > > > > This ma y be a fundamental problem. I don't know how Windows goes with > > killing processes (can that ever hang?), but certainly you can get > > unexpected delays deleting a temp dir, although it would probably > > require some deliberate intervention, like putting your %temp% on a > > remote drive and then bringing that server down. But believe you me, > > if there is a stupid way to do something, someone WILL have done it. > > (Have you ever thought what it'd be like to have your > > swapfile/pagefile on a network drive? I mean, there's acres of room on > > the server, why waste some of your precious local space?) > > > > So you may want to organize this as a separate spin-off process that > > does the cleaning up. [snip rest] Thanks, that's good information. Even if the temp directories do fail to be removed before the join times out (which probably won't happen much) the situation is still no worse than the situation where the daemon thread is just killed without any chance to clean up. And subprocesses would be a more reliable way to ensure cleanup and might be the direction I take it in the future. Carl Banks From harrismh777 at gmail.com Thu May 29 16:11:31 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 29 May 2014 15:11:31 -0500 Subject: IDE for python References: <8761kozg98.fsf@rudin.co.uk> Message-ID: On 5/29/14 11:44 AM, Paul Rudin wrote: > Terry Reedy writes: >> I am curious how many of the editors people have been recommending have all of >> the following Idle features, that I use constantly. >> >> 1. Run code in the editor with a single keypress. >> >> 2. Display output and traceback in a window that lets you jump from the any >> line in the traceback to the corresponding file and line, opening the file if >> necessary. >> >> 3. Search unopened files (grep) for a string or re. >> >> 4. Display grep output in a window that lets you jump from any 'hit' to >> the corresponding file and line, opening the file if necessary. > > Emacs. > Emacs is the coolest tech editor out there, by far; however, the very nature of Emacs (which makes it the coolest) is also unfortunately the very thing that sucks about it... highly configurable (&extensible), highly complex, intricately complicated; especially for novices. The OP is looking for an "IDE-like" interactive environment, because he is "uncomfortable" with IDLE. IDLE is THE choice, however ---precisely because IDLE is clean, elegant, and most importantly "simple". It is simple to understand, and it is even simpler to use effectively... even for novice pythonics. IDLE is straight-forward. As Terry pointed out, IDLE is very useful and functional. And in the modern python world is also very stable (IDLE used to get a black eye because it had snags early-on). Today IDLE works, has great features, and actually helps new users get on-board with Python. marcus From harrismh777 at gmail.com Thu May 29 16:26:37 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 29 May 2014 15:26:37 -0500 Subject: How to run script from interpreter? References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> Message-ID: On 5/28/14 10:22 PM, Steven D'Aprano wrote: >> If you want to use python as a shell-glue you can try using system. >> >> >>> from os import system >> >>> def ([parms]) >> >>> .... blah blah >> >>> .... rc = system(" > > os.system is cool for quick and dirty calls to an external command. But > for serious work, the subprocess module is better. > ... yup, particularly for non trivial network related stuff. Neither here nor there, but I just learned the ";" character command today for the Julia REPL, and got to thinking that python should have a similar way for the REPL to drop into "shell" mode for system commands. So, I might code a clear screen in python: def cls() rc = system("clear") or in Julia function cls() run(`clear`) end ... but on Julia we can also do this: ; clear On the Julia REPL the ";" character drops the julia prompt into shell. I think the IDLE REPL should have a system shell mode. What say you? marcus From breamoreboy at yahoo.co.uk Thu May 29 16:41:29 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 29 May 2014 21:41:29 +0100 Subject: IDE for python In-Reply-To: References: <8761kozg98.fsf@rudin.co.uk> Message-ID: On 29/05/2014 21:11, Mark H Harris wrote: > The OP is looking for an "IDE-like" interactive environment, because he > is "uncomfortable" with IDLE. IDLE is THE choice, however ---precisely > because IDLE is clean, elegant, and most importantly "simple". It is > simple to understand, and it is even simpler to use effectively... even > for novice pythonics. IDLE is straight-forward. > > As Terry pointed out, IDLE is very useful and functional. And in the > modern python world is also very stable (IDLE used to get a black eye > because it had snags early-on). Today IDLE works, has great features, > and actually helps new users get on-board with Python. > > marcus > I'll point out (again?) that IDLE is improving all the time thanks to Terry & Co. This explains why http://legacy.python.org/dev/peps/pep-0434/ Strangely I've been using Eclipse and Pydev since porting Java to Python some time ago, it really simplified the process. However I'd been thinking of changing and picked IDLE because it's there. Perfectly adequate for my current needs. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From tjreedy at udel.edu Thu May 29 16:45:14 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 May 2014 16:45:14 -0400 Subject: IDE for python In-Reply-To: References: Message-ID: On 5/29/2014 12:51 PM, Chris Angelico wrote: > On Fri, May 30, 2014 at 2:39 AM, Terry Reedy wrote: >> I am curious how many of the editors people have been recommending have all >> of the following Idle features, that I use constantly. > > Regarding SciTE: > >> 1. Run code in the editor with a single keypress. > > Yes, although for most of what I like to do, it's not appropriate. But > if you're developing a script that runs and then terminates, yes, you > certainly can. > >> 2. Display output and traceback in a window that lets you jump from the any >> line in the traceback to the corresponding file and line, opening the file >> if necessary. > > Yes; it recognizes the most common formats used by C compilers, as > well as Python's traceback. Pressing F4 repeatedly will cycle you > through the output pane, effectively taking you from one step to > another in the traceback. (Obviously if you have more than one > traceback, it'll go straight from one to another, which won't always > be useful.) You can also double-click a line to go straight there. > >> 3. Search unopened files (grep) for a string or re. > > Yes, either using grep itself (fourth point) or using an internal > search that's more akin to an old DOS or OS/2 style of search. Either > way, the results come up in the output pane, and F4 will cycle through > them. > >> 4. Display grep output in a window that lets you jump from any 'hit' to >> the corresponding file and line, opening the file if necessary. > > As above. These three are all one feature, really. Thank you. This makes your recommendation understandable. > You can type > commands in the output pane and they'll be executed; any program > output that matches one of its parseable "this file, this line" > formats (which is true of 'grep -n') will be picked up. Find in Files (grep) is implemented within Idle, in Python, using re. One of the subprojects of this summer's Idle GSOC student, Saimadhav Heblikar, is to add to Idle something similar to what you describe above. Run an external code analyzer (PyLint/Flake/Checker, whatever...), capture output, and jump to indicated locations. For Idle, the prime intended use would, of course, be for analyzing Python files. -- Terry Jan Reedy From ben at benfinney.id.au Thu May 29 17:05:35 2014 From: ben at benfinney.id.au (Ben Finney) Date: Fri, 30 May 2014 07:05:35 +1000 Subject: IDE for python References: Message-ID: <85mwe02t40.fsf@benfinney.id.au> Terry Reedy writes: > I am curious how many of the editors people have been recommending > have all of the following Idle features, that I use constantly. You can satisfy such wonderings with a search for the answers to such questions, which is how I got these answers. > 1. Run [Python] code in the editor with a single keypress. That's not very clear. If you mean, run the entire file being edited: yes, Vim and Emacs can do that. I don't use such a feature, because I almost never want to run the *entire* module; I want to test the one function I'm working on at that moment. For that purpose, a unit test is more appropriate. Vim and Emacs also have the feature to run a Python unit test suite with a single key and navigate the output. > 2. Display output and traceback in a window that lets you jump from > the any line in the traceback to the corresponding file and line, > opening the file if necessary. Yes, any decent programmer's editor will have this, once it is taught how to parse the error output from the language interpreter. For Vim and Emacs, yes, they already know how to capture error output and interactively jump to the referenced locations in the code. They also both have interactive debugger modes, including for Python. > 3. Search unopened files (grep) for a string or re. > 4. Display grep output in a window that lets you jump from any 'hit' > to the corresponding file and line, opening the file if necessary. This is an essential feature of any decent programming editor, and Vim and Emacs certainly have the feature to grep a file tree and navigate the results interactively. -- \ ?[Entrenched media corporations will] maintain the status quo, | `\ or die trying. Either is better than actually WORKING for a | _o__) living.? ?ringsnake.livejournal.com, 2007-11-12 | Ben Finney From ian.g.kelly at gmail.com Thu May 29 17:54:09 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 29 May 2014 15:54:09 -0600 Subject: Forking PyPI package In-Reply-To: References: <1fgpxn70wxrg0.1rv21r79ohz7z$.dlg@40tude.net> Message-ID: On Thu, May 29, 2014 at 1:40 AM, Chris Angelico wrote: > If you absolutely can't get in touch with him, the only option is to > go back to the original protocol and manually reimplement it, > completely ignoring this code. It's sad but true; some code dies > because of a trivial thing like "Oops, I forgot to actually say that > this is MIT-licensed". The second part of that is that the code should actually *include* the license text. Just writing "BSD license" somewhere on the website or in package metadata is annoyingly common but somewhat questionable in how a judge might interpret it. For instance, there at least four different versions of the BSD license; which one did you mean? From RasikaSrinivasan at gmail.com Thu May 29 18:08:02 2014 From: RasikaSrinivasan at gmail.com (RasikaSrinivasan at gmail.com) Date: Thu, 29 May 2014 15:08:02 -0700 (PDT) Subject: Binary data exchange Message-ID: friends I have a pair of simple python programs as follows: #!/usr/bin/python # broadcast.py import socket from ctypes import * import random class PurgeData(Structure): _fields_ = [("press",c_int), ("ticks",c_int), ("volume",c_float)] myPort = 10756 sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) addr = ('localhost',myPort) #sock.sendto(data,addr) presdata = PurgeData() presdata.press = 0 presdata.ticks = 100 for msg in range(1,20): presdata.press = presdata.press+1 presdata.ticks = presdata.ticks+1 presdata.volume = random.random() sock.sendto(presdata,addr) #-------------------- #!/usr/bin/python # Receiver import socket from ctypes import * class PurgeData(Structure): _fields_ = [("press",c_int), ("ticks",c_int), ("volume",c_float)] myPort = 10756 sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) addr = ('localhost',myPort) sock.bind(addr) presdata=PurgeData() while True: data,addr = sock.recvfrom(1024) memmove(addressof(presdata),data.strip(),len(data.strip())) print presdata.press, presdata.ticks, presdata.volume --------------------- When I tried to run this I get some bizarre results: 1 101 0.343009024858 2 102 0.36397305131 3 103 0.495895296335 4 104 0.372055351734 5 105 0.933839201927 6 106 0.931187808514 7 107 0.876732826233 8 108 0.298638045788 1828716544 -754974720 0.183644190431 1845493760 1660944384 0.186560109258 1862270976 1056964608 0.18631502986 1879048192 1728053248 0.186902835965 1895825408 2097152000 0.18658298254 14 114 0.407857120037 15 115 0.833854913712 16 116 0.00646247947589 17 117 0.297783941031 18 118 0.58082228899 19 119 0.61717569828 the received data for the messages 9 thru 13 are not as expected. I wonder if anyone can see what I am doing wrong? Appreciate any hints. thanks, srini From RasikaSrinivasan at gmail.com Thu May 29 18:13:44 2014 From: RasikaSrinivasan at gmail.com (RasikaSrinivasan at gmail.com) Date: Thu, 29 May 2014 15:13:44 -0700 (PDT) Subject: Binary data exchange In-Reply-To: References: Message-ID: BTW - My environment is: H:\>python Enthought Canopy Python 2.7.6 | 64-bit | (default, Apr 11 2014, 20:31:44) [MSC v .1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> From travisgriggs at gmail.com Thu May 29 18:40:36 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Thu, 29 May 2014 15:40:36 -0700 Subject: IDE for python In-Reply-To: References: Message-ID: > On May 28, 2014, at 3:43, Sameer Rathoud wrote: > > Hello everyone, > > I am new to python. > > I am currently using python 3.3 > > With python I got IDLE, but I am not very comfortable with this. > > Please suggest, if we have any free ide for python development. > -- > https://mail.python.org/mailman/listinfo/python-list I use either vim or textwrangler for simple one file scripts. For larger things with multiple files and/or classes, I like pycharm best ( free community edition ). I tried both pydev and wing before that. From python at mrabarnett.plus.com Thu May 29 19:09:21 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 30 May 2014 00:09:21 +0100 Subject: Binary data exchange In-Reply-To: References: Message-ID: <5387BE21.4010404@mrabarnett.plus.com> On 2014-05-29 23:08, RasikaSrinivasan at gmail.com wrote: > friends > > I have a pair of simple python programs as follows: > > #!/usr/bin/python > # broadcast.py > import socket > from ctypes import * > import random > > class PurgeData(Structure): > _fields_ = [("press",c_int), ("ticks",c_int), ("volume",c_float)] > > myPort = 10756 > > sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) > addr = ('localhost',myPort) > #sock.sendto(data,addr) > > presdata = PurgeData() > presdata.press = 0 > presdata.ticks = 100 > > for msg in range(1,20): > presdata.press = presdata.press+1 > presdata.ticks = presdata.ticks+1 > presdata.volume = random.random() > sock.sendto(presdata,addr) > > #-------------------- > > #!/usr/bin/python > # Receiver > import socket > > from ctypes import * > > class PurgeData(Structure): > _fields_ = [("press",c_int), ("ticks",c_int), ("volume",c_float)] > > myPort = 10756 > > sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) > addr = ('localhost',myPort) > sock.bind(addr) > presdata=PurgeData() > > while True: > data,addr = sock.recvfrom(1024) > memmove(addressof(presdata),data.strip(),len(data.strip())) > print presdata.press, presdata.ticks, presdata.volume > > --------------------- > > When I tried to run this I get some bizarre results: > > > 1 101 0.343009024858 > 2 102 0.36397305131 > 3 103 0.495895296335 > 4 104 0.372055351734 > 5 105 0.933839201927 > 6 106 0.931187808514 > 7 107 0.876732826233 > 8 108 0.298638045788 > 1828716544 -754974720 0.183644190431 > 1845493760 1660944384 0.186560109258 > 1862270976 1056964608 0.18631502986 > 1879048192 1728053248 0.186902835965 > 1895825408 2097152000 0.18658298254 > 14 114 0.407857120037 > 15 115 0.833854913712 > 16 116 0.00646247947589 > 17 117 0.297783941031 > 18 118 0.58082228899 > 19 119 0.61717569828 > > the received data for the messages 9 thru 13 are not as expected. > > I wonder if anyone can see what I am doing wrong? > > Appreciate any hints. thanks, srini > I don't understand why you're using the .strip method. That's for stripping whitespace from text, but you're not sending and receiving text, you're sending and receiving binary data. Personally, I'd use the struct module. From ian.g.kelly at gmail.com Thu May 29 19:20:47 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 29 May 2014 17:20:47 -0600 Subject: Binary data exchange In-Reply-To: <5387BE21.4010404@mrabarnett.plus.com> References: <5387BE21.4010404@mrabarnett.plus.com> Message-ID: On Thu, May 29, 2014 at 5:09 PM, MRAB wrote: > On 2014-05-29 23:08, RasikaSrinivasan at gmail.com wrote: >> the received data for the messages 9 thru 13 are not as expected. >> >> I wonder if anyone can see what I am doing wrong? >> >> Appreciate any hints. thanks, srini >> > I don't understand why you're using the .strip method. That's for > stripping whitespace from text, but you're not sending and receiving > text, you're sending and receiving binary data. And indeed, ASCII characters 9-13 are all whitespace. The receiver appears to be stripping off the first byte of the (presumably little-endian) data and thus shifting the whole struct by a byte for those entries. From RasikaSrinivasan at gmail.com Thu May 29 19:25:40 2014 From: RasikaSrinivasan at gmail.com (RasikaSrinivasan at gmail.com) Date: Thu, 29 May 2014 16:25:40 -0700 (PDT) Subject: Binary data exchange In-Reply-To: References: Message-ID: Of course!!!! Cut and paste issue. Anyhow, i will look at the struct module. cheers, srini On Thursday, May 29, 2014 7:09:21 PM UTC-4, MRAB wrote: > On 2014-05-29 23:08, RasikaSrinivasan at gmail.com wrote: > > > friends > > > > > > I have a pair of simple python programs as follows: > > > > > > #!/usr/bin/python > > > # broadcast.py > > > import socket > > > from ctypes import * > > > import random > > > > > > class PurgeData(Structure): > > > _fields_ = [("press",c_int), ("ticks",c_int), ("volume",c_float)] > > > > > > myPort = 10756 > > > > > > sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) > > > addr = ('localhost',myPort) > > > #sock.sendto(data,addr) > > > > > > presdata = PurgeData() > > > presdata.press = 0 > > > presdata.ticks = 100 > > > > > > for msg in range(1,20): > > > presdata.press = presdata.press+1 > > > presdata.ticks = presdata.ticks+1 > > > presdata.volume = random.random() > > > sock.sendto(presdata,addr) > > > > > > #-------------------- > > > > > > #!/usr/bin/python > > > # Receiver > > > import socket > > > > > > from ctypes import * > > > > > > class PurgeData(Structure): > > > _fields_ = [("press",c_int), ("ticks",c_int), ("volume",c_float)] > > > > > > myPort = 10756 > > > > > > sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) > > > addr = ('localhost',myPort) > > > sock.bind(addr) > > > presdata=PurgeData() > > > > > > while True: > > > data,addr = sock.recvfrom(1024) > > > memmove(addressof(presdata),data.strip(),len(data.strip())) > > > print presdata.press, presdata.ticks, presdata.volume > > > > > > --------------------- > > > > > > When I tried to run this I get some bizarre results: > > > > > > > > > 1 101 0.343009024858 > > > 2 102 0.36397305131 > > > 3 103 0.495895296335 > > > 4 104 0.372055351734 > > > 5 105 0.933839201927 > > > 6 106 0.931187808514 > > > 7 107 0.876732826233 > > > 8 108 0.298638045788 > > > 1828716544 -754974720 0.183644190431 > > > 1845493760 1660944384 0.186560109258 > > > 1862270976 1056964608 0.18631502986 > > > 1879048192 1728053248 0.186902835965 > > > 1895825408 2097152000 0.18658298254 > > > 14 114 0.407857120037 > > > 15 115 0.833854913712 > > > 16 116 0.00646247947589 > > > 17 117 0.297783941031 > > > 18 118 0.58082228899 > > > 19 119 0.61717569828 > > > > > > the received data for the messages 9 thru 13 are not as expected. > > > > > > I wonder if anyone can see what I am doing wrong? > > > > > > Appreciate any hints. thanks, srini > > > > > I don't understand why you're using the .strip method. That's for > > stripping whitespace from text, but you're not sending and receiving > > text, you're sending and receiving binary data. > > > > Personally, I'd use the struct module. From breamoreboy at yahoo.co.uk Thu May 29 19:56:52 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 30 May 2014 00:56:52 +0100 Subject: Binary data exchange In-Reply-To: References: Message-ID: On 30/05/2014 00:25, RasikaSrinivasan at gmail.com wrote: > Of course!!!! Cut and paste issue. Anyhow, i will look at the struct module. cheers, srini > Please let us know how you get on, please don't top post, and please either use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From roy at panix.com Thu May 29 20:13:41 2014 From: roy at panix.com (Roy Smith) Date: Thu, 29 May 2014 20:13:41 -0400 Subject: pyflakes best practices? Message-ID: We've recently started using pyflakes. The results seem to be similar to most tools of this genre. It found a few real problems. It generated a lot of noise about things which weren't really wrong, but were easy to fix (mostly, unused imports), and a few plain old false positives which have no easy "fix" (in the sense of, things I can change which will make pyflakes STFU). So, what's the best practice here? How do people deal with the false positives? Is there some way to annotate the source code to tell pyflakes to ignore something? From rosuav at gmail.com Thu May 29 20:26:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 10:26:18 +1000 Subject: Forking PyPI package In-Reply-To: References: <1fgpxn70wxrg0.1rv21r79ohz7z$.dlg@40tude.net> Message-ID: On Fri, May 30, 2014 at 7:54 AM, Ian Kelly wrote: > On Thu, May 29, 2014 at 1:40 AM, Chris Angelico wrote: >> If you absolutely can't get in touch with him, the only option is to >> go back to the original protocol and manually reimplement it, >> completely ignoring this code. It's sad but true; some code dies >> because of a trivial thing like "Oops, I forgot to actually say that >> this is MIT-licensed". > > The second part of that is that the code should actually *include* the > license text. Just writing "BSD license" somewhere on the website or > in package metadata is annoyingly common but somewhat questionable in > how a judge might interpret it. For instance, there at least four > different versions of the BSD license; which one did you mean? Agreed. I tend to have a file called README or LICENSE in the main source code directory that has license terms (in the case of a README, the license will follow whatever else there is to say); that's generally clear enough, without having to put a header on every single source file. I like to put both a short name and the full license text in there (see eg https://github.com/Rosuav/Yosemite for which I use the MIT license), so it's independent of random web sites - having nothing but a link to the license text makes it that bit more vulnerable. ChrisA From steve+comp.lang.python at pearwood.info Thu May 29 20:33:08 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2014 00:33:08 GMT Subject: How to run script from interpreter? References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> Message-ID: <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 May 2014 15:26:37 -0500, Mark H Harris wrote: > I think the IDLE REPL should have a system shell mode. What say you? I don't use IDLE, so I don't really care what you do to it. But speaking generally, -1 on that. IDLE is primarily aimed at beginners, and beginners have enough trouble distinguishing the system shell separate in their heads from the Python shell, the last thing they need is something that blurs the difference. There is a power-user shell that does exactly what you want, turned up to eleven: IPython. IPython allows you to run system commands by prefixing them with ! and has an entire subsystem of user-configurable "magic" commands using % prefix. (By the way, ; won't work for a Python shell, because ;spam already is valid Python syntax: it's an empty statement followed by the statement spam, separated by a semicolon.) -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Thu May 29 20:46:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 10:46:34 +1000 Subject: How to run script from interpreter? In-Reply-To: <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 30, 2014 at 10:33 AM, Steven D'Aprano wrote: > (By the way, ; won't work for a Python shell, because ;spam already is > valid Python syntax: it's an empty statement followed by the statement > spam, separated by a semicolon.) That's not really a problem, though. It's not going to stop you from doing something actually *useful*, and the fact that the semicolon could be syntactically valid isn't going to come into it, because the REPL would swallow it anyway. But I agree that IDLE does not need a "drop to shell" mode. ChrisA From breamoreboy at yahoo.co.uk Thu May 29 20:50:39 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 30 May 2014 01:50:39 +0100 Subject: pyflakes best practices? In-Reply-To: References: Message-ID: On 30/05/2014 01:13, Roy Smith wrote: > We've recently started using pyflakes. The results seem to be similar > to most tools of this genre. It found a few real problems. It > generated a lot of noise about things which weren't really wrong, but > were easy to fix (mostly, unused imports), and a few plain old false > positives which have no easy "fix" (in the sense of, things I can change > which will make pyflakes STFU). > > So, what's the best practice here? How do people deal with the false > positives? Is there some way to annotate the source code to tell > pyflakes to ignore something? > I was under the impression that pyflakes was configurable. It it isn't I'd simply find another tool. Having said that if you don't get better answers here try gmane.comp.python.code-quality. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Thu May 29 20:52:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 10:52:24 +1000 Subject: Multi-line commands with 'python -c' Message-ID: Since lines are so critical to Python syntax, I'm a little surprised there's no majorly obvious solution to this... or maybe I'm just blind. Problem: Translate this into a shell one-liner: import os for root, dirs, files in os.walk("."): if len(dirs + files) == 1: print(root) Solution 1: SyntaxError python -c 'import os; for root, dirs, files in os.walk("."): if len(dirs + files) == 1: print(root)' You can't put a 'for' statement after an 'import' with just a semicolon. Solution 2: SyntaxError python -c 'import os\nfor root, dirs, files in os.walk("."): if len(dirs + files) == 1: print(root)' You can't put a backslash escape into your code like that! Makes no sense. Solution 3: Silence python -c 'import os' -c 'for root, dirs, files in os.walk("."): if len(dirs + files) == 1: print(root)' Haven't dug into exactly what this does, but the docs say that -c terminates the option list, so I would guess that the second -c and its arg get passed to the script. Solution 4: Rely on the shell's ability to pass newlines inside arguments $ python -c 'import os > for root, dirs, files in os.walk("."): > if len(dirs + files) == 1: print(root) > ' That works, but at that point, you aren't writing a one-liner any more. It's also fiddly to edit. Is there a better way to put multiple virtual lines into a 'python -c' command? ChrisA From roy at panix.com Thu May 29 21:14:20 2014 From: roy at panix.com (Roy Smith) Date: Thu, 29 May 2014 21:14:20 -0400 Subject: pyflakes best practices? References: Message-ID: In article , Mark Lawrence wrote: > On 30/05/2014 01:13, Roy Smith wrote: > > We've recently started using pyflakes. The results seem to be similar > > to most tools of this genre. It found a few real problems. It > > generated a lot of noise about things which weren't really wrong, but > > were easy to fix (mostly, unused imports), and a few plain old false > > positives which have no easy "fix" (in the sense of, things I can change > > which will make pyflakes STFU). > > > > So, what's the best practice here? How do people deal with the false > > positives? Is there some way to annotate the source code to tell > > pyflakes to ignore something? > > > > I was under the impression that pyflakes was configurable. It it isn't > I'd simply find another tool. Having said that if you don't get better > answers here try gmane.comp.python.code-quality. I didn't know that list existed, it looks very interesting. Thanks for the pointer! From steve+comp.lang.python at pearwood.info Thu May 29 21:49:37 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2014 01:49:37 GMT Subject: How to run script from interpreter? References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 May 2014 10:46:34 +1000, Chris Angelico wrote: > On Fri, May 30, 2014 at 10:33 AM, Steven D'Aprano > wrote: >> (By the way, ; won't work for a Python shell, because ;spam already is >> valid Python syntax: it's an empty statement followed by the statement >> spam, separated by a semicolon.) > > That's not really a problem, though. It's not going to stop you from > doing something actually *useful*, and the fact that the semicolon could > be syntactically valid isn't going to come into it, because the REPL > would swallow it anyway. The point is that *syntactically valid* Python statements should not behave differently when running inside the shell or not. I thought that ;statement was syntactically valid -- but I was wrong. The vanilla CPython interactive interpreter gives a syntax error, as do IronPython and Jython. I misinterpreted what I saw in IPython -- it's already doing magic at the command line: In [4]: len [] ------> len([]) Out[4]: 0 In [5]: ;len [] ------> len("[]") Out[5]: 2 -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Thu May 29 22:04:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 12:04:27 +1000 Subject: How to run script from interpreter? In-Reply-To: <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 30, 2014 at 11:49 AM, Steven D'Aprano wrote: > On Fri, 30 May 2014 10:46:34 +1000, Chris Angelico wrote: > >> On Fri, May 30, 2014 at 10:33 AM, Steven D'Aprano >> wrote: >>> (By the way, ; won't work for a Python shell, because ;spam already is >>> valid Python syntax: it's an empty statement followed by the statement >>> spam, separated by a semicolon.) >> >> That's not really a problem, though. It's not going to stop you from >> doing something actually *useful*, and the fact that the semicolon could >> be syntactically valid isn't going to come into it, because the REPL >> would swallow it anyway. > > The point is that *syntactically valid* Python statements should not > behave differently when running inside the shell or not. I thought > that ;statement was syntactically valid -- but I was wrong. The vanilla > CPython interactive interpreter gives a syntax error, as do IronPython > and Jython. Huh. I responded to your post on the unchecked assumption that ";spam" was syntactically valid. I'm still of the opinion that technically valid (but not useful) constructs are allowed to be swallowed by an interactive interpreter; for instance, it's perfectly valid to write this: >>> x = (1 . imag) But quite a few interpreters (though not Python) take a dot on its own line to mean "flush the buffer, cancel my current command". I couldn't find a way to do this in Python, but if someone proposed adding it, the fact that the above is syntactically legal shouldn't be a proposal blocker. It's on par with creating a file with a name beginning with a hyphen, and then fiddling around with various commands as you try to manipulate it (tip: "rm ./-r" works); programs will happily interpret "-r" as an option rather than a file name, without being concerned that it's technically legal. ChrisA From izecksohn at yahoo.com Thu May 29 17:21:55 2014 From: izecksohn at yahoo.com (Pedro Izecksohn) Date: Thu, 29 May 2014 14:21:55 -0700 (PDT) Subject: Proposal of an API to deal with fingerprints on Python Message-ID: <1401398515.60590.YahooMailNeo@web140106.mail.bf1.yahoo.com> ? Today I wrote the following API. It was not implemented on C yet. Do you have any comment? Could you help me to implement it? http://www.izecksohn.com/pedro/python/fingerprint/fingerprint.001.py From zachary.ware+pylist at gmail.com Thu May 29 22:34:59 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 29 May 2014 21:34:59 -0500 Subject: Multi-line commands with 'python -c' In-Reply-To: References: Message-ID: On Thursday, May 29, 2014, Chris Angelico > wrote: > Since lines are so critical to Python syntax, I'm a little surprised > there's no majorly obvious solution to this... or maybe I'm just > blind. > > Problem: Translate this into a shell one-liner: > > import os > for root, dirs, files in os.walk("."): > if len(dirs + files) == 1: print(root) > > Is there a better way to put multiple virtual lines into a 'python -c' > command? > You can always cheat: $ python -c 'exec("import os\nfor root, dirs, files in os.walk(\".\"):\n if len(dirs + files) == 1: print(root)")' Doesn't do much for being long and fiddly, though. -- Zach Sent from an iPad, please bear with any brevity, uncaught auto-uncorrections, HTML, or other annoyances. Suggestions for a great (not just 'good') email app are welcome. -- Sent from Gmail Mobile -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 29 22:44:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 12:44:34 +1000 Subject: Proposal of an API to deal with fingerprints on Python In-Reply-To: <1401398515.60590.YahooMailNeo@web140106.mail.bf1.yahoo.com> References: <1401398515.60590.YahooMailNeo@web140106.mail.bf1.yahoo.com> Message-ID: On Fri, May 30, 2014 at 7:21 AM, Pedro Izecksohn wrote: > Today I wrote the following API. It was not implemented on C yet. Do you have any comment? Could you help me to implement it? > > http://www.izecksohn.com/pedro/python/fingerprint/fingerprint.001.py If that's a proof-of-concept for just the function names and things, then what I'd say is: Follow PEP 8, especially if (as your license comment suggests) you're hoping for it to be included in the Python standard library. Notably, use underscore_separated_names rather than mixedCase for function names. If that's meant to be actual usable (if stubby) code, then PEP 8 is even more important; for instance, "if (None == fpdev):" should be "if fpdev is None:". Also, your bare excepts are nasty code smell. My recommendation: Look into Cython. You're basically wrapping a C library, so you should be able to let Cython do the heavy lifting, and then maybe just add a few convenience functions in pure Python. There won't be much work, that way! Regarding licensing, by the way, I would advise decoupling yourself from the CPython standard library, which has a bit of a mess of licensing and ownership due to its long history. Pick one of the well-known open source licenses, like MIT, GPL2/GPL3, or MPL, and use that. Post your code on some place like github or bitbucket, link to it from PyPI, and let your project stand alone as a third-party installable package - if it's good, people will use it, and they can find it using pip or equivalent. ChrisA From rosuav at gmail.com Thu May 29 22:47:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 12:47:54 +1000 Subject: Multi-line commands with 'python -c' In-Reply-To: References: Message-ID: On Fri, May 30, 2014 at 12:34 PM, Zachary Ware wrote: > You can always cheat: > > $ python -c 'exec("import os\nfor root, dirs, files in os.walk(\".\"):\n if > len(dirs + files) == 1: print(root)")' > > Doesn't do much for being long and fiddly, though. Not really, no! Heh. I wrote that in competition against a theoretical solution involving shell commands and pipes and so on, with the intention being that the Python version could be a simple shell one-liner, just as the pipe version could. (The task: Find all directories with exactly one subdirectory or file in them, not counting dot and dot-dot. Python's os.walk() is pretty much perfect for that.) I tried fiddling with __import__() rather than the import statement, but it didn't really aid clarity much. ChrisA From pwnappleios6 at icloud.com Thu May 29 23:12:00 2014 From: pwnappleios6 at icloud.com (Abdullah Indorewala) Date: Thu, 29 May 2014 23:12:00 -0400 Subject: PythonCE successfully inst'ed, but scripts don't work. Please help. Message-ID: Hi, I know you posted this 15 years ago but I recently stumbled across your post here : https://mail.python.org/pipermail/python-list/1999-May/018340.html And I am in the same situation (kind of). I can?t get Python to install on my MobilePro 770 running Windows CE 3.0. Are you still available? Is this e-mail even valid? I know I?m just some random person on the internet but I need your help in installing Python to my MobilePro 770. Any help would be appreciated. Thanks. From ch2009 at arcor.de Thu May 29 22:47:10 2014 From: ch2009 at arcor.de (Chris) Date: Fri, 30 May 2014 04:47:10 +0200 Subject: Script suddenly stops Message-ID: <5387F12E.101@arcor.de> Dear All, I'm trying to read ten 200 MB textfiles into a MySQL MyISAM database (Linux, ext4). The script output is suddenly stopping, while the Python process is still running (or should I say sleeping?). It's not in top, but in ps visible. Why is it stopping? Is there a way to make it continue, without calling "kill -9", deleting the processed lines and starting it again? Thank you in advance. [1] http://pastebin.com/CxHCA9eB -- Christian From rustompmody at gmail.com Fri May 30 02:04:36 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 29 May 2014 23:04:36 -0700 (PDT) Subject: Multi-line commands with 'python -c' In-Reply-To: References: Message-ID: <25135194-b9cb-4942-bead-c1bdf72923ee@googlegroups.com> On Friday, May 30, 2014 6:22:24 AM UTC+5:30, Chris Angelico wrote: > Since lines are so critical to Python syntax, I'm a little surprised > there's no majorly obvious solution to this... or maybe I'm just > blind. > Problem: Translate this into a shell one-liner: > import os > for root, dirs, files in os.walk("."): > if len(dirs + files) == 1: print(root) I would have thought this would work: python -m os -c 'for root, dirs, files in os.walk("."): if len(dirs + files) == 1: print(root)' Unfortunately doesn't But did show up a small doc-bug: This fact is not documented in $ man python but is documented in $ python -h Anyways... I thought when one signs up for python one has to sign an affidavit saying: "I shall not write one-liners\n" * 100 From steve+comp.lang.python at pearwood.info Fri May 30 02:20:47 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2014 06:20:47 GMT Subject: How to run script from interpreter? References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5388233e$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 May 2014 12:04:27 +1000, Chris Angelico wrote: > On Fri, May 30, 2014 at 11:49 AM, Steven D'Aprano > wrote: >> On Fri, 30 May 2014 10:46:34 +1000, Chris Angelico wrote: >> >>> On Fri, May 30, 2014 at 10:33 AM, Steven D'Aprano >>> wrote: >>>> (By the way, ; won't work for a Python shell, because ;spam already >>>> is valid Python syntax: it's an empty statement followed by the >>>> statement spam, separated by a semicolon.) >>> >>> That's not really a problem, though. It's not going to stop you from >>> doing something actually *useful*, and the fact that the semicolon >>> could be syntactically valid isn't going to come into it, because the >>> REPL would swallow it anyway. >> >> The point is that *syntactically valid* Python statements should not >> behave differently when running inside the shell or not. I thought that >> ;statement was syntactically valid -- but I was wrong. The vanilla >> CPython interactive interpreter gives a syntax error, as do IronPython >> and Jython. > > Huh. I responded to your post on the unchecked assumption that ";spam" > was syntactically valid. I'm still of the opinion that technically valid > (but not useful) constructs are allowed to be swallowed by an > interactive interpreter; Heavens no. If it's legal in a script when running non-interactively, it should be legal when running interactively. I give a grudging exception to things like the REPL ending a function definition at the first empty line, even though it breaks copy-and-paste of working code: py> def example(): ... do_this() ... py> do_that() File "", line 1 do_that() ^ IndentationError: unexpected indent That's a *serious* PITA when copying (say) classes into the interactive interpreter, because you have to delete all the blank lines (or stick comments # in them) before pasting. But I can't see any practical alternative. > for instance, it's perfectly valid to write > this: > >>>> x = (1 > . > imag) Absolutely it is valid Python code, so your REPL better accept it as valid Python code. > But quite a few interpreters (though not Python) take a dot on its own > line to mean "flush the buffer, cancel my current command". I've never come across that. I'm very glad I haven't. Who came up with that broken interface? > I couldn't > find a way to do this in Python, but if someone proposed adding it, the > fact that the above is syntactically legal shouldn't be a proposal > blocker. Damn straight it ought to. If I proposed making: x = (1 + y) do something other than set x to 1+y, I would completely deserve to be dragged out into the street and beaten with halibuts. Replace the + with a dot, and there is no difference at all. If you want to kill the current buffer, just hit Ctrl-C like you're meant to. > It's on par with creating a file with a name beginning with a > hyphen, and then fiddling around with various commands as you try to > manipulate it (tip: "rm ./-r" works); programs will happily interpret > "-r" as an option rather than a file name, without being concerned that > it's technically legal. I don't see any connection between the two. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Fri May 30 02:45:46 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 29 May 2014 23:45:46 -0700 (PDT) Subject: Multi-line commands with 'python -c' In-Reply-To: <25135194-b9cb-4942-bead-c1bdf72923ee@googlegroups.com> References: <25135194-b9cb-4942-bead-c1bdf72923ee@googlegroups.com> Message-ID: On Friday, May 30, 2014 11:34:36 AM UTC+5:30, Rustom Mody wrote: > On Friday, May 30, 2014 6:22:24 AM UTC+5:30, Chris Angelico wrote: > > Since lines are so critical to Python syntax, I'm a little surprised > > there's no majorly obvious solution to this... or maybe I'm just > > blind. > > Problem: Translate this into a shell one-liner: > > import os > > for root, dirs, files in os.walk("."): > > if len(dirs + files) == 1: print(root) Heres a (poooor) approx $ python -c 'import os, pprint; pprint.pprint ([ r for r, d, f in os.walk(".") if len(d+f) != 1])' Mysterious that print after a ; is fine whereas for is not > Anyways... > I thought when one signs up for python one has to sign an affidavit > saying: > "I shall not write one-liners\n" * 100 I hope youve signed it by now From rustompmody at gmail.com Fri May 30 02:54:15 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 29 May 2014 23:54:15 -0700 (PDT) Subject: Multi-line commands with 'python -c' In-Reply-To: References: <25135194-b9cb-4942-bead-c1bdf72923ee@googlegroups.com> Message-ID: <1243054d-84af-46d5-ae7e-5882f35c0b69@googlegroups.com> On Friday, May 30, 2014 12:15:46 PM UTC+5:30, Rustom Mody wrote: > Heres a (poooor) approx > > $ python -c 'import os, pprint; pprint.pprint ([ r for r, d, f in os.walk(".") if len(d+f) != 1])' Without pprint: (pooor) python -c 'import os; print "\n".join([ r for r, d, f in os.walk(".") if len(d+f) != 1])' Or (poor) python -c 'from os import walk; print "\n".join([ r for r, d, f in walk(".") if len(d+f) != 1])' From dieter at handshake.de Fri May 30 03:04:17 2014 From: dieter at handshake.de (dieter) Date: Fri, 30 May 2014 09:04:17 +0200 Subject: Script suddenly stops References: <5387F12E.101@arcor.de> Message-ID: <871tvbbvda.fsf@handshake.de> Chris writes: > I'm trying to read ten 200 MB textfiles into a MySQL MyISAM database > (Linux, ext4). The script output is suddenly stopping, while the Python > process is still running (or should I say sleeping?). It's not in top, > but in ps visible. > > Why is it stopping? Is there a way to make it continue, without calling > "kill -9", deleting the processed lines and starting it again? This is difficult to say (from the distance). I would approach an analysis in the following way: * use a Python with debug symbols (OS provided Python installations usually lack debugging symbols; a manually generated Python usually has those symbols) * run your script unter "gdb" control (the C level debugger) * when you see that your script starts "sleeping", hit "CTRL-C" in the "gdb" session * use "gdb" commands - maybe combined with the special python commands for "gdb" to learn where the "sleeping" happens. These special Python commands allow you to use the C level debugger "gdb" to get information about the Python level. From rosuav at gmail.com Fri May 30 03:19:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 17:19:00 +1000 Subject: How to run script from interpreter? In-Reply-To: <5388233e$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> <5388233e$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 30, 2014 at 4:20 PM, Steven D'Aprano wrote: >> It's on par with creating a file with a name beginning with a >> hyphen, and then fiddling around with various commands as you try to >> manipulate it (tip: "rm ./-r" works); programs will happily interpret >> "-r" as an option rather than a file name, without being concerned that >> it's technically legal. > > I don't see any connection between the two. -r is a valid file name, just as . is a valid line of input. But with the rm command, you can't provide it with -r as a file name - you have to use ./-r or somesuch, because the parser gets to it first. That's the connection. ChrisA From rosuav at gmail.com Fri May 30 03:20:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 17:20:31 +1000 Subject: Multi-line commands with 'python -c' In-Reply-To: <25135194-b9cb-4942-bead-c1bdf72923ee@googlegroups.com> References: <25135194-b9cb-4942-bead-c1bdf72923ee@googlegroups.com> Message-ID: On Fri, May 30, 2014 at 4:04 PM, Rustom Mody wrote: > I thought when one signs up for python one has to sign an affidavit > saying: > "I shall not write one-liners\n" * 100 Certainly not. I write all my list comps on one line! *ducking for cover* ChrisA From anddamNOALPASTICCIODICARNE+gruppi at brapi.net Fri May 30 03:21:52 2014 From: anddamNOALPASTICCIODICARNE+gruppi at brapi.net (Andrea D'Amore) Date: Fri, 30 May 2014 09:21:52 +0200 Subject: IDE for python References: Message-ID: On 2014-05-29 22:40:36 +0000, Travis Griggs said: > I use either vim or textwrangler for simple one file scripts. Since you're on OS X have a look at Exedore, it's paid but very cheap. It aims at providing a beautiful interface, I fetched the free trial a couple days ago and the job so far is impressively neat. I'm not related to the project, I just found it by accident and want to give Cocoa-credit where credit is due. -- Andrea From __peter__ at web.de Fri May 30 03:26:57 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 May 2014 09:26:57 +0200 Subject: Script suddenly stops References: <5387F12E.101@arcor.de> Message-ID: Chris wrote: > Dear All, > > I'm trying to read ten 200 MB textfiles into a MySQL MyISAM database > (Linux, ext4). The script output is suddenly stopping, while the Python > process is still running (or should I say sleeping?). It's not in top, > but in ps visible. > > Why is it stopping? Is there a way to make it continue, without calling > "kill -9", deleting the processed lines and starting it again? > > Thank you in advance. > > > > [1] http://pastebin.com/CxHCA9eB > > #!/usr/bin/python > > import MySQLdb, pprint, re > db = None > daten = "/home/chris/temp/data/data/" > host = "localhost" > user = "data" > passwd = "data" > database = "data" > table = "data" > > def connect_mysql(): > global db, host, user, passwd, database > db = MySQLdb.connect(host, user, passwd, database) > return(db) > > > def read_file(srcfile): > lines = [] > f = open(srcfile, 'r') > while True: > line = f.readline() > #print line > lines.append(line) > if len(line) == 0: > break > return(lines) The read_file() function looks suspicious. It uses a round-about way to read the whole file into memory. Maybe your system is just swapping? Throw read_file() away and instead iterate over the file directly (see below). > def write_db(anonid, query, querytime, itemrank, clickurl): > global db, table > print "write_db aufgerufen." > cur = db.cursor() > try: > cur.execute("""INSERT INTO data (anonid,query,querytime,itemrank,clickurl) VALUES (%s,%s,%s,%s,%s)""", (anonid,query,querytime,itemrank,clickurl)) > db.commit() > except: > db.rollback() > > > def split_line(line): > print "split_line called." > print "line is:", line > searchObj = re.split(r'(\d*)\t(.*)\t([0-9: -]+)\t(\d*)\t([A-Za- z0-9._:/ -]*)',line, re.I|re.U) > return(searchObj) > > > > db = connect_mysql() > pprint.pprint(db) with open(daten + "test-07b.txt") as lines: for line in lines: result = split_line(line) write_db(result[1], result[2], result[3], result[4], result[5]) > db.close() Random remarks: - A bare except is evil. You lose valuable information. - A 'global' statement is only needed to rebind a module-global variable, not to access such a variable. At first glance all your 'global' declarations seem superfluous. - You could change the signature of write_db() to accept result[1:6]. - Do you really need a new cursor for every write? Keep one around as a global. - You might try cur.executemany() to speed things up a bit. From __peter__ at web.de Fri May 30 03:33:24 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 May 2014 09:33:24 +0200 Subject: Multi-line commands with 'python -c' References: <25135194-b9cb-4942-bead-c1bdf72923ee@googlegroups.com> <1243054d-84af-46d5-ae7e-5882f35c0b69@googlegroups.com> Message-ID: Rustom Mody wrote: > On Friday, May 30, 2014 12:15:46 PM UTC+5:30, Rustom Mody wrote: >> Heres a (poooor) approx >> >> $ python -c 'import os, pprint; pprint.pprint ([ r for r, d, f in >> os.walk(".") if len(d+f) != 1])' > > Without pprint: (pooor) > > python -c 'import os; print "\n".join([ r for r, d, f in os.walk(".") if > len(d+f) != 1])' > > Or (poor) > > python -c 'from os import walk; print "\n".join([ r for r, d, f in > walk(".") if len(d+f) != 1])' If there are a lot of matching folders: $ python -c 'import os, sys; sys.stdout.writelines(p + "\n" for p, f, n in os.walk(".") if len(n+f) == 1)' With a little help from the shell: $ echo -e "import os\nfor p, f, n in os.walk('.'):\n if len(f+n) == 1: print(p)" | python From rosuav at gmail.com Fri May 30 03:51:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 17:51:11 +1000 Subject: PythonCE successfully inst'ed, but scripts don't work. Please help. In-Reply-To: References: Message-ID: On Fri, May 30, 2014 at 1:12 PM, Abdullah Indorewala wrote: > Hi, > > I know you posted this 15 years ago but I recently stumbled across your post here : > > https://mail.python.org/pipermail/python-list/1999-May/018340.html > > And I am in the same situation (kind of). I can?t get Python to install on my MobilePro 770 running Windows CE 3.0. Are you still available? Is this e-mail even valid? I know I?m just some random person on the internet but I need your help in installing Python to my MobilePro 770. Any help would be appreciated. > Well... you've reached a valid and current mailing list (mirrored to the comp.lang.python newsgroup), and there's plenty of activity here. But I don't know if anyone here uses WinCE, nor if anyone has the exact version of hardware you're using. So it's probably easiest to just set the previous post aside and start fresh, with details like: 1) What version of Python are you trying to install? 2) What version of Windows? (You already answered that, above; according to Wikipedia, the MobilePro 770 came with WinCE 2.11, so I'm guessing that's been upgraded.) 3) What happens when you try to install? I don't think Win CE is an officially-supported platform, so it's entirely possible you'll have problems with the standard installers. There is, however, a dedicated third-party port at http://pythonce.sourceforge.net/ , which I found by simple Google search for 'python wince'. That might help you, and if not, come back with more info and maybe someone can help out. Good luck! I'm pretty sure "WinCE" is appropriately named after the facial sign of distress. ChrisA From lakshmipathi.g at gmail.com Fri May 30 04:45:16 2014 From: lakshmipathi.g at gmail.com (Lakshmipathi.G) Date: Fri, 30 May 2014 14:15:16 +0530 Subject: how avoid delay while returning from C-python api? In-Reply-To: References: Message-ID: Yes, Cython looks easier but the problem its a very old code ( 6 or 7 years ). Almost entire code base uses plain python-c api. Thanks for the example, will use Cython or Ctypes way for side-projects! ---- Cheers, Lakshmipathi.G FOSS Programmer. www.giis.co.in/readme.html From anddamNOALPASTICCIODICARNE+gruppi at brapi.net Fri May 30 05:04:28 2014 From: anddamNOALPASTICCIODICARNE+gruppi at brapi.net (Andrea D'Amore) Date: Fri, 30 May 2014 11:04:28 +0200 Subject: IDE for python References: Message-ID: On 2014-05-30 07:21:52 +0000, Andrea D'Amore said: > It aims at providing a beautiful interface, Side note: the text editing is still green. -- Andrea From steve+comp.lang.python at pearwood.info Fri May 30 07:27:26 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2014 11:27:26 GMT Subject: How to run script from interpreter? References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> <5388233e$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53886b1e$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 May 2014 17:19:00 +1000, Chris Angelico wrote: > On Fri, May 30, 2014 at 4:20 PM, Steven D'Aprano > wrote: >>> It's on par with creating a file with a name beginning with a hyphen, >>> and then fiddling around with various commands as you try to >>> manipulate it (tip: "rm ./-r" works); programs will happily interpret >>> "-r" as an option rather than a file name, without being concerned >>> that it's technically legal. >> >> I don't see any connection between the two. > > -r is a valid file name, just as . is a valid line of input. But with > the rm command, you can't provide it with -r as a file name - you have > to use ./-r or somesuch, because the parser gets to it first. That's the > connection. The analogy doesn't quite match, because rm, like all shell commands, does it's own argument parsing, whereas Python operators do not. But putting that aside, the parser's rule is "arguments starting with a dash are treated as options". That's *standard behaviour*. If you want to override that standard behaviour, you have to tweak the command: rm -f ./-r /tmp/* Some commands accept a single dash to mean "no more options following this". Assuming rm does the same: rm -f - -r /tmp/* Either way, it is the standard behaviour as defined by rm, and so expected. That makes this the equivalent of Python's rule that dot behaves somewhat like an operator, and that a dot on its own is legal any place a bare binary operator is legal. The analogy to "the REPL is allowed to modify standard syntax to make a bare dot special" would be something like: the shell is allowed to pre-process the command line, so that -r on a line on its own like this: rm -f \ -r \ /tmp/* which otherwise would have been treated as `rm -f -r /tmp/*`, is instead turned into `rm -f ./-r /tmp/*`. Reading the rm man page won't tell you this, because it happens outside of rm, just as reading the Python documentation won't tell you about the tricks your hypothetical REPL does to otherwise legal syntax. rm doesn't know what tricks your hypothetical shell might do, and neither can the Python parser tell what tricks your hypothetical REPL might do. Both see only what the shell give them. This is why I'm so adamant that, while REPLs may be permitted to introduce *new* syntax which is otherwise illegal to the Python parser, (e.g. like IPython's %magic and !shell commands) they *must not* change the meaning of otherwise legal Python syntax. It's simply a bad idea to have legal Python code mean different things depending on what environment you're running it in. (As I mentioned before, the annoying "blank line closes all open blocks" rule gets an exception simply because I don't believe there is any practical alternative.) -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri May 30 07:46:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 21:46:55 +1000 Subject: How to run script from interpreter? In-Reply-To: <53886b1e$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> <5388233e$0$29978$c3e8da3$5496439d@news.astraweb.com> <53886b1e$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 30, 2014 at 9:27 PM, Steven D'Aprano wrote: > This is why I'm so adamant that, while REPLs may be permitted to > introduce *new* syntax which is otherwise illegal to the Python parser, > (e.g. like IPython's %magic and !shell commands) they *must not* change > the meaning of otherwise legal Python syntax. It's simply a bad idea to > have legal Python code mean different things depending on what > environment you're running it in. Hmm. I'm not sure that "raises SyntaxError" is any less a part of the language's promise than "evaluates to twice the value of x" is. Would you, for instance, permit the REPL to define a new __future__ directive, on the basis that it's invalid syntax currently? >>> from __future__ import magic_command_history SyntaxError: future feature magic_command_history is not defined I don't think SyntaxError equates to "invitation to make changes". Also, consider: >>> for i in range(5): i*3+2 2 5 8 11 14 If you do this in a script, it's perfectly legal, but won't print anything. So the REPL is already "chang[ing] the meaning of otherwise legal Python syntax", and what's more, it's making None into a special case: >>> for i in range(5): None if i%2 else i 0 2 4 Practicality beats purity. If it's more useful to the end user for something valid-but-illogical to have a new bit of meaning in interactive mode, I say go for it. ChrisA From alister.nospam.ware at ntlworld.com Fri May 30 08:23:27 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 30 May 2014 12:23:27 GMT Subject: IDE for python References: <8761kozg98.fsf@rudin.co.uk> Message-ID: <3L_hv.150228$CE7.56749@fx17.am4> On Thu, 29 May 2014 15:11:31 -0500, Mark H Harris wrote: > On 5/29/14 11:44 AM, Paul Rudin wrote: >> Terry Reedy writes: >>> I am curious how many of the editors people have been recommending >>> have all of the following Idle features, that I use constantly. >>> >>> 1. Run code in the editor with a single keypress. >>> >>> 2. Display output and traceback in a window that lets you jump from >>> the any line in the traceback to the corresponding file and line, >>> opening the file if necessary. >>> >>> 3. Search unopened files (grep) for a string or re. >>> >>> 4. Display grep output in a window that lets you jump from any 'hit' >>> to the corresponding file and line, opening the file if necessary. >> >> Emacs. >> >> > Emacs is the coolest tech editor out there, by far; however, the very > nature of Emacs (which makes it the coolest) is also unfortunately the > very thing that sucks about it... highly configurable (&extensible), > highly complex, intricately complicated; especially for novices. > > The OP is looking for an "IDE-like" interactive environment, because he > is "uncomfortable" with IDLE. IDLE is THE choice, however ---precisely > because IDLE is clean, elegant, and most importantly "simple". It is > simple to understand, and it is even simpler to use effectively... even > for novice pythonics. IDLE is straight-forward. > > As Terry pointed out, IDLE is very useful and functional. And in the > modern python world is also very stable (IDLE used to get a black eye > because it had snags early-on). Today IDLE works, has great features, > and actually helps new users get on-board with Python. > > marcus The only thing missing form emacs is a good text editor ;-) -- Chemist who falls in acid will be tripping for weeks. From rustompmody at gmail.com Fri May 30 08:47:25 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 30 May 2014 05:47:25 -0700 (PDT) Subject: Multi-line commands with 'python -c' In-Reply-To: References: <25135194-b9cb-4942-bead-c1bdf72923ee@googlegroups.com> Message-ID: On Friday, May 30, 2014 12:50:31 PM UTC+5:30, Chris Angelico wrote: > On Fri, May 30, 2014 at 4:04 PM, Rustom Mody wrote: > > I thought when one signs up for python one has to sign an affidavit > > saying: > > "I shall not write one-liners\n" * 100 > Certainly not. I write all my list comps on one line! > *ducking for cover* Heres a more vile misuse of python3's print-as-function + list-comp-as-for: python3 -c 'from os import walk; [print(r) for r, d, f in walk(".") if len(d+f) == 1]' Well if C programmers can use ',' as one-line ';' and '?:' as one-line if why not python also? [To noobs who are reading: Dont do this!] From rustompmody at gmail.com Fri May 30 08:53:06 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 30 May 2014 05:53:06 -0700 (PDT) Subject: IDE for python In-Reply-To: <8761kozg98.fsf@rudin.co.uk> References: <8761kozg98.fsf@rudin.co.uk> Message-ID: <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> On Thursday, May 29, 2014 10:14:35 PM UTC+5:30, Paul Rudin wrote: > Terry Reedy writes: > > 3. Search unopened files (grep) for a string or re. > Emacs. How do you do this with emacs? I find a menagerie of greppish commands -- rgrep, lgrep, grep-find etc From rosuav at gmail.com Fri May 30 08:58:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 May 2014 22:58:18 +1000 Subject: Multi-line commands with 'python -c' In-Reply-To: References: <25135194-b9cb-4942-bead-c1bdf72923ee@googlegroups.com> Message-ID: On Fri, May 30, 2014 at 10:47 PM, Rustom Mody wrote: > On Friday, May 30, 2014 12:50:31 PM UTC+5:30, Chris Angelico wrote: >> On Fri, May 30, 2014 at 4:04 PM, Rustom Mody wrote: >> > I thought when one signs up for python one has to sign an affidavit >> > saying: >> > "I shall not write one-liners\n" * 100 > >> Certainly not. I write all my list comps on one line! > >> *ducking for cover* > > Heres a more vile misuse of python3's print-as-function + list-comp-as-for: > > python3 -c 'from os import walk; [print(r) for r, d, f in walk(".") if len(d+f) == 1]' > > Well if C programmers can use ',' as one-line ';' and '?:' as one-line if > why not python also? > > [To noobs who are reading: Dont do this!] I actually crafted the exact same vile misuse, prior to asking the question. https://lists.debian.org/debian-user/2014/05/msg02019.html Modulo trivialities like whitespace and the from-import, it's exactly the same as your version. Incidentally, C's ?: operator maps to Python's ternary if/else operator, which most definitely is valid in a one-liner. So it's just the semicolon that you're looking at. In C, you can combine any two statements onto one line; in Python, certain statements may not follow a semicolon. So it's not really ; and ?: that are the point here, but that Python, with its stricter rules about newlines (as opposed to "any whitespace"), doesn't seem to have a convenient notation for putting multiple lines into a -c command. ChrisA From marko at pacujo.net Fri May 30 09:54:10 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 30 May 2014 16:54:10 +0300 Subject: IDE for python References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> Message-ID: <878upjwewt.fsf@elektro.pacujo.net> Rustom Mody : >> > 3. Search unopened files (grep) for a string or re. > > How do you do this with emacs? > I find a menagerie of greppish commands -- rgrep, lgrep, grep-find etc To grep for a pattern in the directory of the active buffer: M-x grep Run grep (like this): grep -nH -e Complete the grep command: Run grep (like this): grep -nH -e class *.py and hit ENTER. Feel free to modify the command from grep to egrep, for example. I often replace -e with -i. To grep for a pattern in any subdirectory: M-x grep Run grep (like this): grep -nH -r assert . or: M-x grep-find Run find (like this): find . -type f -exec grep -nH -e assert {} + Again, you can modify the command freely: M-x grep-find Run find (like this): find . -name '*.py' -exec grep -nH -e assert {} + You will get a list of hits in a new buffer. You can use the C-x ` command to traverse them in order, but there are many other ways. Marko From rustompmody at gmail.com Fri May 30 10:04:18 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 30 May 2014 07:04:18 -0700 (PDT) Subject: IDE for python In-Reply-To: <878upjwewt.fsf@elektro.pacujo.net> References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> Message-ID: On Friday, May 30, 2014 7:24:10 PM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody wrote: > > > >> > 3. Search unopened files (grep) for a string or re. > > > > How do you do this with emacs? > > I find a menagerie of greppish commands -- rgrep, lgrep, grep-find etc > > > > To grep for a pattern in the directory of the active buffer: > > > M-x grep > Run grep (like this): grep -nH -e Well... lgrep is cleverer than grep (in a stupid sort of way :D ) Was just wondering if there were some other tricks From ganesh1pal at gmail.com Fri May 30 10:18:17 2014 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 30 May 2014 19:48:17 +0530 Subject: Optparse to parsing Suggestions !! Message-ID: Hello Python world , I wanted suggestion on how to modify the below code to help me accomodate the below two cases # Here is the Sample code. def main(): """ ---MAIN--- """ parser = optparse.OptionParser(usage='%prog [options] .]', version='1.0') object_choice = ('super_block','blocks''files', 'directory','links') parser.add_option("-o", "--object", action="store",metavar="object",default='inode',dest="object",type='choice', choices=object_choice, help='The object type to be corrupted [ choose from (' + ','.join(object_choice) + ') default: %default]',) parser.add_option("-p", "--path",action="store",metavar="/mnt/",dest="path",type="string",help="The file or directory path in /mnt/",) parser.add_option("-n", "--size",action="store",metavar="size",dest="size",default=1,type='int',help="The offset field) # Instruct optparse to parse the program's command line: (options, args) = parser.parse_args() # Build the dispatch table: object_type_dictionary = { "super_block":super_block_def, "blocks":blocks_def, "files": files_corrupt_def, "directory": directory_corrupt_def, "links": links_corrput_def, # no () here,we're storing function } # Lookup the object type and then call the function: object_type_dictionary[options.object]() Sample Run # python corrupt.py --object=files --path=/tmp/ --size 1000 Questions : Case 1: # The --path is optional for few for the object type. How do I simulate the below behaviour #python corrupt.py --object=super_block --size=1000 ==> Should work even if --path is not given #python corrupt.py --object=super_block --path=/tmp/--size 1000 ==> If user enters --object=super_block and --path=/ifs/ should throw an error saying its an invaild combinations. case 2: # The --path is mandatory for few of the object types and should complain if its not entered . # python corrupt.py --object=files --path=/tmp/ --size 1000 Regards, Ganesh -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Fri May 30 11:06:54 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 30 May 2014 08:06:54 -0700 (PDT) Subject: IDE for python In-Reply-To: References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> Message-ID: Le vendredi 30 mai 2014 16:04:18 UTC+2, Rustom Mody a ?crit?: > On Friday, May 30, 2014 7:24:10 PM UTC+5:30, Marko Rauhamaa wrote: > > > Rustom Mody wrote: > > > > > > > > > >> > 3. Search unopened files (grep) for a string or re. > > > > > > > > How do you do this with emacs? > > > > I find a menagerie of greppish commands -- rgrep, lgrep, grep-find etc > > > > > > > > > > > > To grep for a pattern in the directory of the active buffer: > > > > > > > > > M-x grep > > > Run grep (like this): grep -nH -e > > > > Well... > > lgrep is cleverer than grep (in a stupid sort of way :D ) > > Was just wondering if there were some other tricks ======== Out of curiosity. Are you the Rusi Mody attempting to dive in Xe(La)TeX? jmf From tjreedy at udel.edu Fri May 30 11:24:11 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 May 2014 11:24:11 -0400 Subject: How to run script from interpreter? In-Reply-To: References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> <5388233e$0$29978$c3e8da3$5496439d@news.astraweb.com> <53886b1e$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/30/2014 7:46 AM, Chris Angelico wrote: > Hmm. I'm not sure that "raises SyntaxError" is any less a part of the > language's promise than "evaluates to twice the value of x" is. Of course it is. A real SyntaxError cannot be caught immediately.* When new syntax features are added, breaking the raising of a SyntaxError is *not* a consideration. On the other hand, we do not freely change AbcError to XyzError even when the latter would be more 'correct'. * IE, you cannot type >>> try: .. except SyntaxError: print('caught') because the SyntaxError during parsing rather than during execution. > Also, consider: > >>>> for i in range(5): i*3+2 > > 2 > 5 > 8 > 11 > 14 > > If you do this in a script, it's perfectly legal, but won't print > anything. So the REPL is already "chang[ing] the meaning of otherwise > legal Python syntax", It does not change what is calculated. It adds introspection output as a convenience. The minus is that one may forget that it *is* an addition and use the shortcut when writing a script. (I know I have, occasionally.) > and what's more, it's making None into a special case: Which it is, as the 'zero' of the set of Python objects. >>>> for i in range(5): None if i%2 else i > > 0 > 2 > 4 > > Practicality beats purity. If it's more useful to the end user for > something valid-but-illogical to have a new bit of meaning in > interactive mode, I say go for it. I disagree. -- Terry Jan Reedy From ganesh1pal at gmail.com Fri May 30 11:29:30 2014 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 30 May 2014 20:59:30 +0530 Subject: Optparse to parsing Suggestions !! In-Reply-To: References: Message-ID: On Fri, May 30, 2014 at 7:48 PM, Ganesh Pal wrote: > > Hello Python world , > > > I wanted suggestion on how to modify the below code to help me accomodate > the below two cases > > # Here is the Sample code. > > def main(): > """ ---MAIN--- """ > parser = optparse.OptionParser(usage='%prog [options] .]', > version='1.0') > object_choice = ('super_block','blocks''files', 'directory','links') > > parser.add_option("-o", "--object", > action="store",metavar="object",default='inode',dest="object",type='choice', > choices=object_choice, > help='The object type to be corrupted [ choose from > (' + ','.join(object_choice) + ') default: %default]',) > > parser.add_option("-p", > "--path",action="store",metavar="/mnt/",dest="path",type="string",help="The > file or directory path in /mnt/",) > > parser.add_option("-n", > "--size",action="store",metavar="size",dest="size",default=1,type='int',help="The > offset field) > > > # Instruct optparse to parse the program's command line: > (options, args) = parser.parse_args() > > # Build the dispatch table: > object_type_dictionary = { > "super_block":super_block_def, > "blocks":blocks_def, > "files": files_corrupt_def, > "directory": directory_corrupt_def, > "links": links_corrput_def, # no () here,we're storing function > } > > # Lookup the object type and then call the function: > object_type_dictionary[options.object]() > > > Sample Run > # python corrupt.py --object=files --path=/tmp/ --size 1000 > > > Questions : > > Case 1: # The --path is optional for few for the object type. How do I > simulate the below behaviour > > #python corrupt.py --object=super_block --size=1000 > > ==> Should work even if --path is not given > > #python corrupt.py --object=super_block --path=/tmp/--size 1000 > > ==> If user enters --object=super_block and --path=/ifs/ should > throw an error > > saying its an invaild combinations. > > > > case 2: # The --path is mandatory for few of the object types and should > complain if its not entered . > > # python corrupt.py --object=files --path=/tmp/ --size 1000 > > > Can these be accomplished with optparse using a callback. I was reading about this. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri May 30 11:29:44 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 May 2014 11:29:44 -0400 Subject: Multi-line commands with 'python -c' In-Reply-To: References: <25135194-b9cb-4942-bead-c1bdf72923ee@googlegroups.com> Message-ID: On 5/30/2014 2:45 AM, Rustom Mody wrote: > $ python -c 'import os, pprint; pprint.pprint ([ r for r, d, f in os.walk(".") if len(d+f) != 1])' > > Mysterious that print after a ; is fine whereas for is not Not at all. Simple statememts can follow ; or :, compound statements cannot. -- Terry Jan Reedy From tjreedy at udel.edu Fri May 30 11:46:41 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 May 2014 11:46:41 -0400 Subject: IDE for python In-Reply-To: <878upjwewt.fsf@elektro.pacujo.net> References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> Message-ID: On 5/30/2014 9:54 AM, Marko Rauhamaa wrote: > Rustom Mody : > >>>> 3. Search unopened files (grep) for a string or re. >> >> How do you do this with emacs? >> I find a menagerie of greppish commands -- rgrep, lgrep, grep-find etc > > To grep for a pattern in the directory of the active buffer: > > M-x grep > Run grep (like this): grep -nH -e > > Complete the grep command: > > Run grep (like this): grep -nH -e class *.py > > and hit ENTER. Feel free to modify the command from grep to egrep, for > example. I often replace -e with -i. > > To grep for a pattern in any subdirectory: > > M-x grep > Run grep (like this): grep -nH -r assert . > > or: > > M-x grep-find > Run find (like this): find . -type f -exec grep -nH -e assert {} + > > Again, you can modify the command freely: > > M-x grep-find > Run find (like this): find . -name '*.py' -exec grep -nH -e assert {} + Thank you for the answer. I once had things like this memorized, but now I prefer Idle's dialog, with selected text (if any) and the full path of the current directory (+/.py) pre-inserted as target and search directory, and options as radiobuttons (remembered from my last search) ... > You will get a list of hits in a new buffer. You can use the C-x ` > command to traverse them in order, but there are many other ways. and a scrollable window for results ;-). -- Terry Jan Reedy From __peter__ at web.de Fri May 30 11:53:09 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 May 2014 17:53:09 +0200 Subject: Optparse to parsing Suggestions !! References: Message-ID: Ganesh Pal wrote: > Hello Python world , > > > I wanted suggestion on how to modify the below code to help me accomodate > the below two cases > > # Here is the Sample code. > > def main(): > """ ---MAIN--- """ > parser = optparse.OptionParser(usage='%prog [options] .]', > version='1.0') > object_choice = ('super_block','blocks''files', 'directory','links') > > parser.add_option("-o", "--object", > action="store",metavar="object",default='inode',dest="object",type='choice', > choices=object_choice, > help='The object type to be corrupted [ choose from > (' > + ','.join(object_choice) + ') default: %default]',) > > parser.add_option("-p", > "-- path",action="store",metavar="/mnt/",dest="path",type="string",help="The > file or directory path in /mnt/",) > > parser.add_option("-n", > "-- size",action="store",metavar="size",dest="size",default=1,type='int',help="The > offset field) > > > # Instruct optparse to parse the program's command line: > (options, args) = parser.parse_args() > > # Build the dispatch table: > object_type_dictionary = { > "super_block":super_block_def, > "blocks":blocks_def, > "files": files_corrupt_def, > "directory": directory_corrupt_def, > "links": links_corrput_def, # no () here,we're storing function > } > > # Lookup the object type and then call the function: > object_type_dictionary[options.object]() > > > Sample Run > # python corrupt.py --object=files --path=/tmp/ --size 1000 > > > Questions : > > Case 1: # The --path is optional for few for the object type. How do I > simulate the below behaviour > > #python corrupt.py --object=super_block --size=1000 > > ==> Should work even if --path is not given > > #python corrupt.py --object=super_block --path=/tmp/--size 1000 > > ==> If user enters --object=super_block and --path=/ifs/ should > throw an error > > saying its an invaild combinations. > > > > case 2: # The --path is mandatory for few of the object types and should > complain if its not entered . > > # python corrupt.py --object=files --path=/tmp/ --size 1000 I think you have to do it manually: options, args = parser.parse_args() if options.object == "super_block" and options.path is not None: parser.error("Paths not allowed for 'super_block' object") elif options.object == "files" and options.path is None: parser.error("'files' object requires a path") From rustompmody at gmail.com Fri May 30 12:15:09 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 30 May 2014 09:15:09 -0700 (PDT) Subject: IDE for python In-Reply-To: References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> Message-ID: <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> On Friday, May 30, 2014 8:36:54 PM UTC+5:30, wxjm... at gmail.com wrote: > Out of curiosity. > Are you the Rusi Mody attempting to dive in Xe(La)TeX? Yeah :-) As my blog posts labelled unicode will indicate I am a fan of using unicode in program source: http://blog.languager.org/search/label/Unicode Of course it is not exactly a coincidence that I used APL a bit in my early days. At that time it was great fun though we did not take it seriously.* It is now about time that we stop taking ASCII seriously!! And for those who dont know xetex, its is really x?tex ? a pictorial anagram if written as X?TEX However in all fairness I should say that I cannot seem to find my way to that promised land yet: - xetex does not quite work whereas pdflatex works smoothly - mathjax is awesome however its firmly latex (not xetex) based ------------------- * And the fact that there are recent implementations including web ones means its by no means dead: http://baruchel.hd.free.fr/apps/apl/ which I think unicode aficionados will enjoy From tjreedy at udel.edu Fri May 30 12:37:21 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 May 2014 12:37:21 -0400 Subject: IDE for python In-Reply-To: <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> Message-ID: On 5/30/2014 12:15 PM, Rustom Mody wrote: > And for those who dont know xetex, its is really x?tex ? a pictorial > anagram if written as X?TEX I believe you mean 'pictorial palindrome', which it is! -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Fri May 30 12:38:04 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 30 May 2014 17:38:04 +0100 Subject: IDE for python In-Reply-To: <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> Message-ID: On 30/05/2014 17:15, Rustom Mody wrote: > On Friday, May 30, 2014 8:36:54 PM UTC+5:30, wxjm... at gmail.com wrote: > > It is now about time that we stop taking ASCII seriously!! > This can't happen in the Python world until there is a sensible approach to unicode. Ah, but wait a minute, the ball was set rolling with Python 3.0. Then came PEP 393 and the Flexible String Representation in Python 3.3 and some strings came down in size by a factor of 75% and in most cases it was faster. Just what do some people want in life, jam on it? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rustompmody at gmail.com Fri May 30 12:40:37 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 30 May 2014 09:40:37 -0700 (PDT) Subject: IDE for python In-Reply-To: References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> Message-ID: <2e7c2e32-57ed-45bf-9370-576424194c95@googlegroups.com> On Friday, May 30, 2014 10:07:21 PM UTC+5:30, Terry Reedy wrote: > On 5/30/2014 12:15 PM, Rustom Mody wrote: > > > And for those who dont know xetex, its is really x?tex ? a pictorial > > anagram if written as X?TEX > > I believe you mean 'pictorial palindrome', which it is! > Heh! Getting woozy it looks! From rustompmody at gmail.com Fri May 30 13:07:00 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 30 May 2014 10:07:00 -0700 (PDT) Subject: IDE for python In-Reply-To: References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> Message-ID: On Friday, May 30, 2014 10:08:04 PM UTC+5:30, Mark Lawrence wrote: > On 30/05/2014 17:15, Rustom Mody wrote: > > On Friday, May 30, 2014 8:36:54 PM UTC+5:30, jmf wrote: > > It is now about time that we stop taking ASCII seriously!! > This can't happen in the Python world until there is a sensible approach > to unicode. Ah, but wait a minute, the ball was set rolling with Python > 3.0. Then came PEP 393 and the Flexible String Representation in Python > 3.3 and some strings came down in size by a factor of 75% and in most > cases it was faster. Just what do some people want in life, jam on it? I dont see that these two are related? You are talking about the infrastructure needed for writing unicode apps. The language need not have non-ASCII lexemes for that I am talking about something quite different. Think for example of a German wanting to write "G?del" According to some conventions (s)he can write Goedel But if that is forced just because of ASCII/US-104/what-have-u it would justifiably cause irritation/offense. Likewise I am talking about the fact that x?y is prettier than x != y.? In earlier times the former was not an option. Today the latter is drawn from an effectively random subset of unicode only for historical reasons and not anything technologically current. ----------------------- ? Ok very very distantly related maybe in the sense that since python is a key part of modern linux system admin, and getting out of ASCII-jail needs the infrastructure to work smoothly in the wider unicode world. ? And probably 100s of other such egs, some random sample of which I have listed: http://blog.languager.org/2014/04/unicoded-python.html From wxjmfauth at gmail.com Fri May 30 13:17:33 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 30 May 2014 10:17:33 -0700 (PDT) Subject: IDE for python In-Reply-To: <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> Message-ID: Le vendredi 30 mai 2014 18:15:09 UTC+2, Rustom Mody a ?crit?: > On Friday, May 30, 2014 8:36:54 PM UTC+5:30, wxjm... at gmail.com wrote: > > > > > Out of curiosity. > > > Are you the Rusi Mody attempting to dive in Xe(La)TeX? > > > > Yeah :-) > > > > As my blog posts labelled unicode will indicate I am a fan of using > > unicode in program source: > > http://blog.languager.org/search/label/Unicode > > > > Of course it is not exactly a coincidence that I used APL a bit in my > > early days. At that time it was great fun though we did not take it > > seriously.* > > > > It is now about time that we stop taking ASCII seriously!! > > > > And for those who dont know xetex, its is really x?tex ? a pictorial > > anagram if written as X?TEX > > > > However in all fairness I should say that I cannot seem to find my > > way to that promised land yet: > > - xetex does not quite work whereas pdflatex works smoothly > > - mathjax is awesome however its firmly latex (not xetex) based > > > > ------------------- > > * And the fact that there are recent implementations including web ones means its by no means dead: > > http://baruchel.hd.free.fr/apps/apl/ > > which I think unicode aficionados will enjoy ========= Ok, thanks for the answer. "xetex does not quite work whereas pdflatex works smoothly" ? jmf From breamoreboy at yahoo.co.uk Fri May 30 13:27:52 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 30 May 2014 18:27:52 +0100 Subject: IDE for python In-Reply-To: References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> Message-ID: On 30/05/2014 18:07, Rustom Mody wrote: > On Friday, May 30, 2014 10:08:04 PM UTC+5:30, Mark Lawrence wrote: >> On 30/05/2014 17:15, Rustom Mody wrote: >>> On Friday, May 30, 2014 8:36:54 PM UTC+5:30, jmf wrote: >>> It is now about time that we stop taking ASCII seriously!! > >> This can't happen in the Python world until there is a sensible approach >> to unicode. Ah, but wait a minute, the ball was set rolling with Python >> 3.0. Then came PEP 393 and the Flexible String Representation in Python >> 3.3 and some strings came down in size by a factor of 75% and in most >> cases it was faster. Just what do some people want in life, jam on it? > > I dont see that these two are related? > > You are talking about the infrastructure needed for writing unicode apps. > The language need not have non-ASCII lexemes for that > > I am talking about something quite different. > Think for example of a German wanting to write "G?del" > According to some conventions (s)he can write Goedel > But if that is forced just because of ASCII/US-104/what-have-u it would justifiably > cause irritation/offense. > > Likewise I am talking about the fact that x?y is prettier than x != y.? > > In earlier times the former was not an option. > Today the latter is drawn from an effectively random subset of unicode > only for historical reasons and not anything technologically current. > > > ----------------------- > ? Ok very very distantly related maybe in the sense that since python is a > key part of modern linux system admin, and getting out of ASCII-jail needs > the infrastructure to work smoothly in the wider unicode world. > > ? And probably 100s of other such egs, some random sample of which I have listed: > http://blog.languager.org/2014/04/unicoded-python.html > I just happen to like fishing :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rustompmody at gmail.com Fri May 30 13:30:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 30 May 2014 10:30:27 -0700 (PDT) Subject: IDE for python In-Reply-To: References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> Message-ID: <61e732f1-e902-4769-8d96-c6a5aba3e0b1@googlegroups.com> On Friday, May 30, 2014 10:47:33 PM UTC+5:30, wxjm... at gmail.com wrote: > ========= > Ok, thanks for the answer. > "xetex does not quite work whereas pdflatex works smoothly" > ? Problem is a combination of 1. I am a somewhat clueless noob 2. xetex is emerging technology therefore changing fast and not stable So when something does not work I dont know whether: - its 1 (I am doing something silly) - Or 2 (I have actually hit a bug) I tried writing some small (hello-world) type text using unicode chars rather the old-fashioned \alpha type of locutions. It worked. Added a bunch of more latex packages from apt. It stopped working. ------------------------------ PS It would help all if you read https://wiki.python.org/moin/GoogleGroupsPython and dont double-space earlier mails. From wxjmfauth at gmail.com Fri May 30 14:43:44 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 30 May 2014 11:43:44 -0700 (PDT) Subject: IDE for python In-Reply-To: <61e732f1-e902-4769-8d96-c6a5aba3e0b1@googlegroups.com> References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> <61e732f1-e902-4769-8d96-c6a5aba3e0b1@googlegroups.com> Message-ID: <1c59b690-9f2d-4686-9937-5d570ac0ff6b@googlegroups.com> Le vendredi 30 mai 2014 19:30:27 UTC+2, Rustom Mody a ?crit?: > On Friday, May 30, 2014 10:47:33 PM UTC+5:30, wxjm... at gmail.com wrote: > > > ========= > > > > > Ok, thanks for the answer. > > > > > "xetex does not quite work whereas pdflatex works smoothly" > > > > > ? > > > > Problem is a combination of > > 1. I am a somewhat clueless noob > > 2. xetex is emerging technology therefore changing fast and not stable > > > > So when something does not work I dont know whether: > > - its 1 (I am doing something silly) > > - Or 2 (I have actually hit a bug) > > > > I tried writing some small (hello-world) type text using unicode chars rather > > the old-fashioned \alpha type of locutions. It worked. > > Added a bunch of more latex packages from apt. > > It stopped working. > > > > ------------------------------ > > PS It would help all if you read > > https://wiki.python.org/moin/GoogleGroupsPython > > and dont double-space earlier mails. ======== It's not the place to discuss TeX here. (I have actually 16 more or less complete "distros" on my hd on Windows, all working very well. They are on my hd, but all run from an usb stick as well!) jmf From steve+comp.lang.python at pearwood.info Fri May 30 15:28:26 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2014 19:28:26 GMT Subject: How to run script from interpreter? References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> <5388233e$0$29978$c3e8da3$5496439d@news.astraweb.com> <53886b1e$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5388dbd9$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 May 2014 21:46:55 +1000, Chris Angelico wrote: > On Fri, May 30, 2014 at 9:27 PM, Steven D'Aprano > wrote: >> This is why I'm so adamant that, while REPLs may be permitted to >> introduce *new* syntax which is otherwise illegal to the Python parser, >> (e.g. like IPython's %magic and !shell commands) they *must not* change >> the meaning of otherwise legal Python syntax. It's simply a bad idea to >> have legal Python code mean different things depending on what >> environment you're running it in. > > Hmm. I'm not sure that "raises SyntaxError" is any less a part of the > language's promise than "evaluates to twice the value of x" is. Would > you, for instance, permit the REPL to define a new __future__ directive, > on the basis that it's invalid syntax currently? > >>>> from __future__ import magic_command_history > SyntaxError: future feature magic_command_history is not defined "from __future__ import ..." is an instruction to the compiler, hence a positive language feature. (That's why in source files any such import must occur at the top of the file, before any line of code.) It's a little unfortunate that bogus __future__ imports raise SyntaxError directly rather than some subclass of it, but given that it occurs at compile time, and how rarely one is in a position to try catching the exception, its understandable that the core devs didn't bother making it a separate subclass. (On the other hand, "import __future__" is a regular import that can occur any time you like.) No, a REPL cannot legitimately invent new language features that change Python's semantics, any more than they can legitimately redefine the plus operator + to perform subtraction. But they can legitimately add features to the shell, provided those features don't affect Python code. What's the difference? Consider entering this part of an interactive IPython session: In [14]: len [] -------> len([]) Out[14]: 0 In [15]: n = len [] ------------------------------------------------------------ File "", line 1 n = len [] ^ SyntaxError: invalid syntax Why is [14] permitted, but not [15]? Because [14] is a shell feature, but [15] is Python code. If [15] were permitted, then we would be tempted to use it inside functions: def spam(a): n = len a ... and either be surprised at the syntax error, or (worse!) be surprised that the function runs interactively inside IPython but fails in other shells and non-interactively. If [15] were allowed, we would no longer be running Python code. Of course, a naive user will be confused that len [] is permitted in IPython, but that's okay since it's a power-user's shell aimed at power- users. If the vanilla Python shell introduced such power-user convenience features by default, I would be very disappointed. Before you ask, there is no absolutely hard and fast line between "shell feature" and "Python code", but the more closely your shell features resemble Python code, the harder it will be for users (power or not) to keep them separate in their head and the more likely they will be confused. E.g. suppose my shell decided to allow lines like var = len [] to define the variable var and set it to 0. I'd argue that crosses the line from "useful convenience feature for power-users" to "dangerously confusing misfeature" because it looks too much like Python code. (I'm already dubious about len [] on its own.) A better interface is to have a clear separation between shell commands and Python, and IPython commonly usually uses prefix sigils such as ; % and ! for that. More here, including some cases where I think IPython crosses that line: http://ipython.org/ipython-doc/dev/interactive/reference.html You raise the issue of the vanilla Python shell printing the result of expressions. That would be the P in REPL, yes? :-) It would be a funny REPL that *didn't* print evaluated expressions. (Not entirely unheard of though -- Forth, for example, doesn't print the values you push onto the stack unless you pop them from the stack first. But it does print "ok" after each Read-Eval cycle when working interactively, so I guess it still counts as a REPL.) If we wanted to be pedantic, then yes there are semantic differences between code running in a REPL and the same running non-interactively. The vanilla REPL sets the magic variable _ to the result of the last evaluated expression (IPython has a bazillion variations of that). The REPL defines sys.ps1 and sys.ps2, when running non-interactively they don't exist. PYTHONSTARTUP isn't loaded outside of the REPL. But my argument is that these are a different kind of semantic difference than changing how Python expressions are parsed. Not all semantic differences are equal: (1) in the REPL, evaluating "(spam . attr)" on its own has the side-effect of printing the value of spam.attr (2) in the REPL, evaluating "(spam . attr)" does not perform a lookup of attr on spam are very different kinds of behavioural changes. [For brevity I left out the newlines.] > I don't think SyntaxError equates to "invitation to make changes". No, not in general. But SyntaxError does give a convenient opportunity to add shell features. If a line of text L is valid Python code, then the REPL needs to treat it as valid Python code. If L is invalid Python code, i.e. raises SyntaxError, then the REPL *may* use it as a shell feature, but whether it should or not depends on the details of L. -- Steven From rosuav at gmail.com Fri May 30 15:47:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 May 2014 05:47:45 +1000 Subject: How to run script from interpreter? In-Reply-To: <5388dbd9$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> <5388233e$0$29978$c3e8da3$5496439d@news.astraweb.com> <53886b1e$0$29978$c3e8da3$5496439d@news.astraweb.com> <5388dbd9$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 31, 2014 at 5:28 AM, Steven D'Aprano wrote: > Before you ask, there is no absolutely hard and fast line between "shell > feature" and "Python code", but the more closely your shell features > resemble Python code, the harder it will be for users (power or not) to > keep them separate in their head and the more likely they will be > confused. E.g. suppose my shell decided to allow lines like > > var = len [] > > to define the variable var and set it to 0. I'd argue that crosses the > line from "useful convenience feature for power-users" to "dangerously > confusing misfeature" because it looks too much like Python code. (I'm > already dubious about len [] on its own.) A better interface is to have a > clear separation between shell commands and Python, and IPython commonly > usually uses prefix sigils such as ; % and ! for that. I think this is the nub of the issue. You believe that anything that's syntactically legal in a script MUST (a) be syntactically legal, and (b) have the same semantics (modulo the printing part mentioned below) in the interactive interpreter. I'm a little less strict, and would be okay with some things that make little sense being disallowed. There are already a few such things (you mention the blank line issue), and the question is more whether they're recommended or not, than whether they're allowed or not. (Python 3's super() is a piece of magic, and it's better that it be magical, but it isn't a precedent to be followed.) I can accept that the desirable line is further over than I was putting it; practicality is only so-much of an argument. > You raise the issue of the vanilla Python shell printing the result of > expressions. That would be the P in REPL, yes? :-) It would be a funny > REPL that *didn't* print evaluated expressions. Yes of course, but there's a difference between these: >>> 1 + 2 3 >>> while True: input("Echo? ") if _=="Echo!": break The first one is using the REPL exactly the way everyone would expect it to be used. A single expression is entered, and it is printed. Failing to do that is, indeed, failing on the P of REPL. (That said, a Read-Eval Loop, sans Print, is still of value. I used one for over a decade with REXX, manually prefixing things with "say" when I wanted them printed, err I mean said.) But the second one is looking a lot more like a script, and if you're writing code like that, you really should think about assigning the input to a variable and explicitly printing it, not fiddling with automatic display and the _ capture. A "top-level expression", if you like, should definitely be printed. An inner expression isn't so fundamental. Since Python has been written to print them, we can make use of it; but a REPL that didn't print inner expressions is still a useful tool. Printing inner expressions is sliding toward the line of dangerously confusing misfeatures that you mentioned; you could compose a massively long function, and deep inside it, call something and have its return value printed - and then paste that into a script and find that it's not printing any more. Or, possibly worse, come to python-list with the question "How do I fix this?", not even knowing what the problem is, and having us all assume it's a script. It's a grey area. What's a convenient and useful feature, and what's a problem? Is supporting "print 1+2" in Python 3 on one side or the other of that line? ChrisA From jeanpierreda at gmail.com Fri May 30 16:47:02 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 30 May 2014 13:47:02 -0700 Subject: daemon thread cleanup approach In-Reply-To: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> References: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> Message-ID: Don't use daemon threads, they are inherently un-thread-safe: any global access you do anywhere inside a daemon thread can fail, because daemon threads are still potentially run during interpreter shutdown, when globals are being deleted from every module. Most functions you might call are not safe in a daemon thread at shutdown. -- Devin On Wed, May 28, 2014 at 6:20 PM, Carl Banks wrote: > Ok, so I have an issue with cleaning up threads upon a unexpected exit. I came up with a solution but I wanted to ask if anyone has any advice or warnings. > > Basically I am writing a Python library to run certain tasks. All of the calls in the library start worker threads to do the actual work, and some of the worker threads are persistent, others not. Most threads have cleanup work to do (such as deleting temporary directories and killing spawned processes). > > For better or worse, one of the requirements is that the library can't cause the program to hang no matter what, even if it means you have to forego cleanup in the event of an unexpected exit. Therefore all worker threads run as daemons. Nevertheless, I feel like the worker threads should at least be given a fair opportunity to clean up; all threads can be communicated with and asked to exit. > > One obvious solution is to ask users to put all library calls inside a with-statement that cleans up on exit, but I don't like it for various reasons. > Using atexit doesn't work because it's called after the daemon threads are killed. > > Here's the solution I came up with: in the library's init function, it will start a non-daemon thread that simply joins the main thread, and then asks all existing worker threads to exit gracefully before timing out and leaving them to be killed. So if an exception ends the main thread, there is still a chance to clean up properly. > > Does anyone see a potential problem with this approach? It it possible that this will cause the program to hang in any case? We can assume that all calls to the library will occur from the main thread, or at least from the same thread. (If that isn't the case, then the caller has taken responsibility to ensure the program doesn't hang.) > > This is Python 2.7, and it's only ever going to run on Windows. > > Thanks for any advice/warnings. > > Carl Banks > -- > https://mail.python.org/mailman/listinfo/python-list From duncan.booth at invalid.invalid Fri May 30 17:11:37 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 May 2014 21:11:37 GMT Subject: Multi-line commands with 'python -c' References: Message-ID: Chris Angelico wrote: > Problem: Translate this into a shell one-liner: > > import os > for root, dirs, files in os.walk("."): > if len(dirs + files) == 1: print(root) > This is one area where Windows seems to do better than Linux shells: PS C:\python33> python -c "import os`nfor root, dirs, files in os.walk('.'):`n if len(dirs + files) == 1: print(root)`n" .\Doc .\Lib\concurrent\__pycache__ .\Lib\curses\__pycache__ ... The `n shell escaped newline is interpreted well before Python runs. Also the multiline version works and in Powershell ISE up-arrow pulls it back as a single unit for easy editing: PS C:\python33> python -c @" import os for root, dirs, files in os.walk('.'): if len(dirs + files) == 1: print(root) "@ .\Doc .\Lib\concurrent\__pycache__ .\Lib\curses\__pycache__ ... and so on ... -- Duncan Booth From jeanpierreda at gmail.com Fri May 30 17:42:15 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 30 May 2014 14:42:15 -0700 Subject: Multi-line commands with 'python -c' In-Reply-To: References: Message-ID: In unix shells you can literally use a new line. Or is that only bash? -- Devin On Fri, May 30, 2014 at 2:11 PM, Duncan Booth wrote: > Chris Angelico wrote: > >> Problem: Translate this into a shell one-liner: >> >> import os >> for root, dirs, files in os.walk("."): >> if len(dirs + files) == 1: print(root) >> > > This is one area where Windows seems to do better than Linux shells: > > PS C:\python33> python -c "import os`nfor root, dirs, files in os.walk('.'):`n if len(dirs + files) == 1: print(root)`n" > .\Doc > .\Lib\concurrent\__pycache__ > .\Lib\curses\__pycache__ > ... > > The `n shell escaped newline is interpreted well before Python runs. > > Also the multiline version works and in Powershell ISE up-arrow pulls it back as a > single unit for easy editing: > > PS C:\python33> python -c @" > import os > for root, dirs, files in os.walk('.'): > if len(dirs + files) == 1: print(root) > "@ > .\Doc > .\Lib\concurrent\__pycache__ > .\Lib\curses\__pycache__ > ... and so on ... > > > -- > Duncan Booth > -- > https://mail.python.org/mailman/listinfo/python-list From ethan at stoneleaf.us Fri May 30 16:59:55 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 30 May 2014 13:59:55 -0700 Subject: daemon thread cleanup approach In-Reply-To: References: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> Message-ID: <5388F14B.3010807@stoneleaf.us> On 05/30/2014 01:47 PM, Devin Jeanpierre wrote: > > Don't use daemon threads, they are inherently un-thread-safe: any > global access you do anywhere inside a daemon thread can fail, because > daemon threads are still potentially run during interpreter shutdown, > when globals are being deleted from every module. Most functions you > might call are not safe in a daemon thread at shutdown. Given the use-case (must shut down, cannot risk a hung process, orphan files be damned) I don't think having a daemon thread die because it raised an exception trying to access a missing global is a big deal. -- ~Ethan~ From rosuav at gmail.com Fri May 30 17:47:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 May 2014 07:47:40 +1000 Subject: Multi-line commands with 'python -c' In-Reply-To: References: Message-ID: On Sat, May 31, 2014 at 7:42 AM, Devin Jeanpierre wrote: > In unix shells you can literally use a new line. Or is that only bash? You can in bash, I know, but it's fiddly to type it; and more importantly, it's not a good point in the "this is cleaner than a series of pipes" argument. My primary recommendation, of course, was a three-line script saved as an actual file, but for a more direct parallel to the pipe-it-three-ways model, I wanted to use -c. ChrisA From jeanpierreda at gmail.com Fri May 30 17:58:14 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 30 May 2014 14:58:14 -0700 Subject: daemon thread cleanup approach In-Reply-To: <5388F14B.3010807@stoneleaf.us> References: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> <5388F14B.3010807@stoneleaf.us> Message-ID: On Fri, May 30, 2014 at 1:59 PM, Ethan Furman wrote: > Given the use-case (must shut down, cannot risk a hung process, orphan files > be damned) I don't think having a daemon thread die because it raised an > exception trying to access a missing global is a big deal. It's certainly suboptimal. Subprocesses are better in every way. -- Devin From paul at mcnettware.com Fri May 30 18:03:43 2014 From: paul at mcnettware.com (Paul McNett) Date: Fri, 30 May 2014 15:03:43 -0700 Subject: Script suddenly stops In-Reply-To: <5387F12E.101@arcor.de> References: <5387F12E.101@arcor.de> Message-ID: <5389003F.3060405@mcnettware.com> On 5/29/14, 7:47 PM, Chris wrote: > I'm trying to read ten 200 MB textfiles into a MySQL MyISAM database > (Linux, ext4). The script output is suddenly stopping, while the Python > process is still running (or should I say sleeping?). It's not in top, > but in ps visible. Does it stop in the same place every time? How long are you waiting before giving up? Is it at all possible that it is the MySQL side that is blocking? > Why is it stopping? Is there a way to make it continue, without calling > "kill -9", deleting the processed lines and starting it again? One thing to try (maybe, depending on whether it still fits into your requirements for a database transaction) is to increase the number of rows inserted before each commit. > [1] http://pastebin.com/CxHCA9eB It won't have any bearing, but those globals aren't necessary... Paul From Joshua.R.English at gmail.com Fri May 30 23:38:02 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Fri, 30 May 2014 20:38:02 -0700 (PDT) Subject: Yet another "simple" headscratcher Message-ID: I am trying to whip up a quick matrix class that can handle multiplication. Should be no problem, except when it fails. --- Begin #!/usr/bin/env python # _*_ coding: utf-8 from operator import mul class Matrix(object): """Matrix([data]) Data should be a list of equal sized lists. Defaults to a 2d identity matrix """ def __init__(self, data=None): if data is None: data = [[1,0], [0,1]] self.data = [] if isinstance(data, (list, tuple)): ncols = len(data[0]) for row in data: if len(row) != ncols: raise ValueError("Rows are unequal lengths") self.data.append(row) self.size = (len(self.data), len(self.data[0])) def get_row(self, idx): if (0 <= idx < self.size[0]): return self.data[idx] else: raise ValueError("Bad row") def get_col(self, idx): if (0 <= idx < self.size[1]): return list(d[idx] for d in self.data) else: raise ValueError("Bad column index") def __mul__(self, other): if not isinstance(other, (Matrix,int, float)): raise ValueError("Cannot multiply by given value") if isinstance(other, (int, float)): res = [] for row in self.data: res.append([d*other for d in row]) return Matrix(res) # left with a matrix res = zero_matrix(self.size[0], other.size[1]) for i in range(res.size[0]): for j in range(res.size[1]): print i, j, self.get_row(i), other.get_col(j), temp = map(mul, self.get_row(i), other.get_col(j)) print temp, t = sum(temp) print t res.data[i][j] = t print res.data return res def as_string(self): # return a list of lines that look pretty stringed =[] for row in self.data: stringed.append(map(str, row)) widths = [] for col in range(self.size[1]): column = [s[col] for s in stringed] widths.append(max(map(len, column))) item_format = "{:>%s}" format_items = [item_format % w for w in widths] format_string = " ".join(format_items) formatted = [format_string.format(*s) for s in stringed] return formatted def zero_matrix(rows, cols): row = [0] * cols data = [] for r in range(rows): data.append(row) return Matrix(data) M = Matrix(([1, 0], [0, -1])) N = M*4 print '\n'.join(M.as_string()) print '-' print '\n'.join(N.as_string()) print '-' S = N * M print '\n'.join(S.as_string()) --- END For some reason, my output from this is: 1 0 0 -1 - 4 0 0 -4 - 0 0 [4, 0] [1, 0] [4, 0] 4 [[4, 0], [4, 0]] 0 1 [4, 0] [0, -1] [0, 0] 0 [[4, 0], [4, 0]] 1 0 [0, -4] [1, 0] [0, 0] 0 [[0, 0], [0, 0]] 1 1 [0, -4] [0, -1] [0, 4] 4 [[0, 4], [0, 4]] 0 4 0 4 >>> The print lines prove to me that the logic is working, but for some reason, assigning the sum to a particular item in a particular row is assigning the same row values to every row. This should be one of those really simple Python things, but for the life of me I don't see it. The first [[4, 0], [4, 0]] is clearly wrong. In each step, this algorithm is repeating the row. Any ideas as to why this is happening? Python 2.7.5, Windows 7, so nothing exotic. Josh From Joshua.R.English at gmail.com Fri May 30 23:55:18 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Fri, 30 May 2014 20:55:18 -0700 (PDT) Subject: Yet another "simple" headscratcher In-Reply-To: References: Message-ID: <4bf8faee-f4ee-46d6-99f8-ad43a5a59cab@googlegroups.com> Mea culpa, gang. I found it. It had absolutely nothing to do with the multiplication. It was in zero_matrix. I feel like a fool. Josh From gary.herron at islandtraining.com Fri May 30 23:57:32 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Fri, 30 May 2014 20:57:32 -0700 Subject: Yet another "simple" headscratcher In-Reply-To: References: Message-ID: <5389532C.6010707@islandtraining.com> On 05/30/2014 08:38 PM, Josh English wrote: > ... > > def zero_matrix(rows, cols): > row = [0] * cols > data = [] > for r in range(rows): > data.append(row) > > return Matrix(data) There is a simple and common newbie mistake here. It looks like you are appending several copies of a zero row to data, but in fact you are appending multiple references to a single row. (The hint is that you only created *one* row.) Put the row = [0] * cols inside the loop so each append is using its own row rather than one shared row being used multiple times. Here's a small example that demonstrates problem: >>> row = [0,0,0,0] >>> data = [] >>> data.append(row) >>> data.append(row) >>> data[0][0] = 99 >>> data [[99, 0, 0, 0], [99, 0, 0, 0]] Gary Herron From ian.g.kelly at gmail.com Fri May 30 23:54:00 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 30 May 2014 21:54:00 -0600 Subject: Yet another "simple" headscratcher In-Reply-To: References: Message-ID: On Fri, May 30, 2014 at 9:38 PM, Josh English wrote: > I am trying to whip up a quick matrix class that can handle multiplication. > > Should be no problem, except when it fails. > > [SNIP] > > def zero_matrix(rows, cols): > row = [0] * cols > data = [] > for r in range(rows): > data.append(row) Each row of the matrix that you create here is the *same* list, not different lists that happen to be equal. So when you mutate one row, you mutate all of them. See: https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list From wxjmfauth at gmail.com Sat May 31 02:46:17 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 30 May 2014 23:46:17 -0700 (PDT) Subject: Yet another "simple" headscratcher In-Reply-To: References: Message-ID: <9660e790-4734-4f41-a0bf-840b207c5a15@googlegroups.com> >>> # from my lib >>> def NewMat(nr, nc, val=0.0): ... val = float(val) ... return [[val] * nc for i in range(nr)] ... >>> import vmio6 >>> aa = NewMat(2, 3) >>> vmio6.pr(aa) ( 0.00000e+000 0.00000e+000 0.00000e+000 ) ( 0.00000e+000 0.00000e+000 0.00000e+000 ) >>> aa[0][0] = 3.1416 >>> vmio6.pr(aa) ( 3.14160e+000 0.00000e+000 0.00000e+000 ) ( 0.00000e+000 0.00000e+000 0.00000e+000 ) >>> aa[1][1] = 1.2345 >>> vmio6.pr(aa) ( 3.14160e+000 0.00000e+000 0.00000e+000 ) ( 0.00000e+000 1.23450e+000 0.00000e+000 ) >>> jmf From wxjmfauth at gmail.com Sat May 31 04:46:09 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 31 May 2014 01:46:09 -0700 (PDT) Subject: IDE for python In-Reply-To: References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> Message-ID: Le vendredi 30 mai 2014 18:38:04 UTC+2, Mark Lawrence a ?crit?: > On 30/05/2014 17:15, Rustom Mody wrote: > > > On Friday, May 30, 2014 8:36:54 PM UTC+5:30, wxjm... at gmail.com wrote: > > > > > > It is now about time that we stop taking ASCII seriously!! > > > > > > > This can't happen in the Python world until there is a sensible approach > > to unicode. Ah, but wait a minute, the ball was set rolling with Python > > 3.0. Then came PEP 393 and the Flexible String Representation in Python > > 3.3 and some strings came down in size by a factor of 75% and in most > > cases it was faster. Just what do some people want in life, jam on it? > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > > Mark Lawrence > > > > --- > > This email is free from viruses and malware because avast! Antivirus protection is active. > > http://www.avast.com ======== A guy who is understanding unicode would not have even spent its time in writing a PEP 393 proposal. I skip the discussion(s) I read here and there about PDF. Put this comment in relation with my Xe(La)TeX knowledge. jmf From hayesstw at telkomsa.net Sat May 31 06:07:59 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Sat, 31 May 2014 12:07:59 +0200 Subject: Python 3 is killing Python References: Message-ID: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> On Wed, 28 May 2014 14:23:17 -0500, Larry Martell wrote: >Somthing I came across in my travels through the ether: > >https://medium.com/@deliciousrobots/5d2ad703365d/ I just bought a new book on Python, since the one I had borrowed from my son only dealt with Python 2.3, and everyone told me that was old. So I bought this book, and decided that whatever version of Python it deals with, that's the one I will download and use. The book is: Cunningham, Katie. 2014. Teach yourself Python in 24 hours. Indianapolis: Sams. ISBN: 978-0-672-33687-4 For Python 2.7.5 I'll leave Python 3.2 on my computer, but 2.7.5 will be the one I'm installing now. Even if I could *find* a book that deals with Python 3.x, couldn't afford to but yet another Python book. -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From __peter__ at web.de Sat May 31 06:32:07 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 31 May 2014 12:32:07 +0200 Subject: Optparse to parsing Suggestions !! References: Message-ID: Am Sa Mai 31 2014, 13:08:12 schrieb Ganesh Pal: >> I think you have to do it manually: >> >> options, args = parser.parse_args() >> >> if options.object == "super_block" and options.path is not None: >> parser.error("Paths not allowed for 'super_block' object") >> >> elif options.object == "files" and options.path is None: >> parser.error("'files' object requires a path") >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > Thanks Peter , above will work for case 2. > > How about case 1. i.e . > > The --path is optional for few for the object type. > > #python corrupt.py --object=super_block --size=1000 > > ==> Should work even if --path is not given and should not complain > if --path is missing My code example is meant to convey the basic idea; you have to adapt it to your needs. E. g. if options.object == "super_block": if not path_is_acceptable_for_super_block(options.path): parser.error( "{!r} not an acceptable path for super_block object" .format(options.path)) elif options.object == "files" and options.path is None: parser.error("'files' object requires a path") where you are to write the path_is_acceptable_for_super_block() function to comply with your requirements. From dfnsonfsduifb at gmx.de Sat May 31 07:09:45 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 31 May 2014 13:09:45 +0200 Subject: Python 3 is killing Python In-Reply-To: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> References: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> Message-ID: On 31.05.2014 12:07, Steve Hayes wrote: > So I bought this book, and decided that whatever version of Python it deals > with, that's the one I will download and use. This sounds like remarkably bad advice. That's like saying "I bought a can of motor oil in my department store and whatever engine that is good for that's the car that I'll buy and put into!" > The book is: > > Cunningham, Katie. 2014. Teach yourself Python in 24 hours. > Indianapolis: Sams. > ISBN: 978-0-672-33687-4 > For Python 2.7.5 > > I'll leave Python 3.2 on my computer, but 2.7.5 will be the one I'm installing > now. Even if I could *find* a book that deals with Python 3.x, couldn't afford > to but yet another Python book. Lucky for you 2.7.5 isn't all that different from Py3 and most of it will apply. You'll be missing out on a bunch of cool features (arbitrary precision ints, int division operator, real Unicode support) but that's no big deal. Regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From stefan_ml at behnel.de Sat May 31 07:22:47 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 31 May 2014 13:22:47 +0200 Subject: Python 3 is killing Python In-Reply-To: References: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> Message-ID: Johannes Bauer, 31.05.2014 13:09: > Lucky for you 2.7.5 isn't all that different from Py3 and most of it > will apply. You'll be missing out on a bunch of cool features (arbitrary > precision ints Py2 has them as well (although they are called long). 1 << 300 gives the right answer in both Py2 and Py3, whether the result is a "long" or an "int". > int division operator AFAIR, that was added in Py2.5, so a book about Py2.7 should mention it somewhere. > real Unicode support Now, that is really something that has improved in Py3, and certainly a reason for many people to prefer Py3 over Py2. Stefan From srk90000 at gmail.com Sat May 31 07:40:22 2014 From: srk90000 at gmail.com (srk90000 at gmail.com) Date: Sat, 31 May 2014 04:40:22 -0700 (PDT) Subject: webdesigning Message-ID: <71b56863-6a38-407c-812b-3e756388f119@googlegroups.com> website.. www.webdizer.com From steve+comp.lang.python at pearwood.info Sat May 31 08:30:11 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 May 2014 12:30:11 GMT Subject: Python 3 is killing Python References: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> Message-ID: <5389cb53$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 31 May 2014 12:07:59 +0200, Steve Hayes wrote: > I'll leave Python 3.2 on my computer, but 2.7.5 will be the one I'm > installing now. Even if I could *find* a book that deals with Python > 3.x, couldn't afford to but yet another Python book. Version 2.7 is a good choice, and it will be around for a long time: it will be supported until at least 2020, so you should get many years of use from it. Do not be discouraged about Python 3. There are differences, but they aren't so different as to be a major barrier. By the time you have a bit of experience with 2.7, you will be more than capable of dealing with the differences with version 3. They are not different languages, think of them as slightly different dialects of the same language, like UK and South African English. -- Steven D'Aprano http://import-that.dreamwidth.org/ From marko at pacujo.net Sat May 31 08:44:46 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 31 May 2014 15:44:46 +0300 Subject: Python 3 is killing Python References: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> Message-ID: <87d2euazi9.fsf@elektro.pacujo.net> Steve Hayes : > I'll leave Python 3.2 on my computer, but 2.7.5 will be the one I'm > installing now. Even if I could *find* a book that deals with Python > 3.x, couldn't afford to but yet another Python book. Unfortunately, in the computer field, if there's a book written on a topic, it will most likely be out of date. In the 1990's, I used to buy computer books on various topics. I don't think I have bought one for ten years. Either it is online or it doesn't exist. There's enough Python material online to become a pro in it: * tutorials, * the complete language reference, * the complete library reference, * the complete reference implementation, * this discussion group. Marko From ian.g.kelly at gmail.com Sat May 31 10:37:29 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 31 May 2014 08:37:29 -0600 Subject: Optparse to parsing Suggestions !! In-Reply-To: References: Message-ID: On May 30, 2014 8:26 AM, "Ganesh Pal" wrote: > > > Hello Python world , > > > I wanted suggestion on how to modify the below code to help me accomodate the below two cases Your question was answered already, but I'd like to point out that optparse is deprecated. If possible, you should use argparse instead. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Sat May 31 11:48:43 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 31 May 2014 08:48:43 -0700 (PDT) Subject: Python 3 is killing Python In-Reply-To: <5389cb53$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> <5389cb53$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <99b7b2a2-7521-42d7-a5a0-1a35d4d5b922@googlegroups.com> Le samedi 31 mai 2014 14:30:11 UTC+2, Steven D'Aprano a ?crit?: > On Sat, 31 May 2014 12:07:59 +0200, Steve Hayes wrote: > > > > > I'll leave Python 3.2 on my computer, but 2.7.5 will be the one I'm > > > installing now. Even if I could *find* a book that deals with Python > > > 3.x, couldn't afford to but yet another Python book. > > > > Version 2.7 is a good choice, and it will be around for a long time: it > > will be supported until at least 2020, so you should get many years of > > use from it. > > > > Do not be discouraged about Python 3. There are differences, but they > > aren't so different as to be a major barrier. By the time you have a bit > > of experience with 2.7, you will be more than capable of dealing with the > > differences with version 3. They are not different languages, think of > > them as slightly different dialects of the same language, like UK and > > South African English. > > > > ====== At least Py2 does not crash when using non ascii (eg sticking with cp1252). I just noticed this last week, Thursday, when presenting the absurdity of the Flexible String Representation. jmf From breamoreboy at yahoo.co.uk Sat May 31 12:10:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 31 May 2014 17:10:20 +0100 Subject: Python 3.2 has some deadly infection Message-ID: Some interesting comments here http://techtonik.rainforce.org/2014/05/python-32-has-some-deadly-infection.html so I'm simply asking for other opinions. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From duncan.booth at invalid.invalid Sat May 31 12:41:21 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 31 May 2014 16:41:21 GMT Subject: Multi-line commands with 'python -c' References: Message-ID: Chris Angelico wrote: > On Sat, May 31, 2014 at 7:42 AM, Devin Jeanpierre > wrote: >> In unix shells you can literally use a new line. Or is that only bash? > > You can in bash, I know, but it's fiddly to type it; and more > importantly, it's not a good point in the "this is cleaner than a > series of pipes" argument. My primary recommendation, of course, was a > three-line script saved as an actual file, but for a more direct > parallel to the pipe-it-three-ways model, I wanted to use -c. and you also wrote originally that it's fiddly to edit. I think that Windows Powershell has (at least in the current ISE command line) got the editing a bit better. It's a minor difference though and it has taken Microsoft about 30 years to get to that point. What may be a larger difference, or may just be my lack of Linux-foo, is this: PS C:\python33> $script = @" import os for root, dirs, files in os.walk("."): if len(dirs + files) == 1: print(root) "@ PS C:\python33> python -c $script .\Doc .\Lib\concurrent\__pycache__ .\Lib\curses\__pycache__ ... which is a style I've found useful for example when running a group of related timeit.py commands as I can put things like multi-line setup statements in a variable and then have a simpler command to repeat. But bash as far as I can won't let me do that: $ script='import os for root, dirs, files in os.walk("."): if len(dirs + files) == 1: print(root) ' $ python -c $script File "", line 1 import ^ SyntaxError: invalid syntax -- Duncan Booth From breamoreboy at yahoo.co.uk Sat May 31 13:10:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 31 May 2014 18:10:31 +0100 Subject: pyflakes best practices? In-Reply-To: References: Message-ID: On 30/05/2014 02:14, Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> On 30/05/2014 01:13, Roy Smith wrote: >>> We've recently started using pyflakes. The results seem to be similar >>> to most tools of this genre. It found a few real problems. It >>> generated a lot of noise about things which weren't really wrong, but >>> were easy to fix (mostly, unused imports), and a few plain old false >>> positives which have no easy "fix" (in the sense of, things I can change >>> which will make pyflakes STFU). >>> >>> So, what's the best practice here? How do people deal with the false >>> positives? Is there some way to annotate the source code to tell >>> pyflakes to ignore something? >>> >> >> I was under the impression that pyflakes was configurable. It it isn't >> I'd simply find another tool. Having said that if you don't get better >> answers here try gmane.comp.python.code-quality. > > I didn't know that list existed, it looks very interesting. Thanks for > the pointer! > FYI the full list of Python lists on gmane here http://dir.gmane.org/index.php?prefix=gmane.comp.python -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From __peter__ at web.de Sat May 31 13:11:03 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 31 May 2014 19:11:03 +0200 Subject: Multi-line commands with 'python -c' References: Message-ID: Duncan Booth wrote: > Chris Angelico wrote: > >> On Sat, May 31, 2014 at 7:42 AM, Devin Jeanpierre >> wrote: >>> In unix shells you can literally use a new line. Or is that only > bash? >> >> You can in bash, I know, but it's fiddly to type it; and more >> importantly, it's not a good point in the "this is cleaner than a >> series of pipes" argument. My primary recommendation, of course, was a >> three-line script saved as an actual file, but for a more direct >> parallel to the pipe-it-three-ways model, I wanted to use -c. > > and you also wrote originally that it's fiddly to edit. I think that > Windows Powershell has (at least in the current ISE command line) got > the editing a bit better. It's a minor difference though and it has > taken Microsoft about 30 years to get to that point. > > What may be a larger difference, or may just be my lack of Linux-foo, is > this: > > PS C:\python33> $script = @" > import os > for root, dirs, files in os.walk("."): > if len(dirs + files) == 1: print(root) > "@ > > PS C:\python33> python -c $script > .\Doc > .\Lib\concurrent\__pycache__ > .\Lib\curses\__pycache__ > ... > > which is a style I've found useful for example when running a group of > related timeit.py commands as I can put things like multi-line setup > statements in a variable and then have a simpler command to repeat. > > But bash as far as I can won't let me do that: > > $ script='import os > for root, dirs, files in os.walk("."): > if len(dirs + files) == 1: print(root) > ' > $ python -c $script > File "", line 1 > import > ^ > SyntaxError: invalid syntax $ script='import os > for root, dirs, files in os.walk("."): > if len(dirs + files) == 1: > print(root) > ' $ python3 -c "$script" . ./heureka $ python3 -c 'import sys; print(sys.argv)' $script ['-c', 'import', 'os', 'for', 'root,', 'dirs,', 'files', 'in', 'os.walk("."):', 'if', 'len(dirs', '+', 'files)', '==', '1:', 'print(root)'] $ python3 -c 'import sys; print(sys.argv)' "$script" ['-c', 'import os\nfor root, dirs, files in os.walk("."):\n if len(dirs + files) == 1:\n print(root)\n'] From tokibito at gmail.com Sat May 31 14:36:21 2014 From: tokibito at gmail.com (tokibito at gmail.com) Date: Sat, 31 May 2014 11:36:21 -0700 (PDT) Subject: Suds and Python3 Message-ID: <7516fe94-db33-44ea-9586-92b7446324de@googlegroups.com> Suds is defacto python SOAP client, but it does not mainte recent few years. Why? I want to use SOAP and Python3. How do it? From ch2009 at arcor.de Sat May 31 11:05:14 2014 From: ch2009 at arcor.de (Chris) Date: Sat, 31 May 2014 17:05:14 +0200 Subject: Script suddenly stops In-Reply-To: <5387F12E.101@arcor.de> References: <5387F12E.101@arcor.de> Message-ID: <5389EFAA.8080705@arcor.de> Dear All, thanks a lot for your replies. I've found my mistake. The script output stopped, but the script was still filling the MySQL table. When I resized the Gnome terminal window the output continued. -- Christian From paul at mcnettware.com Sat May 31 14:59:15 2014 From: paul at mcnettware.com (Paul McNett) Date: Sat, 31 May 2014 11:59:15 -0700 Subject: Suds and Python3 In-Reply-To: <7516fe94-db33-44ea-9586-92b7446324de@googlegroups.com> References: <7516fe94-db33-44ea-9586-92b7446324de@googlegroups.com> Message-ID: <538A2683.7050902@mcnettware.com> On 5/31/14, 11:36 AM, tokibito at gmail.com wrote: > Suds is defacto python SOAP client, but it does not mainte recent few years. Why? Is it really the defacto? It seems like I've heard more about pysimplesoap, and looking at GitHub there have been commits in the past 4 days. As far as why it hasn't been maintained, you could write and ask the authors directly. In general, SOAP has been falling out of favor over the past half decade at least because of its relative heaviness next to, e.g. RESTful web services usually using JSON instead of XML. Way, way simpler and more fun to do. That said, SOAP will be around for a long time and if you need to do it, you want a good library for it. I don't have direct experience, but I did do cursory reviews of a handful of the SOAP libaries listed here in the python wiki: https://wiki.python.org/moin/WebServices And from what I can tell without actually trying any of them, pysimplesoap feels like the best option currently. > I want to use SOAP and Python3. How do it? If it were me, I'd install each of the libraries listed on the wiki page and make a matrix of features desired, make up a suite of unit tests to test those features, and then run each of them through the suite to see how they stack up. Also consider how "alive" the project is, and how the project's bug tracker is maintained, look at their forum, etc. Paul From codemonkey at inbox.com Sat May 31 13:28:25 2014 From: codemonkey at inbox.com (Deb Wyatt) Date: Sat, 31 May 2014 09:28:25 -0800 Subject: Python 3 is killing Python In-Reply-To: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> References: Message-ID: > > I just bought a new book on Python, since the one I had borrowed from my > son > only dealt with Python 2.3, and everyone told me that was old. > > So I bought this book, and decided that whatever version of Python it > deals > with, that's the one I will download and use. > > The book is: > > Cunningham, Katie. 2014. Teach yourself Python in 24 hours. > Indianapolis: Sams. > ISBN: 978-0-672-33687-4 > For Python 2.7.5 > > I'll leave Python 3.2 on my computer, but 2.7.5 will be the one I'm > installing > now. Even if I could *find* a book that deals with Python 3.x, couldn't > afford > to but yet another Python book. > > > -- > Steve Hayes from Tshwane, South Africa > Web: http://www.khanya.org.za/stevesig.htm > Blog: http://khanya.wordpress.com > E-mail - see web page, or parse: shayes at dunelm full stop org full stop > uk > -- > https://mail.python.org/mailman/listinfo/python-list In my search for information to learn about object oriented programming, since I come from a pre oop background, I found this site: http://it-ebooks.info/ tons of free books, many fairly up-to-date. A wealth of knowledge for the do it yourself learner. Hope this is helpful to you. Deb in WA, USA ____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! Check it out at http://www.inbox.com/marineaquarium From marko at pacujo.net Sat May 31 15:55:07 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 31 May 2014 22:55:07 +0300 Subject: Python 3.2 has some deadly infection References: Message-ID: <87wqd1afl0.fsf@elektro.pacujo.net> Mark Lawrence : > Some interesting comments here > http://techtonik.rainforce.org/2014/05/python-32-has-some-deadly-infection.html > so I'm simply asking for other opinions. I read the article, but unfortunately I failed to see interesting comments or opinions. There was some graphic, but it didn't say anything to me, and the article didn't really seem to be making any argument apart from the disappointed tone. Marko From rhodri at wildebst.org.uk Sat May 31 19:17:04 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Sun, 01 Jun 2014 00:17:04 +0100 Subject: IDE for python References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> Message-ID: On Fri, 30 May 2014 13:53:06 +0100, Rustom Mody wrote: > On Thursday, May 29, 2014 10:14:35 PM UTC+5:30, Paul Rudin wrote: >> Terry Reedy writes: >> > 3. Search unopened files (grep) for a string or re. > >> Emacs. > > How do you do this with emacs? > I find a menagerie of greppish commands -- rgrep, lgrep, grep-find etc I generally find "M-x grep" sufficient. -- Rhodri James *-* Wildebeest Herder to the Masses From ngangsia at gmail.com Sat May 31 20:28:50 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sat, 31 May 2014 17:28:50 -0700 (PDT) Subject: Business model Message-ID: <518b225d-9d6d-4609-92fc-d25ab56690f4@googlegroups.com> I am already writing programs in python. I wish to use my programming skills for a business model, any business approach. Is any one here business oriented to give me some guide lines or do any person knows Google groups that i can join that will help me approach my objective. Hope to hear from you guys please. Thanks From breamoreboy at yahoo.co.uk Sat May 31 21:30:01 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 01 Jun 2014 02:30:01 +0100 Subject: Business model In-Reply-To: <518b225d-9d6d-4609-92fc-d25ab56690f4@googlegroups.com> References: <518b225d-9d6d-4609-92fc-d25ab56690f4@googlegroups.com> Message-ID: On 01/06/2014 01:28, ngangsia akumbo wrote: > I am already writing programs in python. > > I wish to use my programming skills for a business model, any business approach. > > Is any one here business oriented to give me some guide lines or do any person knows Google groups that i can join that will help me approach my objective. > > Hope to hear from you guys please. > Thanks > http://code.activestate.com/lists/python-list/655550/ seems rather similar. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rustompmody at gmail.com Sat May 31 21:48:07 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 31 May 2014 18:48:07 -0700 (PDT) Subject: IDE for python In-Reply-To: References: <8761kozg98.fsf@rudin.co.uk> <7deeb0f8-f4f4-4661-b0bb-f9481b6ef35a@googlegroups.com> <878upjwewt.fsf@elektro.pacujo.net> <7713af25-2ed4-49b3-9457-b352f9486c78@googlegroups.com> Message-ID: On Friday, May 30, 2014 10:37:00 PM UTC+5:30, Rustom Mody wrote: > You are talking about the infrastructure needed for writing unicode apps. > The language need not have non-ASCII lexemes for that > I am talking about something quite different. > Think for example of a German wanting to write "G?del" > According to some conventions (s)he can write Goedel > But if that is forced just because of ASCII/US-104/what-have-u it would justifiably > cause irritation/offense. Curiously I just saw this tex/emacs question/answer elsewhere ? particularly amusing the first 'char' of the answer. Question: | I'm a new Emacs/Auctex User. Auctex for Emacs is amazing but | there are some little things could be better. When generating a | section with c-c c-s the label ist generated automatically. But | if there is an german Umlaut in the section title like '?' this | becomes just 'a' in the label. Is there any possibility that | auctex will substitute the '?' by 'ae' and not by 'a'? Answer: | '?' is not possible, since latex can not handle Umlauts in references. | For 'ae' I'm sure someone is able to provide a little patch. From ngangsia at gmail.com Sat May 31 21:49:53 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sat, 31 May 2014 18:49:53 -0700 (PDT) Subject: Business model In-Reply-To: References: <518b225d-9d6d-4609-92fc-d25ab56690f4@googlegroups.com> Message-ID: <7302f275-7268-4c34-8d6e-6d47d56696b1@googlegroups.com> On Sunday, June 1, 2014 2:30:01 AM UTC+1, Mark Lawrence wrote: > On 01/06/2014 01:28, ngangsia akumbo wrote: sorry for asking the same question > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > > Mark Lawrence > > > > --- > > This email is free from viruses and malware because avast! Antivirus protection is active. > > http://www.avast.com From steve+comp.lang.python at pearwood.info Sat May 31 22:26:17 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Jun 2014 02:26:17 GMT Subject: Python 3.2 has some deadly infection References: Message-ID: <538a8f48$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 31 May 2014 17:10:20 +0100, Mark Lawrence wrote: > Some interesting comments here > http://techtonik.rainforce.org/2014/05/python-32-has-some-deadly- infection.html > so I'm simply asking for other opinions. Oh, Anatoly Techtonik. He's quite notorious on python-dev for wanting to impose his wild and sometimes wacky processes on the entire community. Specific examples aren't coming to mind, and I'm too lazy to search the archives, so I'll just make one up to give you an idea of the flavour of his requests: "Twitter is the only way that developers can effectively communicate. We must shut down all the mailing lists and the bug tracker and move all communication immediately to Twitter. And by we I mean you." [Not an actual quote.] I've come to the conclusion that he occasionally has a point to his posts, but only at random by virtue of the scatter-gun technique. He's obviously widely read, but not deeply, and so he fires off a lot of ill- thought out but superficially attractive proposals. Just by chance a few of them end up being interesting, not *interesting enough* for somebody else to do the work. At this point the ideas languish, because he refuses to sign a contributor agreement so the Python core developers cannot accept anything from him. This blog post is a strong opinion about Python, but it isn't clear what that opinion *actually is*. His post is rambling and unfocused and incoherent ("art is the future"). He rails against having to write PEPs, and decries the lack of stats, summaries, analysis and comparison, utterly missing the point that the purpose of the PEP process is to provide those stats, summaries, analysis and comparison. Reading between the lines, I think what he means, deep down, is that *somebody else* ought to gather those stats and do the analysis to support his ideas, and not expect him to write the PEP. He makes at least one factually wrong claim: "I thought that C/C++ must die, because really all major security problems are because of it." [actual quote] He's talking about buffer overflows. Buffer overflows have never been responsible for "all" major security problems. Even allowing for a little hyperbole, buffer overflows have not been responsible for the majority of major security problems for a very long time. It is not 1992 any more, and today the single largest source of security bugs are code injection attacks. In Python terms that mostly means failure to sanitize SQL queries and the use of eval() and exec() on untrusted data. http://cwe.mitre.org/top25/ Three of the top four software errors are forms of code injection: SQL injection, OS command injection, cross-site scripting. The classic C buffer overflow comes in at number 3, so it's not an inconsiderable cause of security vulnerabilities even today, but it is not even close to the only such cause. See also http://www.sans.org/top25-software-errors/ Back to the blog post... it's 2014, Python 3.3 and 3.4 have come out, why is he talking about 3.2? It's interesting that he starts off by stating his graph is meaningless: "They don't measure anything - just show some lines that correlate to each other." then immediately tries to draw a conclusion from those lines: "It looks like the peak of Python was on February 2011, and since then there was a significant drop." I've written about the difficulty of measuring language popularity in any meaningful way: http://import-that.dreamwidth.org/1388.html http://import-that.dreamwidth.org/2873.html Anatoly has picked the TIOBE Index, but I don't know that this is the best measure of language popularity. According to it, Python is more popular than Javascript. I love Python, but really, more popular than Javascript? That feels wrong to me. In any case, I think that a better explanation for the observed dip in Feb 2011 is not that Python 3.2 is infected (infected by what?) but *regression to the mean*. Regression to the mean is a statistical phenomenon which basically says that all else being equal, an extreme value is likely to be followed by a less extreme (closer to the average) value. Language popularity, as measured by TIOBE, is at least in part random. (Look at how wiggly the lines are. The wiggles represent random variation.) If by chance a language gets a spike in interest one month, it is less likely to Because TIOBE's results contain so much random noise, they really ought to smooth them out by averaging the scores over a three month window, and show trend lines. They don't, I believe, because random hiccoughs in the data provide interest: "Last month, Java was overthrown from it's #1 ranking by C. This month it has fought its way back to #1 again! Tune in next month to see if C can repeat it's stunning victory!!!" I think that long term trend lines would be much less exciting but much more informative. Eyeballing the graph, it seems to me that Java and C++ are trending down, C is probably steady, and Objective C and Python trending up. If by chance there was a flurry of interest in Python for a month or two, and then things fell back to normal (regression to the mean), that might look like a slump. But I digress... back to Anatoly's post. I think he reveals more about himself than Python: "When these little things sum up, you realize that you're just wasting time trying to improve things that people don't want to improve. They don't want to improve the process. They don't realize that the problem is not in the language, but in the way they don't want to hear each other. Technology showed that people want to be heard, that they opinion should be accounted , not closed as won't fix , or works for me . It is not a community process, when you rely on abilities of certain individuals to monitor and respond to all traffic and wishes, especially when they fail to do so." On Python-Dev, this is Anatoly's repeated claim: the process is broken, because well it just is okay. In my opinion, "the process is broken" is Anatoly's shorthand for "I want to do things THIS way, and you won't let me. My way is SO OBVIOUSLY BRILLIANT that everybody, no matter their circumstances, will be immeasurably better off by switching to my process instead of the old way of doing things. Anyone who thinks differently is simply not paying attention. Didn't you hear how brilliant my process is?" Anatoly does make a few concrete complaints about Python 3, or at least as concrete as he gets in this post: "I expected Python 3 to be ready for the internet age" -- What does that mean? What makes him think it isn't? "with cross-platform behavior preferred over system-dependent one" -- It's not clear how cross-platform behaviour has anything to do with the Internet age. Python has preferred cross-platform behaviour forever, except for those features and modules which are explicitly intended to be interfaces to system-dependent features. (E.g. a lot of functions in the os module are thin wrappers around OS features. Hence the name of the module.) "with clear semantics to work with binary data" -- There are clear semantics to work with binary data: use bytes, and the struct module. Those features can be improved, and indeed Python 3.4 has improved them, and 3.5 is in the process of improving them further. But to suggest that Python doesn't have those clear semantics is simply false. "with non-confusing error handling" -- How is Python 3's error handling confusing? It's the same error handling as Python 2. Where is the confusion? TL;DR: Anatoly's blog post is long on disappointment and short on actual content. It feels to me that we could summarise his post as: I don't know what I want, I won't recognise it even if I saw it, but Python 3 isn't it. I blame others for not living up to my expectations for features I cannot describe and were never promised. -- Steven From steve+comp.lang.python at pearwood.info Sat May 31 22:32:33 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Jun 2014 02:32:33 GMT Subject: Business model References: <518b225d-9d6d-4609-92fc-d25ab56690f4@googlegroups.com> <7302f275-7268-4c34-8d6e-6d47d56696b1@googlegroups.com> Message-ID: <538a90c1$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 31 May 2014 18:49:53 -0700, ngangsia akumbo wrote: > On Sunday, June 1, 2014 2:30:01 AM UTC+1, Mark Lawrence wrote: >> On 01/06/2014 01:28, ngangsia akumbo wrote: > > sorry for asking the same question No need to apologise. It's an interesting question, and reading the answers given last time will be useful. After you have read those dozen or so answers, please come back with any further questions. Here's the link again: http://code.activestate.com/lists/python-list/655550/ -- Steven From rosuav at gmail.com Sat May 31 22:43:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jun 2014 12:43:37 +1000 Subject: Python 3.2 has some deadly infection In-Reply-To: <538a8f48$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <538a8f48$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jun 1, 2014 at 12:26 PM, Steven D'Aprano wrote: > TL;DR: Anatoly's blog post is long on disappointment and short on actual > content. It feels to me that we could summarise his post as: > > I don't know what I want, I won't recognise it even if I saw > it, but Python 3 isn't it. I blame others for not living up > to my expectations for features I cannot describe and were > never promised. I think that summary is accurate. When Mark posted this last night (okay, it was last night for me, probably not for most of you), I tried to read the post and figure out what he was actually saying... and failed. Gave up on it and moved on. Got better things to do with my life... like, I dunno, actually writing code, which seems to be something that people who whine in blog posts don't do. ChrisA From hayesstw at telkomsa.net Sat May 31 22:57:27 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Sun, 01 Jun 2014 04:57:27 +0200 Subject: Python 3 is killing Python References: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> Message-ID: <965lo9tqov049ldm9jlgukcchjonnh1m50@4ax.com> On Sat, 31 May 2014 13:09:45 +0200, Johannes Bauer wrote: >On 31.05.2014 12:07, Steve Hayes wrote: > >> So I bought this book, and decided that whatever version of Python it deals >> with, that's the one I will download and use. > >This sounds like remarkably bad advice. That's like saying "I bought a >can of motor oil in my department store and whatever engine that is good >for that's the car that I'll buy and put into!" No, it's a bit like flying in a Boeing 747 rather than a Concorde. The latyer may be later and more technically advanced and flew faster, but no one uses or supports it. > >> The book is: >> >> Cunningham, Katie. 2014. Teach yourself Python in 24 hours. >> Indianapolis: Sams. >> ISBN: 978-0-672-33687-4 >> For Python 2.7.5 >> >> I'll leave Python 3.2 on my computer, but 2.7.5 will be the one I'm installing >> now. Even if I could *find* a book that deals with Python 3.x, couldn't afford >> to but yet another Python book. > >Lucky for you 2.7.5 isn't all that different from Py3 and most of it >will apply. You'll be missing out on a bunch of cool features (arbitrary >precision ints, int division operator, real Unicode support) but that's >no big deal. I'm prepared to forgo whatever advantages those may have to avoid the frustration of example code not working and not knowing why. -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From hayesstw at telkomsa.net Sat May 31 23:00:09 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Sun, 01 Jun 2014 05:00:09 +0200 Subject: Python 3 is killing Python References: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> <5389cb53$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 31 May 2014 12:30:11 GMT, Steven D'Aprano wrote: >On Sat, 31 May 2014 12:07:59 +0200, Steve Hayes wrote: > >> I'll leave Python 3.2 on my computer, but 2.7.5 will be the one I'm >> installing now. Even if I could *find* a book that deals with Python >> 3.x, couldn't afford to but yet another Python book. > >Version 2.7 is a good choice, and it will be around for a long time: it >will be supported until at least 2020, so you should get many years of >use from it. > >Do not be discouraged about Python 3. There are differences, but they >aren't so different as to be a major barrier. By the time you have a bit >of experience with 2.7, you will be more than capable of dealing with the >differences with version 3. They are not different languages, think of >them as slightly different dialects of the same language, like UK and >South African English. That's more or less what the book said, about why it chose to use 2 rather than 3. -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From hayesstw at telkomsa.net Sat May 31 23:05:05 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Sun, 01 Jun 2014 05:05:05 +0200 Subject: Python 3 is killing Python References: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> <87d2euazi9.fsf@elektro.pacujo.net> Message-ID: <4s5lo91dpa4e7iakbdtq4umar01o6vte7f@4ax.com> On Sat, 31 May 2014 15:44:46 +0300, Marko Rauhamaa wrote: >Steve Hayes : > >> I'll leave Python 3.2 on my computer, but 2.7.5 will be the one I'm >> installing now. Even if I could *find* a book that deals with Python >> 3.x, couldn't afford to but yet another Python book. > >Unfortunately, in the computer field, if there's a book written on a >topic, it will most likely be out of date. > >In the 1990's, I used to buy computer books on various topics. I don't >think I have bought one for ten years. Either it is online or it doesn't >exist. > >There's enough Python material online to become a pro in it: I hate reading stuff online, and find it diffucult to learn anything with that method. I use MS Word 97 in preference to Libre Office wor Word 2010 (both of which I have) because I have a book on the first, but not on the others. I can't read online books in the bath or in bed. -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From rosuav at gmail.com Sat May 31 23:35:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jun 2014 13:35:11 +1000 Subject: Python 3 is killing Python In-Reply-To: <965lo9tqov049ldm9jlgukcchjonnh1m50@4ax.com> References: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> <965lo9tqov049ldm9jlgukcchjonnh1m50@4ax.com> Message-ID: On Sun, Jun 1, 2014 at 12:57 PM, Steve Hayes wrote: > On Sat, 31 May 2014 13:09:45 +0200, Johannes Bauer > wrote: > >>On 31.05.2014 12:07, Steve Hayes wrote: >> >>> So I bought this book, and decided that whatever version of Python it deals >>> with, that's the one I will download and use. >> >>This sounds like remarkably bad advice. That's like saying "I bought a >>can of motor oil in my department store and whatever engine that is good >>for that's the car that I'll buy and put into!" > > No, it's a bit like flying in a Boeing 747 rather than a Concorde. The latyer > may be later and more technically advanced and flew faster, but no one uses or > supports it. "Conky" is more like Python 1 - nobody uses it now (actually, there are more people using Python 1.x than flying Concorde), but it had its place in history. You're flying in a 747-400, which is fine, but when I want to go to England, I'd much rather go in a 777-300ER. (And yes, I've flown in both. Can't remember what model Queenie was, but with the 777s it's usually an Emirates 300ER.) The 747 is still functional, but no more functional than its era, and life's a lot better with the newer aircraft. If you want to start a brand new airline, you won't go for 747s if you can get 777s and A380s for the same price. For those who have 747s in their fleet, there's no problem - there'll be spare parts available from the manufacturer until at least donkey's years, and even after that, you can probably get third-party spare parts from some ex-Soviet mob (at least, they must be Soviets, why else would they wear red hats?); but you'll only get the features that were in the 747s when they were built, plus maybe some minor upgrades to the ancillary bits and pieces. Sure, you can get some of the fancy interior pieces that were designed for the 777s (enum, for instance), but the main hull isn't changing. So if you want to start a one-man airline (where you're managing the company, flying the plane, and everything else), do you start by looking at the relative merits of the 747-400 and 777-300ER and choosing, or do you poke around in your local second-hand shop for "Learn To Fly A Jet In Twenty-Four Hours" and see which cockpit it's showing photos of? There are courses for both types; both aircraft come with excellent "quick start" guides (see https://docs.python.org/2/tutorial/ and https://docs.python.org/3/tutorial/ ); and everything you want to ask about either type can be answered by the team of Boeing-List at Boeing.Org people, any hour of the day or night. All you're doing is picking your technology on the basis of *one* dead-tree book that you happen to have found. Is that really the most important deciding point? ChrisA